Merge "Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.unwatchedPages.js
1 /*!
2 * JavaScript for Special:UnwatchedPages
3 */
4 ( function ( mw, $ ) {
5 $( function () {
6 $( 'a.mw-watch-link' ).click( function ( e ) {
7 var promise,
8 api = new mw.Api(),
9 $link = $( this ),
10 $subjectLink = $link.closest( 'li' ).children( 'a' ).eq( 0 ),
11 title = mw.util.getParamValue( 'title', $link.attr( 'href' ) );
12 // nice format
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.
18 return false;
19 }
20 $link.data( 'mwDisabled', true ).addClass( 'mw-watch-link-disabled' );
21
22 // Preload the notification module for mw.notify
23 mw.loader.load( 'mediawiki.notification' );
24
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' } );
35 } );
36 } else {
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' } );
45 } );
46 }
47
48 promise.always( function () {
49 $link.data( 'mwDisabled', false ).removeClass( 'mw-watch-link-disabled' );
50 } );
51
52 e.preventDefault();
53 } );
54 } );
55 }( mediaWiki, jQuery ) );