d-before-unload
Advanced tools
Comparing version 0.1.0 to 0.1.1
14
index.js
@@ -6,3 +6,11 @@ module.exports = BeforeUnload; | ||
BeforeUnload.prototype.create = function(model, dom) { | ||
dom.on('beforeunload', window, function(e) { | ||
// Don't do anything until the user makes some kind of mutation | ||
model.root.once('all', '**', function() { | ||
// Thereafter, stop the user from leaving the page whenever a change might be pending | ||
dom.on('beforeunload', window, listenerFn(model)); | ||
}); | ||
}; | ||
function listenerFn(model) { | ||
return function beforeunloadListener(e) { | ||
if (!model.hasPending()) return; | ||
@@ -13,3 +21,3 @@ var confirmationMessage = model.get('message') || | ||
return confirmationMessage; | ||
}); | ||
}; | ||
}; | ||
} |
{ | ||
"name": "d-before-unload", | ||
"description": "Derby component to stop page from unloading when it has pending operations", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
1370
19