Merge "Use new wikipage.watchlistChange hook"

This commit is contained in:
jenkins-bot 2022-01-10 22:21:17 +00:00 committed by Gerrit Code Review
commit a627011ddf
2 changed files with 9 additions and 13 deletions

View file

@ -991,11 +991,8 @@ function update( data, comment, pageName, replyWidget ) {
if ( mw.loader.getState( 'mediawiki.page.watch.ajax' ) === 'ready' ) {
var watch = require( 'mediawiki.page.watch.ajax' );
watch.updateWatchLink(
// eslint-disable-next-line no-jquery/no-global-selector
$( '#ca-watch a, #ca-unwatch a' ),
data.watched ? 'unwatch' : 'watch',
'idle',
watch.updatePageWatchStatus(
data.watched,
data.watchlistexpiry
);
}

View file

@ -542,8 +542,7 @@ ReplyWidget.prototype.setup = function ( data ) {
}
}
// eslint-disable-next-line no-jquery/no-global-selector
$( '#ca-watch, #ca-unwatch' ).on( 'watchpage.mw', this.onWatchToggleHandler );
mw.hook( 'wikipage.watchlistChange' ).add( this.onWatchToggleHandler );
return this;
};
@ -627,8 +626,7 @@ ReplyWidget.prototype.teardown = function ( abandoned ) {
this.modeTabSelect.blur();
}
this.unbindBeforeUnloadHandler();
// eslint-disable-next-line no-jquery/no-global-selector
$( '#ca-watch, #ca-unwatch' ).off( 'watchpage.mw', this.onWatchToggleHandler );
mw.hook( 'wikipage.watchlistChange' ).remove( this.onWatchToggleHandler );
this.clear();
this.emit( 'teardown', abandoned );
@ -638,17 +636,18 @@ ReplyWidget.prototype.teardown = function ( abandoned ) {
/**
* Handle changes to the watch state of the page
*
* @param {jQuery.Event} e Event
* @param {string} actionPerformed Watch action taken
* @param {boolean} isWatched
* @param {string} expiry
* @param {string} expirySelected
*/
ReplyWidget.prototype.onWatchToggle = function ( e, actionPerformed ) {
ReplyWidget.prototype.onWatchToggle = function ( isWatched ) {
var widget = this;
this.checkboxesPromise.then( function ( checkboxes ) {
if ( checkboxes.checkboxesByName.wpWatchthis ) {
checkboxes.checkboxesByName.wpWatchthis.setSelected(
!!mw.user.options.get( 'watchdefault' ) ||
( !!mw.user.options.get( 'watchcreations' ) && !widget.pageExists ) ||
actionPerformed === 'watch'
isWatched
);
}
} );