1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Switch from addEventListener to onbeforeunload

This makes it possible for TiddlyDesktop to reuse these functions to
handle detecting unsaved changes
This commit is contained in:
Jermolene 2015-01-10 18:08:12 +00:00
parent be06cb1019
commit 3657bbe920
2 changed files with 4 additions and 4 deletions

View File

@ -75,14 +75,14 @@ function SaverHandler(options) {
} }
}); });
// Set up our beforeunload handler // Set up our beforeunload handler
window.addEventListener("beforeunload",function(event) { window.onbeforeunload = function(event) {
var confirmationMessage; var confirmationMessage;
if(self.isDirty()) { if(self.isDirty()) {
confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); confirmationMessage = $tw.language.getString("UnsavedChangesWarning");
event.returnValue = confirmationMessage; // Gecko event.returnValue = confirmationMessage; // Gecko
} }
return confirmationMessage; return confirmationMessage;
}); };
} }
// Install the save action handlers // Install the save action handlers
if($tw.browser) { if($tw.browser) {

View File

@ -39,14 +39,14 @@ function Syncer(options) {
// Browser event handlers // Browser event handlers
if($tw.browser) { if($tw.browser) {
// Set up our beforeunload handler // Set up our beforeunload handler
window.addEventListener("beforeunload",function(event) { window.onbeforeunload = function(event) {
var confirmationMessage; var confirmationMessage;
if(self.isDirty()) { if(self.isDirty()) {
confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); confirmationMessage = $tw.language.getString("UnsavedChangesWarning");
event.returnValue = confirmationMessage; // Gecko event.returnValue = confirmationMessage; // Gecko
} }
return confirmationMessage; return confirmationMessage;
}); };
// Listen out for login/logout/refresh events in the browser // Listen out for login/logout/refresh events in the browser
$tw.rootWidget.addEventListener("tm-login",function() { $tw.rootWidget.addEventListener("tm-login",function() {
self.handleLoginEvent(); self.handleLoginEvent();