1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-29 06:37:39 +00:00

Refactor browser unload task handling

Make it possible to register multiple task functions that will be
called when the window is unloaded
This commit is contained in:
Jermolene
2015-05-03 16:23:35 +01:00
parent d23f174d01
commit 48dcf959ff
3 changed files with 29 additions and 5 deletions

View File

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