Blockly Factory: Warn user when leaving/refreshing page (#607)

* warn user upon refreshing page and leaving page (by going to prev page or by exiting the window or tab)

* alert upon leaving page ONLY when unsaved changes

* nit remove log

* no alert when on starter block, added clarifying comment
This commit is contained in:
Tina Quach
2016-08-31 13:39:47 -07:00
committed by picklesrus
parent 8d89e62bc8
commit cbdf8a597e
2 changed files with 16 additions and 1 deletions

View File

@@ -619,6 +619,21 @@ AppController.prototype.onresize = function(event) {
}
};
/**
* Handler for the window's 'onbeforeunload' event. When a user has unsaved
* changes and refreshes or leaves the page, confirm that they want to do so
* before actually refreshing.
*/
AppController.prototype.confirmLeavePage = function() {
if (!BlockFactory.isStarterBlock() &&
!FactoryUtils.savedBlockChanges(this.blockLibraryController)) {
// When a string is assigned to the returnValue Event property, a dialog box
// appears, asking the users for confirmation to leave the page.
return 'You will lose any unsaved changes. Are you sure you want ' +
'to exit this page?';
}
};
/**
* Initialize Blockly and layout. Called on page load.
*/

View File

@@ -41,7 +41,7 @@
window.addEventListener('load', init);
</script>
</head>
<body>
<body onbeforeunload="return blocklyFactory.confirmLeavePage()">
<h1><a href="https://developers.google.com/blockly/">Blockly</a> &gt;
<a href="../index.html">Demos</a> &gt; Blockly Factory
<button id="helpButton" title="View documentation in new window.">