Merge "Change delimiter for multiple namespaces and tags"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.watchlist.js
index bfe2c1c..7cc9b9b 100644 (file)
@@ -3,49 +3,48 @@
  */
 ( function ( mw, $, OO ) {
        $( function () {
-               var $resetForm = $( '#mw-watchlist-resetbutton' ),
-                       $progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element;
-
-               $progressBar.css( {
-                       visibility: 'hidden',
-                       position: 'absolute',
-                       width: '100%'
-               } );
-               $resetForm.append( $progressBar );
+               var $progressBar, $resetForm = $( '#mw-watchlist-resetbutton' );
 
                // If the user wants to reset their watchlist, use an API call to do so (no reload required)
                // Adapted from a user script by User:NQ of English Wikipedia
                // (User:NQ/WatchlistResetConfirm.js)
                $resetForm.submit( function ( event ) {
-                       event.preventDefault();
+                       var $button = $resetForm.find( 'input[name=mw-watchlist-reset-submit]' );
 
-                       OO.ui.confirm( mw.msg( 'watchlist-mark-all-visited' ) ).done( function ( confirmed ) {
-                               var $button;
-
-                               if ( confirmed ) {
-                                       // Disable reset button to prevent multiple requests and show progress bar
-                                       $button = $resetForm.find( 'input[name=mw-watchlist-reset-submit]' ).prop( 'disabled', true );
-                                       $progressBar.css( 'visibility', 'visible' );
-
-                                       // Use action=setnotificationtimestamp to mark all as visited,
-                                       // then set all watchlist lines accordingly
-                                       new mw.Api().postWithToken( 'csrf', {
-                                               formatversion: 2,
-                                               action: 'setnotificationtimestamp',
-                                               entirewatchlist: true
-                                       } ).done( function () {
-                                               $button.css( 'visibility', 'hidden' );
-                                               $progressBar.css( 'visibility', 'hidden' );
-                                               $( '.mw-changeslist-line-watched' )
-                                                       .removeClass( 'mw-changeslist-line-watched' )
-                                                       .addClass( 'mw-changeslist-line-not-watched' );
-                                       } ).fail( function () {
-                                               // On error, fall back to server-side reset
-                                               // First remove this submit listener and then re-submit the form
-                                               $resetForm.off( 'submit' ).submit();
-                                       } );
+                       event.preventDefault();
 
-                               }
+                       // Disable reset button to prevent multiple concurrent requests
+                       $button.prop( 'disabled', true );
+
+                       if ( !$progressBar ) {
+                               $progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element;
+                               $progressBar.css( {
+                                       position: 'absolute',
+                                       width: '100%'
+                               } );
+                       }
+                       // Show progress bar
+                       $resetForm.append( $progressBar );
+
+                       // Use action=setnotificationtimestamp to mark all as visited,
+                       // then set all watchlist lines accordingly
+                       new mw.Api().postWithToken( 'csrf', {
+                               formatversion: 2,
+                               action: 'setnotificationtimestamp',
+                               entirewatchlist: true
+                       } ).done( function () {
+                               // Enable button again
+                               $button.prop( 'disabled', false );
+                               // Hide the button because further clicks can not generate any visual changes
+                               $button.css( 'visibility', 'hidden' );
+                               $progressBar.detach();
+                               $( '.mw-changeslist-line-watched' )
+                                       .removeClass( 'mw-changeslist-line-watched' )
+                                       .addClass( 'mw-changeslist-line-not-watched' );
+                       } ).fail( function () {
+                               // On error, fall back to server-side reset
+                               // First remove this submit listener and then re-submit the form
+                               $resetForm.off( 'submit' ).submit();
                        } );
                } );