2 * JavaScript for Special:UnwatchedPages
6 $( 'a.mw-watch-link' ).on( 'click', function ( e
) {
10 $subjectLink
= $link
.closest( 'li' ).children( 'a' ).eq( 0 ),
11 title
= mw
.util
.getParamValue( 'title', $link
.attr( 'href' ) );
13 title
= mw
.Title
.newFromText( title
).toText();
14 $link
.addClass( 'mw-watch-link-disabled' );
16 // Preload the notification module for mw.notify
17 mw
.loader
.load( 'mediawiki.notification' );
19 // Use the class to determine whether to watch or unwatch
20 // eslint-disable-next-line no-jquery/no-class-state
21 if ( !$subjectLink
.hasClass( 'mw-watched-item' ) ) {
22 $link
.text( mw
.msg( 'watching' ) );
23 promise
= api
.watch( title
).done( function () {
24 $subjectLink
.addClass( 'mw-watched-item' );
25 $link
.text( mw
.msg( 'unwatch' ) );
26 mw
.notify( mw
.msg( 'addedwatchtext-short', title
) );
27 } ).fail( function () {
28 $link
.text( mw
.msg( 'watch' ) );
29 mw
.notify( mw
.msg( 'watcherrortext', title
), { type
: 'error' } );
32 $link
.text( mw
.msg( 'unwatching' ) );
33 promise
= api
.unwatch( title
).done( function () {
34 $subjectLink
.removeClass( 'mw-watched-item' );
35 $link
.text( mw
.msg( 'watch' ) );
36 mw
.notify( mw
.msg( 'removedwatchtext-short', title
) );
37 } ).fail( function () {
38 $link
.text( mw
.msg( 'unwatch' ) );
39 mw
.notify( mw
.msg( 'watcherrortext', title
), { type
: 'error' } );
43 promise
.always( function () {
44 $link
.removeClass( 'mw-watch-link-disabled' );