2017-07-12 15:12:40 +00:00
|
|
|
( function ( M ) {
|
2019-02-07 16:34:18 +00:00
|
|
|
var
|
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend = mobile.mfExtend,
|
2019-02-07 16:34:18 +00:00
|
|
|
View = mobile.View,
|
|
|
|
util = mobile.util,
|
|
|
|
Icon = mobile.Icon,
|
2018-01-05 18:52:17 +00:00
|
|
|
notificationIcon = new Icon( {
|
2019-07-09 19:12:51 +00:00
|
|
|
name: 'bellOutline-base20',
|
|
|
|
glyphPrefix: 'wikimedia'
|
2019-03-19 23:21:56 +00:00
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
2019-03-19 23:21:56 +00:00
|
|
|
* A notification button for displaying a notifications overlay
|
2017-07-12 15:12:40 +00:00
|
|
|
* @class NotificationButton
|
|
|
|
* @extends View
|
2018-07-10 22:47:31 +00:00
|
|
|
* @param {Object} options Configuration options
|
2019-03-19 23:21:56 +00:00
|
|
|
* @param {string} options.notificationIconClass e.g. mw-ui-icon for icon
|
|
|
|
* @param {boolean} options.hasUnseenNotifications whether the user has unseen notifications
|
|
|
|
* @param {number} options.notificationCountRaw number of unread notifications
|
|
|
|
* @param {string} options.title tooltip for badge
|
|
|
|
* @param {string} options.url to see all notifications
|
|
|
|
* @param {boolean} options.hasNotifications whether the user has unseen notifications
|
|
|
|
* @param {Function} options.onClick handler for when the badge is clicked
|
|
|
|
* @memberof NotificationBadge
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function NotificationBadge( options ) {
|
2019-03-19 23:21:56 +00:00
|
|
|
var $el, $notificationAnchor,
|
2017-11-28 19:46:55 +00:00
|
|
|
count = options.notificationCountRaw || 0,
|
2017-07-12 15:12:40 +00:00
|
|
|
el = options.el;
|
|
|
|
|
|
|
|
if ( el ) {
|
2019-03-19 23:21:56 +00:00
|
|
|
// Learn properties based on current element
|
2017-07-12 15:12:40 +00:00
|
|
|
$el = $( el );
|
2019-03-19 23:21:56 +00:00
|
|
|
options.hasUnseenNotifications = $el.find( '.notification-unseen' ).length > 0;
|
2017-07-12 15:12:40 +00:00
|
|
|
options.hasNotifications = options.hasUnseenNotifications;
|
2019-03-19 23:21:56 +00:00
|
|
|
$notificationAnchor = $el.find( 'a' );
|
|
|
|
options.title = $notificationAnchor.attr( 'title' );
|
|
|
|
options.url = $notificationAnchor.attr( 'href' );
|
2017-10-18 18:28:37 +00:00
|
|
|
count = Number( $el.find( 'span' ).data( 'notification-count' ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2018-11-22 19:10:40 +00:00
|
|
|
View.call( this,
|
2019-03-19 23:21:56 +00:00
|
|
|
util.extend( {
|
|
|
|
notificationIconClass: notificationIcon.getClassName(),
|
|
|
|
hasNotifications: false,
|
|
|
|
hasUnseenNotifications: false,
|
|
|
|
notificationCountRaw: 0
|
|
|
|
}, options, {
|
2018-11-22 19:10:40 +00:00
|
|
|
isBorderBox: false
|
|
|
|
} )
|
|
|
|
);
|
2017-11-28 19:46:55 +00:00
|
|
|
this.url = options.url;
|
2017-10-18 18:28:37 +00:00
|
|
|
this.setCount( count );
|
2019-03-19 23:21:56 +00:00
|
|
|
if ( options.onClick ) {
|
|
|
|
this.$el.on( 'click', options.onClick );
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend( NotificationBadge, View, {
|
2019-07-02 21:10:10 +00:00
|
|
|
template: mw.template.get( 'skins.minerva.scripts', 'badge.mustache' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Update the notification count
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof NotificationBadge
|
|
|
|
* @instance
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {number} count
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
setCount: function ( count ) {
|
2017-10-18 18:28:37 +00:00
|
|
|
if ( count > 100 ) {
|
|
|
|
count = 100;
|
|
|
|
}
|
|
|
|
this.options.notificationCountRaw = count;
|
|
|
|
this.options.notificationCountString = mw.message( 'echo-badge-count',
|
|
|
|
mw.language.convertNumber( count )
|
|
|
|
).text();
|
2017-07-12 15:12:40 +00:00
|
|
|
this.options.isNotificationCountZero = count === 0;
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Marks all notifications as seen
|
2018-08-20 23:40:40 +00:00
|
|
|
*
|
|
|
|
* @memberof NotificationBadge
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
markAsSeen: function () {
|
|
|
|
this.options.hasUnseenNotifications = false;
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2019-07-02 21:10:10 +00:00
|
|
|
module.exports = NotificationBadge;
|
2019-09-27 18:53:01 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2017-07-12 15:12:40 +00:00
|
|
|
}( mw.mobileFrontend ) );
|