2 * JavaScript for Special:UnwatchedPages
6 $( 'a.mw-watch-link' ).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 // Disable link whilst we're busy to avoid double handling
15 if ( $link
.data( 'mwDisabled' ) ) {
16 // mw-watch-link-disabled disables pointer-events which prevents the click event
17 // from happening in the first place. In older browsers we kill the event here.
20 $link
.data( 'mwDisabled', true ).addClass( 'mw-watch-link-disabled' );
22 // Preload the notification module for mw.notify
23 mw
.loader
.load( 'mediawiki.notification' );
25 // Use the class to determine whether to watch or unwatch
26 if ( !$subjectLink
.hasClass( 'mw-watched-item' ) ) {
27 $link
.text( mw
.msg( 'watching' ) );
28 promise
= api
.watch( title
).done( function () {
29 $subjectLink
.addClass( 'mw-watched-item' );
30 $link
.text( mw
.msg( 'unwatch' ) );
31 mw
.notify( mw
.msg( 'addedwatchtext-short', title
) );
32 } ).fail( function () {
33 $link
.text( mw
.msg( 'watch' ) );
34 mw
.notify( mw
.msg( 'watcherrortext', title
), { type
: 'error' } );
37 $link
.text( mw
.msg( 'unwatching' ) );
38 promise
= api
.unwatch( title
).done( function () {
39 $subjectLink
.removeClass( 'mw-watched-item' );
40 $link
.text( mw
.msg( 'watch' ) );
41 mw
.notify( mw
.msg( 'removedwatchtext-short', title
) );
42 } ).fail( function () {
43 $link
.text( mw
.msg( 'unwatch' ) );
44 mw
.notify( mw
.msg( 'watcherrortext', title
), { type
: 'error' } );
48 promise
.always( function () {
49 $link
.data( 'mwDisabled', false ).removeClass( 'mw-watch-link-disabled' );
55 }( mediaWiki
, jQuery
) );