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