2015-08-13 00:54:16 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-03 01:56:13 +00:00
|
|
|
// Remove ?markasread=XYZ from the URL
|
|
|
|
var uri = new mw.Uri();
|
|
|
|
if ( uri.query.markasread !== undefined ) {
|
|
|
|
delete uri.query.markasread;
|
|
|
|
window.history.replaceState( null, document.title, uri );
|
|
|
|
}
|
|
|
|
|
2015-09-16 19:29:01 +00:00
|
|
|
mw.echo = mw.echo || {};
|
2016-08-01 23:31:18 +00:00
|
|
|
mw.echo.config = mw.echo.config || {};
|
|
|
|
// Set default max prioritized action links per item
|
|
|
|
mw.echo.config.maxPrioritizedActions = 2;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
// Activate ooui
|
2017-01-06 13:06:39 +00:00
|
|
|
$( function () {
|
2016-01-15 22:11:33 +00:00
|
|
|
var myWidget, echoApi,
|
2015-09-15 06:13:51 +00:00
|
|
|
$existingAlertLink = $( '#pt-notifications-alert a' ),
|
2016-07-21 18:19:17 +00:00
|
|
|
$existingMessageLink = $( '#pt-notifications-notice a' ),
|
2016-07-20 00:24:17 +00:00
|
|
|
numAlerts = $existingAlertLink.attr( 'data-counter-num' ),
|
|
|
|
numMessages = $existingMessageLink.attr( 'data-counter-num' ),
|
|
|
|
badgeLabelAlerts = $existingAlertLink.attr( 'data-counter-text' ),
|
|
|
|
badgeLabelMessages = $existingMessageLink.attr( 'data-counter-text' ),
|
2015-09-03 21:24:03 +00:00
|
|
|
hasUnseenAlerts = $existingAlertLink.hasClass( 'mw-echo-unseen-notifications' ),
|
|
|
|
hasUnseenMessages = $existingMessageLink.hasClass( 'mw-echo-unseen-notifications' ),
|
2015-08-13 00:54:16 +00:00
|
|
|
// Store links
|
|
|
|
links = {
|
2017-11-06 19:06:35 +00:00
|
|
|
notifications: $( '#pt-notifications-alert a' ).attr( 'href' ) || mw.util.getUrl( 'Special:Notifications' ),
|
|
|
|
preferences: ( $( '#pt-preferences a' ).attr( 'href' ) || mw.util.getUrl( 'Special:Preferences' ) ) +
|
|
|
|
'#mw-prefsection-echo'
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
// Respond to click on the notification button and load the UI on demand
|
2015-09-24 01:13:37 +00:00
|
|
|
$( '.mw-echo-notification-badge-nojs' ).click( function ( e ) {
|
2016-04-10 13:31:02 +00:00
|
|
|
var time = mw.now(),
|
|
|
|
myType = $( this ).parent().prop( 'id' ) === 'pt-notifications-alert' ? 'alert' : 'message';
|
2015-09-24 01:13:37 +00:00
|
|
|
|
2018-02-23 22:35:33 +00:00
|
|
|
if ( e.which !== 1 || $( this ).data( 'clicked' ) ) {
|
|
|
|
return false;
|
2015-09-24 01:13:37 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 22:35:33 +00:00
|
|
|
$( this ).data( 'clicked', true );
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
// Dim the button while we load
|
|
|
|
$( this ).addClass( 'mw-echo-notifications-badge-dimmed' );
|
|
|
|
|
|
|
|
// Fire the notification API requests
|
2016-08-04 14:42:11 +00:00
|
|
|
echoApi = new mw.echo.api.EchoApi();
|
2016-01-15 22:11:33 +00:00
|
|
|
echoApi.fetchNotifications( myType )
|
2015-11-11 23:22:36 +00:00
|
|
|
.then( function ( data ) {
|
|
|
|
mw.track( 'timing.MediaWiki.echo.overlay.api', mw.now() - time );
|
|
|
|
return data;
|
|
|
|
} );
|
2015-09-15 06:13:51 +00:00
|
|
|
|
|
|
|
// Load the ui
|
2016-01-20 23:05:21 +00:00
|
|
|
mw.loader.using( 'ext.echo.ui.desktop', function () {
|
2016-04-10 13:31:02 +00:00
|
|
|
var messageController,
|
|
|
|
alertController,
|
|
|
|
messageModelManager,
|
|
|
|
alertModelManager,
|
2016-03-15 21:13:19 +00:00
|
|
|
unreadMessageCounter,
|
|
|
|
unreadAlertCounter,
|
|
|
|
maxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' );
|
2016-02-27 01:19:06 +00:00
|
|
|
|
2015-11-21 01:54:12 +00:00
|
|
|
// Overlay
|
|
|
|
$( 'body' ).append( mw.echo.ui.$overlay );
|
2015-09-15 06:13:51 +00:00
|
|
|
// Load message button and popup if messages exist
|
|
|
|
if ( $existingMessageLink.length ) {
|
2016-03-15 21:13:19 +00:00
|
|
|
unreadMessageCounter = new mw.echo.dm.UnreadNotificationCounter( echoApi, 'message', maxNotificationCount );
|
2016-04-10 13:31:02 +00:00
|
|
|
messageModelManager = new mw.echo.dm.ModelManager( unreadMessageCounter, { type: 'message' } );
|
2016-11-18 21:16:43 +00:00
|
|
|
messageController = new mw.echo.Controller( echoApi, messageModelManager );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
mw.echo.ui.messageWidget = new mw.echo.ui.NotificationBadgeWidget(
|
|
|
|
messageController,
|
|
|
|
messageModelManager,
|
|
|
|
{
|
|
|
|
$overlay: mw.echo.ui.$overlay,
|
2016-07-20 00:24:17 +00:00
|
|
|
numItems: Number( numMessages ),
|
2016-04-10 13:31:02 +00:00
|
|
|
hasUnseen: hasUnseenMessages,
|
2016-07-20 00:24:17 +00:00
|
|
|
badgeIcon: 'tray',
|
2017-09-02 00:08:21 +00:00
|
|
|
convertedNumber: badgeLabelMessages,
|
2016-04-10 13:31:02 +00:00
|
|
|
links: links,
|
|
|
|
href: $existingMessageLink.attr( 'href' )
|
2015-10-26 22:23:22 +00:00
|
|
|
}
|
|
|
|
);
|
2015-09-15 06:13:51 +00:00
|
|
|
// Replace the link button with the ooui button
|
2015-09-17 00:05:52 +00:00
|
|
|
$existingMessageLink.parent().replaceWith( mw.echo.ui.messageWidget.$element );
|
2015-09-15 06:13:51 +00:00
|
|
|
}
|
2016-03-15 21:13:19 +00:00
|
|
|
unreadAlertCounter = new mw.echo.dm.UnreadNotificationCounter( echoApi, 'alert', maxNotificationCount );
|
2016-04-10 13:31:02 +00:00
|
|
|
alertModelManager = new mw.echo.dm.ModelManager( unreadAlertCounter, { type: 'alert' } );
|
2016-11-18 21:16:43 +00:00
|
|
|
alertController = new mw.echo.Controller( echoApi, alertModelManager );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
mw.echo.ui.alertWidget = new mw.echo.ui.NotificationBadgeWidget(
|
|
|
|
alertController,
|
|
|
|
alertModelManager,
|
|
|
|
{
|
2016-07-20 00:24:17 +00:00
|
|
|
numItems: Number( numAlerts ),
|
2017-09-02 00:08:21 +00:00
|
|
|
convertedNumber: badgeLabelAlerts,
|
2016-04-10 13:31:02 +00:00
|
|
|
hasUnseen: hasUnseenAlerts,
|
2016-07-20 00:24:17 +00:00
|
|
|
badgeIcon: 'bell',
|
2016-04-10 13:31:02 +00:00
|
|
|
links: links,
|
|
|
|
$overlay: mw.echo.ui.$overlay,
|
|
|
|
href: $existingAlertLink.attr( 'href' )
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-07-21 23:18:05 +00:00
|
|
|
alertModelManager.on( 'allTalkRead', function () {
|
|
|
|
// If there was a talk page notification, get rid of it
|
|
|
|
$( '#pt-mytalk a' )
|
|
|
|
.removeClass( 'mw-echo-alert' )
|
|
|
|
.text( mw.msg( 'mytalk' ) );
|
|
|
|
} );
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
// Replace the link button with the ooui button
|
2015-09-17 00:05:52 +00:00
|
|
|
$existingAlertLink.parent().replaceWith( mw.echo.ui.alertWidget.$element );
|
2015-09-15 06:13:51 +00:00
|
|
|
|
|
|
|
// HACK: Now that the module loaded, show the popup
|
|
|
|
myWidget = myType === 'alert' ? mw.echo.ui.alertWidget : mw.echo.ui.messageWidget;
|
2016-01-15 22:11:33 +00:00
|
|
|
myWidget.once( 'finishLoading', function () {
|
2015-09-22 18:55:01 +00:00
|
|
|
// Log timing after notifications are shown
|
|
|
|
mw.track( 'timing.MediaWiki.echo.overlay', mw.now() - time );
|
|
|
|
} );
|
2015-09-15 06:13:51 +00:00
|
|
|
myWidget.popup.toggle( true );
|
2015-09-24 21:33:21 +00:00
|
|
|
mw.track( 'timing.MediaWiki.echo.overlay.ooui', mw.now() - time );
|
2015-08-13 00:54:16 +00:00
|
|
|
} );
|
2015-09-15 22:58:13 +00:00
|
|
|
|
|
|
|
if ( hasUnseenAlerts || hasUnseenMessages ) {
|
|
|
|
// Clicked on the flyout due to having unread notifications
|
|
|
|
mw.track( 'counter.MediaWiki.echo.unseen.click' );
|
|
|
|
}
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
// Prevent default
|
|
|
|
return false;
|
2015-08-13 00:54:16 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|