( function( $, mw ) { 'use strict'; mw.echo.special = { 'timestamp': 0, 'offset': 0, 'header': '', 'processing': false, 'moreData': '0', 'optionsToken': '', /** * Show the dismiss interface (Dismiss and Cancel buttons). */ 'showDismissOption': function( closeBox ) { var $notification = $( closeBox ).parent(); $( closeBox ).hide(); $notification.data( 'dismiss', true ); $notification.find( '.mw-echo-dismiss' ).show(); }, /** * Handle clicking the Dismiss button. * First we have to retrieve the options token. */ 'dismiss': function( notification ) { var eventType, _this = this, $notification = $( notification ); var tokenRequest = { 'action': 'tokens', 'type' : 'options', 'format': 'json' }; if ( this.optionsToken ) { this.finishDismiss( notification ); } else { $.ajax( { type: 'get', url: mw.util.wikiScript( 'api' ), data: tokenRequest, dataType: 'json', success: function( data ) { if ( typeof data.tokens.optionstoken === 'undefined' ) { alert( mw.msg( 'echo-error-token' ) ); } else { _this.optionsToken = data.tokens.optionstoken; _this.finishDismiss( notification ); } /* // TODO: Use something like this for the flyout to immediately // hide the notifications without reloading the page. We reload // the page in the archive interface since we're also dealing // with date headers. eventType = $notification.attr( 'data-notification-type' ); $( 'li[data-notification-type="' + eventType + '"]' ).hide(); */ }, error: function() { alert( mw.msg( 'echo-error-token' ) ); } } ); } }, /** * Change the user's preferences related to this notification type and * reload the page. */ 'finishDismiss': function( notification ) { var _this = this, $notification = $( notification ), eventType = $notification.attr( 'data-notification-type' ), change = 'echo-web-notifications' + eventType + '=0', prefRequest = { 'action': 'options', 'change': change, 'token': this.optionsToken, 'format': 'json' }; $.ajax( { type: 'post', url: mw.util.wikiScript( 'api' ), data: prefRequest, dataType: 'json', success: function( data ) { window.location.reload(); }, error: function() { alert( mw.msg( 'echo-error-preference' ) ); } } ); }, 'setUpDismissability' : function( notification ) { var $dismissButton, $cancelButton, _this = this, $notification = $( notification ); // Add dismiss box var $closebox = $( '
' ) .addClass( 'mw-echo-close-box' ) .css( 'display', 'none' ) .click( function() { _this.showDismissOption( this ); } ); $notification.append( $closebox ); // Add dismiss and cancel buttons $dismissButton = $( '