Switching modes created an infinite loop onBeforeUnload

Switching from visual to source reruns setupUnloadHandlers, which caused an
infinite loop where it thought it was its own fallback pre-existing handler.

Bug: T153346
Change-Id: I8df55a5395ede02fc34ec47a94f2c780dc08595f
This commit is contained in:
David Lynch 2017-03-08 11:32:03 -06:00
parent b27fe68833
commit d6c71632ef

View file

@ -33,6 +33,7 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
// Properties
this.onBeforeUnloadFallback = null;
this.onBeforeUnload = this.onBeforeUnload.bind( this );
this.onUnloadHandler = this.onUnload.bind( this );
this.activating = false;
this.deactivating = false;
@ -1566,11 +1567,13 @@ ve.init.mw.DesktopArticleTarget.prototype.saveEditSection = function ( heading )
* @method
*/
ve.init.mw.DesktopArticleTarget.prototype.setupUnloadHandlers = function () {
// Remember any already set beforeunload handler
this.onBeforeUnloadFallback = window.onbeforeunload;
// Attach our handlers
window.onbeforeunload = this.onBeforeUnload.bind( this );
window.addEventListener( 'unload', this.onUnloadHandler );
if ( window.onbeforeunload !== this.onBeforeUnload ) {
// Remember any already set beforeunload handler
this.onBeforeUnloadFallback = window.onbeforeunload;
// Attach our handlers
window.onbeforeunload = this.onBeforeUnload;
window.addEventListener( 'unload', this.onUnloadHandler );
}
};
/**
* Remove onunload and onbeforunload handlers.