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 // Use the class to determine whether to watch or unwatch
23 if ( !$subjectLink.hasClass( 'mw-watched-item' ) ) {
24 $link.text( mw.msg( 'watching' ) );
25 promise = api.watch( title ).done( function () {
26 $subjectLink.addClass( 'mw-watched-item' );
27 $link.text( mw.msg( 'unwatch' ) );
28 mw.notify( mw.msg( 'addedwatchtext-short', title ) );
29 } ).fail( function () {
30 $link.text( mw.msg( 'watch' ) );
31 mw.notify( mw.msg( 'watcherrortext', title ) );
34 $link.text( mw.msg( 'unwatching' ) );
35 promise = api.unwatch( title ).done( function () {
36 $subjectLink.removeClass( 'mw-watched-item' );
37 $link.text( mw.msg( 'watch' ) );
38 mw.notify( mw.msg( 'removedwatchtext-short', title ) );
39 } ).fail( function () {
40 $link.text( mw.msg( 'unwatch' ) );
41 mw.notify( mw.msg( 'watcherrortext', title ) );
45 promise.always( function () {
46 $link.data( 'mwDisabled', false ).removeClass( 'mw-watch-link-disabled' );
52 }( mediaWiki, jQuery ) );