From cc47a4d05c563cef9910f0b4c14d08d35d264443 Mon Sep 17 00:00:00 2001 From: Rob Moen Date: Wed, 20 Jun 2012 12:22:00 -0700 Subject: [PATCH] Add Hook for 'watch' event triggered on MW watch link or icon to update save dialog checkbox with correct watched state. Call mw.page.watch.updateWatchLink onSave to refresh icon with watched state. Patchset 2- updated event name Change-Id: I23ef1aad9c8ace13df1b9a6bf0bfeddb9d8bcb37 --- .../ve/init/targets/ve.init.ViewPageTarget.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ve/init/targets/ve.init.ViewPageTarget.js b/modules/ve/init/targets/ve.init.ViewPageTarget.js index 60612af480..a4aa9323a1 100644 --- a/modules/ve/init/targets/ve.init.ViewPageTarget.js +++ b/modules/ve/init/targets/ve.init.ViewPageTarget.js @@ -191,6 +191,14 @@ ve.init.ViewPageTarget.prototype.onSave = function( html ) { // This is a page creation, refresh the page window.location.href = this.viewUri; } else { + // Update the watch link to match the state of 'watch checkbox' in save dialog + var watchPage = this.$saveDialog + .find( '#ve-init-viewPageTarget-saveDialog-watchList') + .prop( 'checked' ); + mw.page.watch.updateWatchLink( + $('#ca-watch a, #ca-unwatch a'), + watchPage === true ? 'unwatch': 'watch' + ); this.hideSaveDialog(); this.resetSaveDialog(); this.replacePageContent( html ); @@ -535,6 +543,17 @@ ve.init.ViewPageTarget.prototype.setupSaveDialog = function() { ); this.$saveDialogSaveButton = this.$saveDialog .find( '.ve-init-viewPageTarget-saveDialog-saveButton' ); + + /* Hook onto the 'watch' event on by mediawiki.page.watch.ajax.js + * Triggered when mw.page.watch.updateWatchLink(link, action) is called. + */ + $( '#ca-watch, #ca-unwatch' ).on( 'watch.mw', + ve.proxy( function( e, action ){ + this.$saveDialog + .find( '#ve-init-viewPageTarget-saveDialog-watchList') + .prop( 'checked', ( action === 'watch') ); + }, this ) + ); }; /**