From c9ce606b7ceec76476479f7d856a25e0111c9ec1 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 13 Aug 2014 19:29:00 +0100 Subject: [PATCH] Move the unsaved changes warning into the syncer --- core/modules/startup/startup.js | 9 --------- core/modules/syncer.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/modules/startup/startup.js b/core/modules/startup/startup.js index c4f93192d..a6d16c8ad 100755 --- a/core/modules/startup/startup.js +++ b/core/modules/startup/startup.js @@ -54,15 +54,6 @@ exports.startup = function() { $tw.syncer = new $tw.Syncer({wiki: $tw.wiki}); // Host-specific startup if($tw.browser) { - // Set up our beforeunload handler - window.addEventListener("beforeunload",function(event) { - var confirmationMessage = undefined; - if($tw.syncer.isDirty()) { - confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); - event.returnValue = confirmationMessage; // Gecko - } - return confirmationMessage; - }); // Install the popup manager $tw.popup = new $tw.utils.Popup({ rootElement: document.body diff --git a/core/modules/syncer.js b/core/modules/syncer.js index 6600573fb..3d6081008 100644 --- a/core/modules/syncer.js +++ b/core/modules/syncer.js @@ -45,6 +45,17 @@ function Syncer(options) { this.wiki.addEventListener("change",function(changes) { self.syncToServer(changes); }); + // Set up our beforeunload handler + if($tw.browser) { + window.addEventListener("beforeunload",function(event) { + var confirmationMessage = undefined; + if(self.isDirty()) { + confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); + event.returnValue = confirmationMessage; // Gecko + } + return confirmationMessage; + }); + } // Listen out for lazyLoad events if(this.syncadaptor) { this.wiki.addEventListener("lazyLoad",function(title) {