mirror of
https://github.com/google/blockly.git
synced 2026-01-31 04:30:11 +01:00
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:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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> >
|
||||
<a href="../index.html">Demos</a> > Blockly Factory
|
||||
<button id="helpButton" title="View documentation in new window.">
|
||||
|
||||
Reference in New Issue
Block a user