Merge "Minor adjustments to align with WikimediaUI color palette"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.watchlist.js
1 /*!
2 * JavaScript for Special:Watchlist
3 */
4 ( function ( mw, $, OO ) {
5 $( function () {
6 var $progressBar, $resetForm = $( '#mw-watchlist-resetbutton' );
7
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]' );
13
14 event.preventDefault();
15
16 // Disable reset button to prevent multiple concurrent requests
17 $button.prop( 'disabled', true );
18
19 // Show progress bar
20 if ( $progressBar ) {
21 $progressBar.css( 'visibility', 'visible' );
22 } else {
23 $progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element;
24 $progressBar.css( {
25 position: 'absolute',
26 width: '100%'
27 } );
28 $resetForm.append( $progressBar );
29 }
30
31 // Use action=setnotificationtimestamp to mark all as visited,
32 // then set all watchlist lines accordingly
33 new mw.Api().postWithToken( 'csrf', {
34 formatversion: 2,
35 action: 'setnotificationtimestamp',
36 entirewatchlist: true
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();
50 } );
51 } );
52
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();
59 } );
60 }
61 } );
62
63 }( mediaWiki, jQuery, OO ) );