2015-08-13 00:54:16 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
'use strict';
|
|
|
|
|
2015-09-16 19:29:01 +00:00
|
|
|
mw.echo = mw.echo || {};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
mw.echo.apiCallParams = {
|
|
|
|
action: 'query',
|
|
|
|
meta: 'notifications',
|
|
|
|
// We have to send the API 'groupbysection' otherwise
|
|
|
|
// the 'messageunreadfirst' doesn't do anything.
|
|
|
|
// TODO: Fix the API.
|
|
|
|
notgroupbysection: 1,
|
|
|
|
notmessageunreadfirst: 1,
|
|
|
|
notformat: 'flyout',
|
|
|
|
notlimit: 25,
|
|
|
|
notprop: 'index|list|count',
|
|
|
|
uselang: mw.config.get( 'wgUserLanguage' )
|
|
|
|
};
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
// Activate ooui
|
|
|
|
$( document ).ready( function () {
|
2015-09-15 06:13:51 +00:00
|
|
|
var apiRequest, myWidget,
|
|
|
|
$existingAlertLink = $( '#pt-notifications-alert a' ),
|
2015-09-07 23:54:47 +00:00
|
|
|
$existingMessageLink = $( '#pt-notifications-message a' ),
|
2015-08-13 00:54:16 +00:00
|
|
|
numAlerts = $existingAlertLink.text(),
|
|
|
|
numMessages = $existingMessageLink.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 = {
|
2015-09-08 15:27:40 +00:00
|
|
|
notifications: $( '#pt-notifications-alert a' ).attr( 'href' ),
|
2015-09-11 15:15:26 +00:00
|
|
|
preferences: $( '#pt-preferences a' ).attr( 'href' ) + '#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
|
|
|
|
$( '.mw-echo-notification-badge-nojs' ).click( function () {
|
|
|
|
var myType = $( this ).parent().prop( 'id' ) === 'pt-notifications-alert' ? 'alert' : 'message';
|
|
|
|
// Dim the button while we load
|
|
|
|
$( this ).addClass( 'mw-echo-notifications-badge-dimmed' );
|
|
|
|
|
|
|
|
// Fire the notification API requests
|
|
|
|
apiRequest = new mw.Api( { ajax: { cache: false } } ).get( $.extend( { notsections: myType }, mw.echo.apiCallParams ) );
|
|
|
|
|
|
|
|
// Load the ui
|
|
|
|
mw.loader.using( 'ext.echo.ui', function () {
|
|
|
|
// Load message button and popup if messages exist
|
|
|
|
if ( $existingMessageLink.length ) {
|
|
|
|
mw.echo.ui.messageWidget = new mw.echo.ui.NotificationBadgeWidget( {
|
|
|
|
type: 'message',
|
|
|
|
markReadWhenSeen: false,
|
|
|
|
numItems: numMessages,
|
|
|
|
hasUnseen: hasUnseenMessages,
|
|
|
|
badgeIcon: 'speechBubble',
|
|
|
|
links: links
|
|
|
|
} );
|
|
|
|
// avoid late debouncedUpdateThemeClasses
|
|
|
|
mw.echo.ui.messageWidget.debouncedUpdateThemeClasses();
|
|
|
|
// Replace the link button with the ooui button
|
|
|
|
$existingMessageLink.replaceWith( mw.echo.ui.messageWidget.$element );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load alerts popup and button
|
|
|
|
mw.echo.ui.alertWidget = new mw.echo.ui.NotificationBadgeWidget( {
|
|
|
|
type: 'alert',
|
|
|
|
markReadWhenSeen: true,
|
|
|
|
numItems: numAlerts,
|
|
|
|
hasUnseen: hasUnseenAlerts,
|
|
|
|
badgeIcon: {
|
|
|
|
seen: 'bell',
|
|
|
|
unseen: 'bellOn'
|
|
|
|
},
|
|
|
|
links: links
|
|
|
|
} );
|
|
|
|
// avoid late debouncedUpdateThemeClasses
|
|
|
|
mw.echo.ui.alertWidget.debouncedUpdateThemeClasses();
|
|
|
|
// Replace the link button with the ooui button
|
|
|
|
$existingAlertLink.replaceWith( mw.echo.ui.alertWidget.$element );
|
|
|
|
|
|
|
|
// HACK: Now that the module loaded, show the popup
|
|
|
|
myWidget = myType === 'alert' ? mw.echo.ui.alertWidget : mw.echo.ui.messageWidget;
|
|
|
|
myWidget.populateNotifications( apiRequest );
|
|
|
|
myWidget.popup.toggle( true );
|
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
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
} )( mediaWiki, jQuery );
|