mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
e9264022a7
Added the following Javascript hooks: * ext.echo.notifications.beforeRender: Firing before a group of notification widgets are rendered, whether in the popup, in the special page, or in a cross-wiki bundle (which requires async loading) * ext.echo.badge.countChange: Fired when the badge count changes with the notification type, count and the label count for display purposes. * ext.echo.popup.onInitialize: Fired when the popup is opened and after notifications were fetched, with the context of the popup notification type. * ext.echo.special.onInitialize: Fired when the special page is ready and notifications were fetched. Note that it will be fired whenever the special page is updated with notifications list, as well, like when changing filter, remote wiki or pagination. The hooks were also documented in hooks.txt Bug: T146296 Change-Id: Ie3dc97f97e8d1f90b67f62fcdc65dd29cb379aad
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
( function ( mw, $ ) {
|
|
/**
|
|
* Notification badge button widget for echo popup.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.ButtonWidget
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration object
|
|
* @cfg {string} [type] The notification types this button represents;
|
|
* 'message', 'alert' or 'all'
|
|
* @cfg {string} [href] URL the badge links to
|
|
*/
|
|
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 } ) );
|
|
|
|
this.$element
|
|
.addClass( 'mw-echo-notifications-badge' );
|
|
|
|
this.count = 0;
|
|
this.type = config.type || 'alert';
|
|
this.setCount( config.numItems, config.label );
|
|
|
|
if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) {
|
|
this.$element.attr( 'href', config.href );
|
|
}
|
|
};
|
|
|
|
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';
|
|
|
|
/**
|
|
* 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;
|
|
|
|
if ( this.count !== numItems ) {
|
|
this.count = numItems;
|
|
|
|
// Fire badge count change hook
|
|
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, label );
|
|
}
|
|
|
|
this.$element
|
|
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems )
|
|
.attr( 'data-counter-num', numItems )
|
|
.attr( 'data-counter-text', label );
|
|
};
|
|
} )( mediaWiki, jQuery );
|