/*global window:false */ ( function( $, mw ) { 'use strict'; mw.echo.overlay = { 'updateCount' : function( newCount ) { // Accomodate '10' or '100+'. Numbers need to be // passed as numbers for correct behavior of '0'. if ( !isNaN( newCount ) ) { newCount = Number( newCount ); } if ( mw.echo.overlay.configuration['notifications-link-full'] ) { $( '#pt-notifications > a' ) .text( mw.msg( 'echo-link' ) ) .badge( newCount, true, true ); } else { $( '#pt-notifications > a' ) .addClass( 'mw-echo-short-link' ) .text( '' ) .badge( newCount, true, true ); } mw.echo.overlay.notificationCount = newCount; }, 'configuration' : mw.config.get( 'wgEchoOverlayConfiguration' ), 'buildOverlay' : function( callback ) { var notificationLimit, $overlay = $( '
' ).addClass( 'mw-echo-overlay' ), $link = $( '#pt-notifications a' ), $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; $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 = $( '