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 );
21 $progressBar
.css( 'visibility', 'visible' );
23 $progressBar
= new OO
.ui
.ProgressBarWidget( { progress
: false } ).$element
;
28 $resetForm
.append( $progressBar
);
31 // Use action=setnotificationtimestamp to mark all as visited,
32 // then set all watchlist lines accordingly
33 new mw
.Api().postWithToken( 'csrf', {
35 action
: 'setnotificationtimestamp',
37 } ).done( function () {
38 // Enable button again
39 $button
.prop( 'disabled', false );
40 // Hide the button because further clicks can not generate any visual changes
41 $button
.css( 'visibility', 'hidden' );
42 $progressBar
.css( 'visibility', 'hidden' );
43 $( '.mw-changeslist-line-watched' )
44 .removeClass( 'mw-changeslist-line-watched' )
45 .addClass( 'mw-changeslist-line-not-watched' );
46 } ).fail( function () {
47 // On error, fall back to server-side reset
48 // First remove this submit listener and then re-submit the form
49 $resetForm
.off( 'submit' ).submit();
53 // if the user wishes to reload the watchlist whenever a filter changes
54 if ( mw
.user
.options
.get( 'watchlistreloadautomatically' ) ) {
55 // add a listener on all form elements in the header form
56 $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () {
57 // submit the form when one of the input fields is modified
58 $( '#mw-watchlist-form' ).submit();
63 }( mediaWiki
, jQuery
, OO
) );