/*global window:false */ ( function ( $, mw ) { 'use strict'; // backwards compatibility <= MW 1.21 var getUrl = mw.util.getUrl || mw.util.wikiGetlink; function EchoOverlay( apiResultNotifications ) { this.api = mw.echo.overlay.api; // set internal properties this.tabs = []; this._buildOverlay( apiResultNotifications ); } function EchoOverlayTab( name, notifications ) { this.api = mw.echo.overlay.api; this.name = name; this.unread = []; this._buildList( notifications ); } EchoOverlayTab.prototype = { unread: [], getUnreadIds: function() { return this.unread; }, /** * Mark all unread notifications as read * @method * @return jQuery.Deferred */ markAsRead: function() { var self = this; // only need to mark as read if there is unread item if ( this.unread.length ) { return this.api.post( mw.echo.desktop.appendUseLang( { 'action' : 'echomarkread', 'list' : this.unread.join( '|' ), 'token': mw.user.tokens.get( 'editToken' ) } ) ).then( function ( result ) { return result.query.echomarkread[self.name]; } ).done( function() { // reset internal state of unread messages self.unread = []; } ); } else { return new $.Deferred(); } }, /** * Builds an Echo notifications list * @method * @param string tabName the tab * @param object notifications as returned by the api of notification items * @return jQuery element */ _buildList: function( notifications ) { var self = this, $ul = $( '