/*global window:false */ ( function ( $, mw ) { 'use strict'; mw.echo.overlay = { /** * @param newCount formatted count * @param rawCount unformatted count */ updateCount: function ( newCount, rawCount ) { var $badge = $( '.mw-echo-notifications-badge' ); $badge.text( newCount ); if ( rawCount !== '0' && rawCount !== 0 ) { $badge.addClass( 'mw-echo-unread-notifications' ); } else { $badge.removeClass( 'mw-echo-unread-notifications' ); } }, configuration: mw.config.get( 'wgEchoOverlayConfiguration' ), removeOverlay: function () { $( '.mw-echo-overlay, .mw-echo-overlay-pokey' ).fadeOut( 'fast', function () { $( this ).remove(); } ); }, buildOverlay: function ( callback ) { var notificationLimit, $overlay = $( '
' ).addClass( 'mw-echo-overlay' ), $prefLink = $( '#pt-preferences a' ), count = 0, apiData, api = new mw.Api( { ajax: { cache: false } } ); // Set notification limit based on height of the window notificationLimit = Math.floor( ( $( window ).height() - 134 ) / 90 ); if ( notificationLimit < 1 ) { notificationLimit = 1; } else if ( notificationLimit > 8 ) { notificationLimit = 8; } apiData = { 'action' : 'query', 'meta' : 'notifications', 'notformat' : 'flyout', 'notlimit' : notificationLimit, 'notprop' : 'index|list|count' }; api.get( mw.echo.desktop.appendUseLang( apiData ) ).done( function ( result ) { var notifications = result.query.notifications, unread = [], unreadTotalCount = result.query.notifications.count, unreadRawTotalCount = result.query.notifications.rawcount, $title = $( '
' ).addClass( 'mw-echo-overlay-title' ), $ul = $( '