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 event
.preventDefault();
14 OO
.ui
.confirm( mw
.msg( 'watchlist-mark-all-visited' ) )
15 .done( function ( confirmed
) {
22 // Disable reset button to prevent multiple requests
23 $button
= $resetForm
.find( 'input[name=mw-watchlist-reset-submit]' );
24 $button
.prop( 'disabled', true );
28 $progressBar
.css( 'visibility', 'visible' );
30 $progressBar
= new OO
.ui
.ProgressBarWidget( { progress
: false } ).$element
;
35 $resetForm
.append( $progressBar
);
38 // Use action=setnotificationtimestamp to mark all as visited,
39 // then set all watchlist lines accordingly
40 new mw
.Api().postWithToken( 'csrf', {
42 action
: 'setnotificationtimestamp',
44 } ).done( function () {
45 // Enable button again
46 $button
.prop( 'disabled', false );
47 // Hide the button because further clicks can not generate any visual changes
48 $button
.css( 'visibility', 'hidden' );
49 $progressBar
.css( 'visibility', 'hidden' );
50 $( '.mw-changeslist-line-watched' )
51 .removeClass( 'mw-changeslist-line-watched' )
52 .addClass( 'mw-changeslist-line-not-watched' );
53 } ).fail( function () {
54 // On error, fall back to server-side reset
55 // First remove this submit listener and then re-submit the form
56 $resetForm
.off( 'submit' ).submit();
61 // if the user wishes to reload the watchlist whenever a filter changes
62 if ( mw
.user
.options
.get( 'watchlistreloadautomatically' ) ) {
63 // add a listener on all form elements in the header form
64 $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () {
65 // submit the form when one of the input fields is modified
66 $( '#mw-watchlist-form' ).submit();
71 }( mediaWiki
, jQuery
, OO
) );