X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.watchlist.js;h=7cc9b9bb5ad3240f368f930fcf3c03fea3e6885e;hb=93be2c205a66701416067f8fc26fe989ffab296e;hp=a35f4d10641d1a6c57bc306cd8513800ccc97c9d;hpb=4d20257029329cdffd0734e4b6a4fcc50ec5445d;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special/mediawiki.special.watchlist.js b/resources/src/mediawiki.special/mediawiki.special.watchlist.js index a35f4d1064..7cc9b9bb5a 100644 --- a/resources/src/mediawiki.special/mediawiki.special.watchlist.js +++ b/resources/src/mediawiki.special/mediawiki.special.watchlist.js @@ -1,15 +1,61 @@ /*! * JavaScript for Special:Watchlist - * - * This script is only loaded, if the user opt-in a setting in Special:Preferences, - * that the watchlist should be automatically reloaded, when a filter option is - * changed in the header form. */ -jQuery( function ( $ ) { - // add a listener on all form elements in the header form - $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () { - // submit the form, when one of the input fields was changed - $( '#mw-watchlist-form' ).submit(); +( function ( mw, $, OO ) { + $( function () { + 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 ) { + var $button = $resetForm.find( 'input[name=mw-watchlist-reset-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(); + } ); + } ); + + // if the user wishes to reload the watchlist whenever a filter changes + if ( mw.user.options.get( 'watchlistreloadautomatically' ) ) { + // add a listener on all form elements in the header form + $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () { + // submit the form when one of the input fields is modified + $( '#mw-watchlist-form' ).submit(); + } ); + } } ); -} ); +}( mediaWiki, jQuery, OO ) );