2015-09-17 00:05:52 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
/**
|
|
|
|
* Notification badge button widget for echo popup.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.ButtonWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
2016-09-26 17:08:43 +00:00
|
|
|
* @cfg {string} [type] The notification types this button represents;
|
|
|
|
* 'message', 'alert' or 'all'
|
2015-09-24 01:13:37 +00:00
|
|
|
* @cfg {string} [href] URL the badge links to
|
2015-09-17 00:05:52 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.BadgeLinkWidget = function MwEchoUiBadgeLinkWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
mw.echo.ui.BadgeLinkWidget.parent.call( this, config );
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.LabelElement.call( this, $.extend( { $label: this.$element }, config ) );
|
|
|
|
OO.ui.mixin.ButtonElement.call( this, $.extend( { $button: this.$element }, config ) );
|
|
|
|
OO.ui.mixin.TitledElement.call( this, $.extend( { $titled: this.$element }, config ) );
|
|
|
|
OO.ui.mixin.FlaggedElement.call( this, $.extend( {}, config, { $flagged: this.$element } ) );
|
|
|
|
|
2016-07-20 00:24:17 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-notifications-badge' );
|
|
|
|
|
2016-09-26 17:08:43 +00:00
|
|
|
this.count = 0;
|
|
|
|
this.type = config.type || 'alert';
|
2016-07-20 00:24:17 +00:00
|
|
|
this.setCount( config.numItems, config.label );
|
2015-09-24 01:13:37 +00:00
|
|
|
|
|
|
|
if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) {
|
|
|
|
this.$element.attr( 'href', config.href );
|
|
|
|
}
|
2015-09-17 00:05:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.BadgeLinkWidget, OO.ui.Widget );
|
|
|
|
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.LabelElement );
|
|
|
|
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.ButtonElement );
|
|
|
|
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.TitledElement );
|
|
|
|
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.FlaggedElement );
|
|
|
|
|
|
|
|
mw.echo.ui.BadgeLinkWidget.static.tagName = 'a';
|
|
|
|
|
2016-07-20 00:24:17 +00:00
|
|
|
/**
|
|
|
|
* Set the count labels for this button.
|
|
|
|
*
|
|
|
|
* @param {number} numItems Number of items
|
|
|
|
* @param {string} [label] Label of the button. Defaults to the item number.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, label ) {
|
|
|
|
label = label || numItems;
|
|
|
|
|
2016-09-26 17:08:43 +00:00
|
|
|
if ( this.count !== numItems ) {
|
|
|
|
this.count = numItems;
|
|
|
|
|
|
|
|
// Fire badge count change hook
|
|
|
|
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, label );
|
|
|
|
}
|
|
|
|
|
2016-07-20 00:24:17 +00:00
|
|
|
this.$element
|
|
|
|
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems )
|
|
|
|
.attr( 'data-counter-num', numItems )
|
|
|
|
.attr( 'data-counter-text', label );
|
|
|
|
};
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|