/*global window:false */ ( function( $, mw ) { 'use strict'; mw.echo.overlay = { 'updateCount' : function( newCount ) { var $badge = $( '.mw-echo-notifications-badge' ); $badge.text( newCount ); // newCount could be '99+' or another string. // Checking for number as well just to be paranoid. if ( newCount !== '0' && newCount !== 0 ) { $badge.addClass( 'mw-echo-unread-notifications' ); } else { $badge.removeClass( 'mw-echo-unread-notifications' ); } }, 'configuration' : mw.config.get( 'wgEchoOverlayConfiguration' ), 'buildOverlay' : function( callback ) { var notificationLimit, $overlay = $( '
' ).addClass( 'mw-echo-overlay' ), $prefLink = $( '#pt-preferences a' ), count = 0, Api = new mw.Api(); // 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; } Api.get( { 'action' : 'query', 'meta' : 'notifications', 'notformat' : 'flyout', 'notlimit' : notificationLimit, 'notprop' : 'index|list|count' }, { 'ok' : function( result ) { var notifications = result.query.notifications, unread = [], unreadTotalCount = result.query.notifications.count, $title = $( '
' ), $ul = $( '' ), titleText = '', overflow = false, $overlayFooter, $markReadButton; if ( unreadTotalCount !== undefined ) { mw.echo.overlay.updateCount( unreadTotalCount ); } $ul.css( 'max-height', notificationLimit * 95 + 'px' ); $.each( notifications.index, function( index, id ) { var data = notifications.list[id], $li = $( '
  • ' ) .data( 'details', data ) .data( 'id', id ) .attr( 'data-notification-category', data.category ) .addClass( 'mw-echo-notification' ) .append( data['*'] ) .appendTo( $ul ); if ( !data.read ) { $li.addClass( 'mw-echo-unread' ); unread.push( id ); } // Set up each individual notification with a close box and dismiss // interface if it is dismissable. if ( $li.find( '.mw-echo-dismiss' ).length ) { mw.echo.setUpDismissability( $li ); } } ); if ( notifications.index.length > 0 ) { if ( isNaN( unreadTotalCount ) || unreadTotalCount > unread.length ) { titleText = mw.msg( 'echo-overlay-title-overflow', unread.length, unreadTotalCount ); overflow = true; } else { titleText = mw.msg( 'echo-overlay-title' ); } } else { titleText = mw.msg( 'echo-none' ); } $markReadButton = $( '