2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2015-09-17 00:05:52 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2018-05-22 14:57:23 +00:00
|
|
|
* @cfg {string} [numItems=0] The number of items that are in the button display
|
2017-09-02 00:08:21 +00:00
|
|
|
* @cfg {string} [convertedNumber] A converted version of the initial count
|
2015-09-17 00:05:52 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.BadgeLinkWidget = function MwEchoUiBadgeLinkWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.BadgeLinkWidget.super.call( this, config );
|
2015-09-17 00:05:52 +00:00
|
|
|
|
|
|
|
// 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';
|
2018-05-22 14:57:23 +00:00
|
|
|
this.setCount( config.numItems || 0, config.convertedNumber );
|
2015-09-24 01:13:37 +00:00
|
|
|
|
|
|
|
if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) {
|
|
|
|
this.$element.attr( 'href', config.href );
|
|
|
|
}
|
2019-04-13 18:45:11 +00:00
|
|
|
if ( this.type === 'alert' ) {
|
|
|
|
this.$element
|
|
|
|
.addClass( 'oo-ui-icon-bell' );
|
|
|
|
} else {
|
|
|
|
this.$element
|
|
|
|
.addClass( 'oo-ui-icon-tray' );
|
|
|
|
}
|
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
|
2017-09-02 00:08:21 +00:00
|
|
|
* @param {string} [convertedNumber] Label of the button. Defaults to the default message
|
|
|
|
* showing the item number.
|
2016-07-20 00:24:17 +00:00
|
|
|
*/
|
2017-09-02 00:08:21 +00:00
|
|
|
mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, convertedNumber ) {
|
|
|
|
convertedNumber = convertedNumber !== undefined ? convertedNumber : numItems;
|
2016-07-20 00:24:17 +00:00
|
|
|
|
2017-03-30 22:06:14 +00:00
|
|
|
this.$element
|
|
|
|
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems )
|
2017-09-02 00:08:21 +00:00
|
|
|
.toggleClass( 'mw-echo-notifications-badge-long-label', convertedNumber.length > 2 )
|
2017-03-30 22:06:14 +00:00
|
|
|
.attr( 'data-counter-num', numItems )
|
2017-09-02 00:08:21 +00:00
|
|
|
.attr( 'data-counter-text', convertedNumber );
|
|
|
|
|
|
|
|
this.setLabel( mw.msg(
|
|
|
|
this.type === 'alert' ?
|
|
|
|
'echo-notification-alert' :
|
|
|
|
'echo-notification-notice',
|
|
|
|
convertedNumber
|
|
|
|
) );
|
2017-03-30 22:06:14 +00:00
|
|
|
|
2016-09-26 17:08:43 +00:00
|
|
|
if ( this.count !== numItems ) {
|
|
|
|
this.count = numItems;
|
|
|
|
|
|
|
|
// Fire badge count change hook
|
2017-09-02 00:08:21 +00:00
|
|
|
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, convertedNumber );
|
2016-09-26 17:08:43 +00:00
|
|
|
}
|
2016-07-20 00:24:17 +00:00
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|