2 * JavaScript for Special:Watchlist
4 ( function ( mw
, $, OO
) {
6 var $progressBar
, $resetForm
= $( '#mw-watchlist-resetbutton' );
8 // If the user wants to reset their watchlist, use an API call to do so (no reload required)
9 // Adapted from a user script by User:NQ of English Wikipedia
10 // (User:NQ/WatchlistResetConfirm.js)
11 $resetForm
.submit( function ( event
) {
12 var $button
= $resetForm
.find( 'input[name=mw-watchlist-reset-submit]' );
14 event
.preventDefault();
16 // Disable reset button to prevent multiple concurrent requests
17 $button
.prop( 'disabled', true );
19 if ( !$progressBar
) {
20 $progressBar
= new OO
.ui
.ProgressBarWidget( { progress
: false } ).$element
;
27 $resetForm
.append( $progressBar
);
29 // Use action=setnotificationtimestamp to mark all as visited,
30 // then set all watchlist lines accordingly
31 new mw
.Api().postWithToken( 'csrf', {
33 action
: 'setnotificationtimestamp',
35 } ).done( function () {
36 // Enable button again
37 $button
.prop( 'disabled', false );
38 // Hide the button because further clicks can not generate any visual changes
39 $button
.css( 'visibility', 'hidden' );
40 $progressBar
.detach();
41 $( '.mw-changeslist-line-watched' )
42 .removeClass( 'mw-changeslist-line-watched' )
43 .addClass( 'mw-changeslist-line-not-watched' );
44 } ).fail( function () {
45 // On error, fall back to server-side reset
46 // First remove this submit listener and then re-submit the form
47 $resetForm
.off( 'submit' ).submit();
51 // if the user wishes to reload the watchlist whenever a filter changes
52 if ( mw
.user
.options
.get( 'watchlistreloadautomatically' ) ) {
53 // add a listener on all form elements in the header form
54 $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () {
55 // submit the form when one of the input fields is modified
56 $( '#mw-watchlist-form' ).submit();
61 }( mediaWiki
, jQuery
, OO
) );