From dd52503b6adc2eec0bad34b99250adcf77e8025e Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Thu, 5 Feb 2015 00:05:56 +0000 Subject: [PATCH] Unbind watch event handler in VPT when necessary Caught by Timo in I1df2836f Change-Id: I0f0af71cdca26f7e8d13f9ea50d22c833b6e1683 --- .../init/targets/ve.init.mw.ViewPageTarget.js | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index d287de1fa0..e4dae21992 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -29,6 +29,8 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() { // we activate; so unbind them again this.unbindHandlers(); + this.onWatchToggleHandler = this.onWatchToggle.bind( this ); + // Properties this.toolbarSaveButton = null; this.saveDialog = null; @@ -227,6 +229,43 @@ ve.init.mw.ViewPageTarget.prototype.setupLocalNoticeMessages = function () { } }; +/** + * Handle the watch button being toggled on/off. + * @param {jQuery.Event} e Event object whih triggered the event + * @param {string} actionPerformed 'watch' or 'unwatch' + */ +ve.init.mw.ViewPageTarget.prototype.onWatchToggle = function ( e, actionPerformed ) { + if ( !this.active && !this.activating ) { + return; + } + this.$checkboxes.filter( '#wpWatchthis' ) + .prop( 'checked', + mw.user.options.get( 'watchdefault' ) || + ( mw.user.options.get( 'watchcreations' ) && !this.pageExists ) || + actionPerformed === 'watch' + ); +}; + +/** + * @inheritdoc + */ +ve.init.mw.ViewPageTarget.prototype.bindHandlers = function () { + ve.init.mw.ViewPageTarget.super.prototype.bindHandlers.call( this ); + if ( this.onWatchToggleHandler ) { + $( '#ca-watch, #ca-unwatch' ).on( 'watchpage.mw', this.onWatchToggleHandler ); + } +}; + +/** + * @inheritdoc + */ +ve.init.mw.ViewPageTarget.prototype.unbindHandlers = function () { + ve.init.mw.ViewPageTarget.super.prototype.unbindHandlers.call( this ); + if ( this.onWatchToggleHandler ) { + $( '#ca-watch, #ca-unwatch' ).off( 'watchpage.mw', this.onWatchToggleHandler ); + } +}; + /** * Switch to edit mode. * @@ -242,18 +281,6 @@ ve.init.mw.ViewPageTarget.prototype.activate = function () { this.originalEditondbclick = mw.user.options.get( 'editondblclick' ); mw.user.options.set( 'editondblclick', 0 ); - $( '#ca-watch, #ca-unwatch' ).on( 'watchpage.mw', function ( e, actionPerformed ) { - if ( !this.active && !this.activating ) { - return; - } - this.$checkboxes.filter( '#wpWatchthis' ) - .prop( 'checked', - mw.user.options.get( 'watchdefault' ) || - ( mw.user.options.get( 'watchcreations' ) && !this.pageExists ) || - actionPerformed === 'watch' - ); - }.bind( this ) ); - // User interface changes this.transformPage(); this.hideReadOnlyContent();