| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
mw.echo.ui.BadgeLinkWidget = function MwEchoUiBadgeLinkWidget( config ) { |
| 17 |
config = config || {}; |
| 18 |
|
| 19 |
|
| 20 |
mw.echo.ui.BadgeLinkWidget.super.call( this, config ); |
| 21 |
|
| 22 |
|
| 23 |
OO.ui.mixin.LabelElement.call( this, Object.assign( { $label: this.$element }, config ) ); |
| 24 |
OO.ui.mixin.ButtonElement.call( this, Object.assign( { $button: this.$element }, config ) ); |
| 25 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { $titled: this.$element }, config ) ); |
| 26 |
OO.ui.mixin.FlaggedElement.call( this, Object.assign( {}, config, { $flagged: this.$element } ) ); |
| 27 |
|
| 28 |
this.$element |
| 29 |
.addClass( 'mw-echo-notifications-badge' ); |
| 30 |
|
| 31 |
this.count = 0; |
| 32 |
this.type = config.type || 'alert'; |
| 33 |
this.setCount( config.numItems || 0, config.convertedNumber ); |
| 34 |
|
| 35 |
if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) { |
| 36 |
this.$element.attr( 'href', config.href ); |
| 37 |
} |
| 38 |
if ( this.type === 'alert' ) { |
| 39 |
this.$element |
| 40 |
.addClass( 'oo-ui-icon-bell' ); |
| 41 |
} else { |
| 42 |
this.$element |
| 43 |
.addClass( 'oo-ui-icon-tray' ); |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
OO.inheritClass( mw.echo.ui.BadgeLinkWidget, OO.ui.Widget ); |
| 48 |
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.LabelElement ); |
| 49 |
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.ButtonElement ); |
| 50 |
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.TitledElement ); |
| 51 |
OO.mixinClass( mw.echo.ui.BadgeLinkWidget, OO.ui.mixin.FlaggedElement ); |
| 52 |
|
| 53 |
mw.echo.ui.BadgeLinkWidget.static.tagName = 'a'; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
mw.echo.ui.BadgeLinkWidget.prototype.onClick = function ( ev ) { |
| 63 |
ev.preventDefault(); |
| 64 |
this.emit( 'click' ); |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, convertedNumber ) { |
| 75 |
convertedNumber = convertedNumber !== undefined ? convertedNumber : numItems; |
| 76 |
|
| 77 |
this.$element |
| 78 |
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems ) |
| 79 |
.toggleClass( 'mw-echo-notifications-badge-long-label', convertedNumber.length > 2 ) |
| 80 |
.attr( 'data-counter-num', numItems ) |
| 81 |
.attr( 'data-counter-text', convertedNumber ); |
| 82 |
|
| 83 |
this.setLabel( mw.msg( |
| 84 |
this.type === 'alert' ? |
| 85 |
'echo-notification-alert' : |
| 86 |
'echo-notification-notice', |
| 87 |
convertedNumber |
| 88 |
) ); |
| 89 |
|
| 90 |
if ( this.count !== numItems ) { |
| 91 |
this.count = numItems; |
| 92 |
|
| 93 |
|
| 94 |
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, convertedNumber ); |
| 95 |
} |
| 96 |
}; |
| 97 |
}() ); |