Browse Source

Show unload alert with only unsaved changes. Close #24

pull/67/head
Artur Arseniev 10 years ago
parent
commit
0725c0d8df
  1. 2
      bower.json
  2. 6
      dist/grapes.min.js
  3. 2
      package.json
  4. 115
      src/editor/config/config.js
  5. 15
      src/editor/model/Editor.js
  6. 5
      src/grapesjs/config/config.js
  7. 5
      src/grapesjs/main.js

2
bower.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Open source Web Template Editor", "description": "Open source Web Template Editor",
"version": "0.4.22", "version": "0.4.23",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",
"main": [ "main": [

6
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Open source Web Template Editor", "description": "Open source Web Template Editor",
"version": "0.4.22", "version": "0.4.23",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

115
src/editor/config/config.js

@ -2,88 +2,91 @@ define(function () {
var blkStyle = '.blk-row::after{ content: ""; clear: both; display: block;} .blk-row{padding: 10px;}'; var blkStyle = '.blk-row::after{ content: ""; clear: both; display: block;} .blk-row{padding: 10px;}';
return { return {
// Style prefix // Style prefix
stylePrefix: 'gjs-', stylePrefix: 'gjs-',
//TEMP //TEMP
components: '', components: '',
// Enable/Disable possibility to copy(ctrl + c) & paste(ctrl + v) components // Enable/Disable possibility to copy(ctrl + c) & paste(ctrl + v) components
copyPaste: true, copyPaste: true,
// Enable/Disable undo manager // Show an alert before unload the page with unsaved changes
undoManager: true, noticeOnUnload: true,
// Height for the editor container // Enable/Disable undo manager
height: '900px', undoManager: true,
// Width for the editor container // Height for the editor container
width: '100%', height: '900px',
// CSS that could only be seen (for instance, inside the code viewer) // Width for the editor container
protectedCss: '*{box-sizing: border-box;}body{margin:0;height:auto;background:#fff}#wrapper{min-height:100%; overflow:auto}', width: '100%',
// CSS for the iframe which containing the canvas, useful if you need to custom something inside // CSS that could only be seen (for instance, inside the code viewer)
// (eg. the style of the selected component) protectedCss: '*{box-sizing: border-box;}body{margin:0;height:auto;background:#fff}#wrapper{min-height:100%; overflow:auto}',
canvasCss: '',
// Default command // CSS for the iframe which containing the canvas, useful if you need to custom something inside
defaultCommand: 'select-comp', // (eg. the style of the selected component)
canvasCss: '',
// Show a toolbar when the component is selected // Default command
showToolbar: 1, defaultCommand: 'select-comp',
// Allow script tag importing // Show a toolbar when the component is selected
allowScripts: 0, showToolbar: 1,
// If true render a select of available devices // Allow script tag importing
showDevices: 1, allowScripts: 0,
// When enabled, on device change media rules won't be created // If true render a select of available devices
devicePreviewMode: 0, showDevices: 1,
// This option makes available custom component types also for loaded // When enabled, on device change media rules won't be created
// elements inside canvas devicePreviewMode: 0,
loadCompsOnRender: 1,
// Dom element // This option makes available custom component types also for loaded
el: '', // elements inside canvas
loadCompsOnRender: 1,
//Configurations for Asset Manager // Dom element
assetManager: {}, el: '',
//Configurations for Canvas //Configurations for Asset Manager
canvas: {}, assetManager: {},
//Configurations for Layers //Configurations for Canvas
layers: {}, canvas: {},
//Configurations for Storage Manager //Configurations for Layers
storageManager: {}, layers: {},
//Configurations for Rich Text Editor //Configurations for Storage Manager
rte: {}, storageManager: {},
//Configurations for DomComponents //Configurations for Rich Text Editor
domComponents: {}, rte: {},
//Configurations for Modal Dialog //Configurations for DomComponents
modal: {}, domComponents: {},
//Configurations for Code Manager //Configurations for Modal Dialog
codeManager: {}, modal: {},
//Configurations for Panels //Configurations for Code Manager
panels: {}, codeManager: {},
//Configurations for Commands //Configurations for Panels
commands: {}, panels: {},
//Configurations for Css Composer //Configurations for Commands
cssComposer: {}, commands: {},
//Configurations for Selector Manager //Configurations for Css Composer
selectorManager: {}, cssComposer: {},
//Configurations for Selector Manager
selectorManager: {},
//Configurations for Device Manager //Configurations for Device Manager
deviceManager: { deviceManager: {

15
src/editor/model/Editor.js

@ -39,8 +39,23 @@ define(['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'Dev
this.initUndoManager(); // Is already called (inside components and css composer) this.initUndoManager(); // Is already called (inside components and css composer)
this.on('change:selectedComponent', this.componentSelected, this); this.on('change:selectedComponent', this.componentSelected, this);
this.on('change:changesCount', this.updateBeforeUnload, this);
}, },
/**
* Set the alert before unload in case it's requested
* and there are unsaved changes
*/
updateBeforeUnload: function() {
var changes = this.get('changesCount');
if (this.config.noticeOnUnload && changes) {
window.onbeforeunload = function(e) { return 1;};
} else {
window.onbeforeunload = null;
}
},
/** /**
* Load generic module * Load generic module
* @param {String} moduleName Module name * @param {String} moduleName Module name

5
src/grapesjs/config/config.js

@ -22,9 +22,6 @@ define(function () {
// Enable/Disable undo manager // Enable/Disable undo manager
undoManager: true, undoManager: true,
// Show an alert before unload the page
noticeOnUnload: true,
// Storage Manager // Storage Manager
storageManager: {}, storageManager: {},
@ -34,4 +31,4 @@ define(function () {
// Custom options for plugins // Custom options for plugins
pluginsOpts: {} pluginsOpts: {}
}; };
}); });

5
src/grapesjs/main.js

@ -47,11 +47,6 @@ define(function (require) {
if(!els) if(!els)
throw new Error("'container' is required"); throw new Error("'container' is required");
if(c.noticeOnUnload)
window.onbeforeunload = function(e) {
return 1;
};
c.el = document.querySelector(els); c.el = document.querySelector(els);
var editor = new Editor(c).init(); var editor = new Editor(c).init();

Loading…
Cancel
Save