From 1db0ced8cc91cfab1c2727bdf662821625f83595 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 17 May 2013 17:44:21 +0100 Subject: [PATCH] Fix various issues with prematurely aborting VE load Add checks to make sure parts of the target are acutally active before trying to tear them down or use them. This fixes a couple of issues which appeared when the VE was closed before it had a chance to finish loading. Bug: 48520 Bug: 47813 Change-Id: Ide5def0e983bab49108b40008fc170957c7fc2a2 --- .../mw/targets/ve.init.mw.ViewPageTarget.js | 19 ++++++++++++++++--- modules/ve/init/mw/ve.init.mw.Target.js | 3 +-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js index 64b4e1e416..02f28b5950 100644 --- a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js @@ -284,7 +284,16 @@ ve.init.mw.ViewPageTarget.prototype.deactivate = function ( override ) { this.resetSaveDialog(); this.hideSaveDialog(); this.detachSaveDialog(); - this.tearDownSurface(); + // Check we got as far as setting up the surface + if ( this.active ) { + this.tearDownSurface(); + } else { + this.showPageContent(); + } + // If there is a load in progress, abort it + if ( this.loading ) { + this.loading.abort(); + } this.showTableOfContents(); this.deactivating = false; } @@ -324,7 +333,8 @@ ve.init.mw.ViewPageTarget.prototype.onLoad = function ( doc ) { * @param {Mixed} error Thrown exception or HTTP error string */ ve.init.mw.ViewPageTarget.prototype.onLoadError = function ( response, status ) { - if ( confirm( ve.msg( 'visualeditor-loadwarning', status ) ) ) { + // Don't show an error if the load was manually aborted + if ( status !== 'abort' && confirm( ve.msg( 'visualeditor-loadwarning', status ) ) ) { this.load(); } else { this.activating = false; @@ -1478,7 +1488,10 @@ ve.init.mw.ViewPageTarget.prototype.setUpToolbar = function () { .addClass( 've-init-mw-viewPageTarget-toolbar' ) .insertBefore( '#firstHeading' ); this.toolbar.$bar.slideDown( 'fast', ve.bind( function () { - this.surface.getContext().update(); + // Check the surface wasn't torn down while the toolbar was animating + if ( this.surface ) { + this.surface.getContext().update(); + } }, this ) ); }; diff --git a/modules/ve/init/mw/ve.init.mw.Target.js b/modules/ve/init/mw/ve.init.mw.Target.js index 8fc90e1970..b98231895b 100644 --- a/modules/ve/init/mw/ve.init.mw.Target.js +++ b/modules/ve/init/mw/ve.init.mw.Target.js @@ -414,8 +414,7 @@ ve.init.mw.Target.prototype.load = function () { // Start loading the module immediately mw.loader.load( this.modules ); // Load DOM - this.loading = true; - $.ajax( { + this.loading = $.ajax( { 'url': this.apiUrl, 'data': { 'action': 'visualeditor',