mediawiki-extensions-Echo/modules/ext.echo.init.js
eranroz 381b7be7d8 Avoid flashes: late debounce causes annoying flashes
Validate elements are updated before replacing elements in the DOM.

Bug: T112168
Change-Id: Ia9556b0b9e9f5b0132be5a61a2cde7bb4dc5606e
2015-09-11 11:09:17 +00:00

60 lines
1.8 KiB
JavaScript

( function ( mw, $ ) {
'use strict';
if ( mw.echo.Logger.static.clickThroughEnabled ) {
mw.loader.using( 'ext.eventLogging', function () {
mw.eventLog.setDefaults( 'EchoInteraction', {
version: mw.config.get( 'wgEchoConfig' ).version,
userId: +mw.config.get( 'wgUserId' ),
editCount: +mw.config.get( 'wgUserEditCount' )
} );
} );
}
// Activate ooui
$( document ).ready( function () {
var $existingAlertLink = $( '#pt-notifications-alert a' ),
$existingMessageLink = $( '#pt-notifications-message a' ),
numAlerts = $existingAlertLink.text(),
numMessages = $existingMessageLink.text(),
hasUnseenAlerts = $existingAlertLink.hasClass( 'mw-echo-unseen-notifications' ),
hasUnseenMessages = $existingMessageLink.hasClass( 'mw-echo-unseen-notifications' ),
// Store links
links = {
notifications: $( '#pt-notifications-alert a' ).attr( 'href' ),
preferences: $( '#pt-preferences a' ).attr( 'href' )
};
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();
$existingMessageLink.replaceWith( mw.echo.ui.messageWidget.$element );
}
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();
$existingAlertLink.replaceWith( mw.echo.ui.alertWidget.$element );
} );
} )( mediaWiki, jQuery );