/*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' } ).done( 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, 'data-notification-event': data.id, 'data-notification-type': data.type } ) .addClass( 'mw-echo-notification' ) .append( data['*'] ) .appendTo( $ul ); // Grey links in the notification title and footer (except on hover) $li.find( '.mw-echo-title a, .mw-echo-notification-footer a' ) .addClass( 'mw-echo-grey-link' ); $li.hover( function() { $( this ).find( '.mw-echo-title a' ).removeClass( 'mw-echo-grey-link' ); }, function() { $( this ).find( '.mw-echo-title a' ).addClass( 'mw-echo-grey-link' ); } ); // If there is a primary link, make the entire notification clickable. if ( $li.find( '.mw-echo-notification-primary-link' ).length ) { $li.css( 'cursor', 'pointer' ); $li.click( function() { if ( mw.echo.clickThroughEnabled ) { // Log the clickthrough mw.echo.logInteraction( 'notification-link-click', 'flyout', data.id, data.type ); } window.location.href = $li.find( '.mw-echo-notification-primary-link' ).attr( 'href' ); } ); } mw.echo.setupNotificationLogging( $li, 'flyout' ); 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 = $( '