From 7cdaa2a290115394bea3d069163e5585e05d7653 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 12 Mar 2014 12:05:02 -0700 Subject: [PATCH] Fix JS error trying to access this.saveDialog from switch to source mode code path The switch to source mode code path was causing onSerializeComplete to be called, which accesses this.saveDialog because it assumes it's being called from onSaveDialogReview. In fact, onSaveDialogReview was calling it twice, once as the callback it passes to serialize() and once in response to the serializeComplete event. Cleaned this up by renaming the function and removing the event binding, so it's now only called once and only for reviewing changes to new pages, not in the switch to source mode code path. Bug: 62544 Change-Id: I86eea57806a20408c8dc89a234c39cae1d969bca --- .../init/targets/ve.init.mw.ViewPageTarget.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 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 95a43bc697..8de4d4155f 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -106,7 +106,6 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() { 'showChanges': 'onShowChanges', 'showChangesError': 'onShowChangesError', 'noChanges': 'onNoChanges', - 'serializeComplete': 'onSerializeComplete', 'serializeError': 'onSerializeError', 'sanityCheckComplete': 'updateToolbarSaveButtonState' } ); @@ -571,20 +570,6 @@ ve.init.mw.ViewPageTarget.prototype.onShowChanges = function ( diffHtml ) { this.saveDialog.setDiffAndReview( diffHtml ); }; -/** - * Handle Serialize event. - * - * @method - * @param {string} wikitext - */ -ve.init.mw.ViewPageTarget.prototype.onSerializeComplete = function ( wikitext ) { - // Invalidate the viewer wikitext on next change - this.surface.getModel().getDocument().once( 'transact', - ve.bind( this.saveDialog.clearDiff, this.saveDialog ) - ); - this.saveDialog.setDiffAndReview( $( '
' ).text( wikitext ) );
-};
-
 /**
  * Handle failed show changes event.
  *
@@ -758,13 +743,27 @@ ve.init.mw.ViewPageTarget.prototype.onSaveDialogReview = function () {
 			// Has no callback, handled via target.onShowChanges
 			this.showChanges( this.docToSave );
 		} else {
-			this.serialize( this.docToSave, ve.bind( this.onSerialize, this ) );
+			this.serialize( this.docToSave, ve.bind( this.onSaveDialogReviewComplete, this ) );
 		}
 	} else {
 		this.saveDialog.swapPanel( 'review' );
 	}
 };
 
+/**
+ * Handle completed serialize request for diff views for new page creations.
+ *
+ * @method
+ * @param {string} wikitext
+ */
+ve.init.mw.ViewPageTarget.prototype.onSaveDialogReviewComplete = function ( wikitext ) {
+	// Invalidate the viewer wikitext on next change
+	this.surface.getModel().getDocument().once( 'transact',
+		ve.bind( this.saveDialog.clearDiff, this.saveDialog )
+	);
+	this.saveDialog.setDiffAndReview( $( '
' ).text( wikitext ) );
+};
+
 /**
  * Try to save the current document.
  * @fires saveInitiated