bfe2c1c3ae719c7b8fd2df31a0e11ce4f2954827
[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 $resetForm = $( '#mw-watchlist-resetbutton' ),
7 $progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element;
8
9 $progressBar.css( {
10 visibility: 'hidden',
11 position: 'absolute',
12 width: '100%'
13 } );
14 $resetForm.append( $progressBar );
15
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();
21
22 OO.ui.confirm( mw.msg( 'watchlist-mark-all-visited' ) ).done( function ( confirmed ) {
23 var $button;
24
25 if ( 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' );
29
30 // Use action=setnotificationtimestamp to mark all as visited,
31 // then set all watchlist lines accordingly
32 new mw.Api().postWithToken( 'csrf', {
33 formatversion: 2,
34 action: 'setnotificationtimestamp',
35 entirewatchlist: true
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();
46 } );
47
48 }
49 } );
50 } );
51
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();
58 } );
59 }
60 } );
61
62 }( mediaWiki, jQuery, OO ) );