| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
( function () { |
| 5 |
$( () => { |
| 6 |
$( 'a.mw-watch-link' ).on( 'click', function ( e ) { |
| 7 |
const api = new mw.Api(), |
| 8 |
$link = $( this ), |
| 9 |
$subjectLink = $link.closest( 'li' ).children( 'a' ).eq( 0 ), |
| 10 |
titleParam = mw.util.getParamValue( 'title', $link.attr( 'href' ) ), |
| 11 |
|
| 12 |
title = mw.Title.newFromText( titleParam ).toText(); |
| 13 |
$link.addClass( 'mw-watch-link-disabled' ); |
| 14 |
|
| 15 |
|
| 16 |
mw.loader.load( 'mediawiki.notification' ); |
| 17 |
|
| 18 |
let promise; |
| 19 |
|
| 20 |
|
| 21 |
if ( !$subjectLink.hasClass( 'mw-watched-item' ) ) { |
| 22 |
$link.text( mw.msg( 'watching' ) ); |
| 23 |
promise = api.watch( title ).done( () => { |
| 24 |
$subjectLink.addClass( 'mw-watched-item' ); |
| 25 |
$link.text( mw.msg( 'unwatch' ) ); |
| 26 |
mw.notify( mw.msg( 'addedwatchtext-short', title ) ); |
| 27 |
} ).fail( ( code, data ) => { |
| 28 |
$link.text( mw.msg( 'watch' ) ); |
| 29 |
mw.notify( api.getErrorMessage( data ), { type: 'error' } ); |
| 30 |
} ); |
| 31 |
} else { |
| 32 |
$link.text( mw.msg( 'unwatching' ) ); |
| 33 |
promise = api.unwatch( title ).done( () => { |
| 34 |
$subjectLink.removeClass( 'mw-watched-item' ); |
| 35 |
$link.text( mw.msg( 'watch' ) ); |
| 36 |
mw.notify( mw.msg( 'removedwatchtext-short', title ) ); |
| 37 |
} ).fail( ( code, data ) => { |
| 38 |
$link.text( mw.msg( 'unwatch' ) ); |
| 39 |
mw.notify( api.getErrorMessage( data ), { type: 'error' } ); |
| 40 |
} ); |
| 41 |
} |
| 42 |
|
| 43 |
promise.always( () => { |
| 44 |
$link.removeClass( 'mw-watch-link-disabled' ); |
| 45 |
} ); |
| 46 |
|
| 47 |
e.preventDefault(); |
| 48 |
} ); |
| 49 |
} ); |
| 50 |
}() ); |