diff --git a/src/block_manager/view/BlocksView.js b/src/block_manager/view/BlocksView.js
index a0b7ccaa5..199d9f0a8 100644
--- a/src/block_manager/view/BlocksView.js
+++ b/src/block_manager/view/BlocksView.js
@@ -61,9 +61,14 @@ function(Backbone, BlockView) {
onDrop: function(model){
this.em.runDefault();
- if (model && model.get && model.get('activeOnRender')) {
- model.trigger('active');
- model.set('activeOnRender', 0);
+ if (model && model.get) {
+ if(model.get('activeOnRender')) {
+ model.trigger('active');
+ model.set('activeOnRender', 0);
+ }
+
+ // Register all its components (eg. for the Undo Manager)
+ this.em.initChildrenComp(model);
}
},
diff --git a/src/demo.js b/src/demo.js
index 13f36fb6c..9cfc1352e 100644
--- a/src/demo.js
+++ b/src/demo.js
@@ -36,12 +36,13 @@ require(['config/require-config'], function() {
content: " More text node --- ",
}],
}],*/
-
+ /*
storageManager:{
autoload: 0,
storeComponents: 1,
storeStyles: 1,
},
+ */
commands: {
defaults : [{
id: 'open-github',
@@ -334,6 +335,37 @@ require(['config/require-config'], function() {
window.editor = editor;
+ var pnm = editor.Panels;
+ pnm.addButton('options', [{
+ id: 'undo',
+ className: 'fa fa-undo icon-undo',
+ command: function(editor, sender) {
+ sender.set('active', 0);
+ editor.UndoManager.undo(1);
+ },
+ attributes: { title: 'Undo (CTRL/CMD + Z)'}
+ },{
+ id: 'redo',
+ className: 'fa fa-repeat icon-redo',
+ command: function(editor, sender) {
+ sender.set('active', 0);
+ editor.UndoManager.redo(1);
+ },
+ attributes: { title: 'Redo (CTRL/CMD + SHIFT + Z)' }
+ },{
+ id: 'clean-all',
+ className: 'fa fa-trash icon-blank',
+ command: function(editor, sender) {
+ if(sender) sender.set('active',false);
+ if(confirm('Are you sure to clean the canvas?')){
+ var comps = editor.DomComponents.clear();
+ localStorage.setItem('gjs-css', '');
+ localStorage.setItem('gjs-html', '');
+ }
+ },
+ attributes: { title: 'Empty canvas' }
+ }]);
+
editor.render();
});
});
diff --git a/src/dom_components/main.js b/src/dom_components/main.js
index da7afdd98..fcc88cfc3 100644
--- a/src/dom_components/main.js
+++ b/src/dom_components/main.js
@@ -21,7 +21,7 @@
* @example
* ...
* domComponents: {
- * components: '
Hello world!
',
+ * components: 'Hello world!
',
* }
* // Or
* domComponents: {
@@ -34,86 +34,86 @@
*/
define(function(require) {
- return function (){
- var c = {},
- componentTypes = {},
- defaults = require('./config/config'),
- Component = require('./model/Component'),
- ComponentView = require('./view/ComponentView');
+ return function (){
+ var c = {},
+ componentTypes = {},
+ defaults = require('./config/config'),
+ Component = require('./model/Component'),
+ ComponentView = require('./view/ComponentView');
- var component, componentView;
- var defaultTypes = [
- {
- id: 'cell',
- model: require('./model/ComponentTableCell'),
- view: require('./view/ComponentTableCellView'),
- },
- {
- id: 'row',
- model: require('./model/ComponentTableRow'),
- view: require('./view/ComponentTableRowView'),
- },
- {
- id: 'table',
- model: require('./model/ComponentTable'),
- view: require('./view/ComponentTableView'),
- },
- {
- id: 'map',
- model: require('./model/ComponentMap'),
- view: require('./view/ComponentMapView'),
- },
- {
- id: 'link',
- model: require('./model/ComponentLink'),
- view: require('./view/ComponentLinkView'),
- },
- {
- id: 'video',
- model: require('./model/ComponentVideo'),
- view: require('./view/ComponentVideoView'),
- },
- {
- id: 'image',
- model: require('./model/ComponentImage'),
- view: require('./view/ComponentImageView'),
- },
- {
- id: 'textnode',
- model: require('./model/ComponentTextNode'),
- view: require('./view/ComponentTextNodeView'),
- },
- {
- id: 'text',
- model: require('./model/ComponentText'),
- view: require('./view/ComponentTextView'),
- },
- {
- id: 'default',
- model: Component,
- view: ComponentView,
- },
- ];
+ var component, componentView;
+ var defaultTypes = [
+ {
+ id: 'cell',
+ model: require('./model/ComponentTableCell'),
+ view: require('./view/ComponentTableCellView'),
+ },
+ {
+ id: 'row',
+ model: require('./model/ComponentTableRow'),
+ view: require('./view/ComponentTableRowView'),
+ },
+ {
+ id: 'table',
+ model: require('./model/ComponentTable'),
+ view: require('./view/ComponentTableView'),
+ },
+ {
+ id: 'map',
+ model: require('./model/ComponentMap'),
+ view: require('./view/ComponentMapView'),
+ },
+ {
+ id: 'link',
+ model: require('./model/ComponentLink'),
+ view: require('./view/ComponentLinkView'),
+ },
+ {
+ id: 'video',
+ model: require('./model/ComponentVideo'),
+ view: require('./view/ComponentVideoView'),
+ },
+ {
+ id: 'image',
+ model: require('./model/ComponentImage'),
+ view: require('./view/ComponentImageView'),
+ },
+ {
+ id: 'textnode',
+ model: require('./model/ComponentTextNode'),
+ view: require('./view/ComponentTextNodeView'),
+ },
+ {
+ id: 'text',
+ model: require('./model/ComponentText'),
+ view: require('./view/ComponentTextView'),
+ },
+ {
+ id: 'default',
+ model: Component,
+ view: ComponentView,
+ },
+ ];
- return {
+ return {
- componentTypes: defaultTypes,
+ componentTypes: defaultTypes,
- /**
+ /**
* Name of the module
* @type {String}
* @private
*/
name: 'DomComponents',
- /**
- * Returns config
- * @return {Object} Config object
- * @private
- */
- getConfig: function () {
- return c;
- },
+ /**
+ * Returns config
+ * @return {Object} Config object
+ * @private
+ */
+ getConfig: function () {
+ return c;
+ },
/**
* Mandatory for the storage manager
@@ -121,13 +121,13 @@ define(function(require) {
* @private
*/
storageKey: function(){
- var keys = [];
- var smc = (c.stm && c.stm.getConfig()) || {};
+ var keys = [];
+ var smc = (c.stm && c.stm.getConfig()) || {};
if(smc.storeHtml)
keys.push('html');
if(smc.storeComponents)
keys.push('components');
- return keys;
+ return keys;
},
/**
@@ -153,29 +153,29 @@ define(function(require) {
// Load dependencies
if(c.em){
c.rte = c.em.get('rte') || '';
- c.modal = c.em.get('Modal') || '';
- c.am = c.em.get('AssetManager') || '';
- c.em.get('Parser').compTypes = defaultTypes;
+ c.modal = c.em.get('Modal') || '';
+ c.am = c.em.get('AssetManager') || '';
+ c.em.get('Parser').compTypes = defaultTypes;
}
component = new Component(c.wrapper, {
- sm: c.em,
- config: c,
- defaultTypes: defaultTypes,
- componentTypes: componentTypes,
- });
- component.set({ attributes: {id: 'wrapper'}});
+ sm: c.em,
+ config: c,
+ defaultTypes: defaultTypes,
+ componentTypes: componentTypes,
+ });
+ component.set({ attributes: {id: 'wrapper'}});
- if(c.em && !c.em.config.loadCompsOnRender) {
- component.get('components').add(c.components);
- }
+ if(c.em && !c.em.config.loadCompsOnRender) {
+ component.get('components').add(c.components);
+ }
- componentView = new ComponentView({
- model: component,
- config: c,
- defaultTypes: defaultTypes,
- componentTypes: componentTypes,
- });
+ componentView = new ComponentView({
+ model: component,
+ config: c,
+ defaultTypes: defaultTypes,
+ componentTypes: componentTypes,
+ });
return this;
},
@@ -236,158 +236,158 @@ define(function(require) {
return obj;
},
- /**
- * Returns privately the main wrapper
- * @return {Object}
- * @private
- */
- getComponent : function(){
- return component;
- },
+ /**
+ * Returns privately the main wrapper
+ * @return {Object}
+ * @private
+ */
+ getComponent : function(){
+ return component;
+ },
- /**
- * Returns root component inside the canvas. Something like inside HTML page
- * The wrapper doesn't differ from the original Component Model
- * @return {Component} Root Component
- * @example
- * // Change background of the wrapper and set some attribute
- * var wrapper = domComponents.getWrapper();
- * wrapper.set('style', {'background-color': 'red'});
- * wrapper.set('attributes', {'title': 'Hello!'});
- */
- getWrapper: function(){
- return this.getComponent();
- },
+ /**
+ * Returns root component inside the canvas. Something like inside HTML page
+ * The wrapper doesn't differ from the original Component Model
+ * @return {Component} Root Component
+ * @example
+ * // Change background of the wrapper and set some attribute
+ * var wrapper = domComponents.getWrapper();
+ * wrapper.set('style', {'background-color': 'red'});
+ * wrapper.set('attributes', {'title': 'Hello!'});
+ */
+ getWrapper: function(){
+ return this.getComponent();
+ },
- /**
- * Returns wrapper's children collection. Once you have the collection you can
- * add other Components(Models) inside. Each component can have several nested
- * components inside and you can nest them as more as you wish.
- * @return {Components} Collection of components
- * @example
- * // Let's add some component
- * var wrapperChildren = domComponents.getComponents();
- * var comp1 = wrapperChildren.add({
- * style: { 'background-color': 'red'}
- * });
- * var comp2 = wrapperChildren.add({
- * tagName: 'span',
- * attributes: { title: 'Hello!'}
- * });
- * // Now let's add an other one inside first component
- * // First we have to get the collection inside. Each
- * // component has 'components' property
- * var comp1Children = comp1.get('components');
- * // Procede as before. You could also add multiple objects
- * comp1Children.add([
- * { style: { 'background-color': 'blue'}},
- * { style: { height: '100px', width: '100px'}}
- * ]);
- * // Remove comp2
- * wrapperChildren.remove(comp2);
- */
- getComponents: function(){
- return this.getWrapper().get('components');
- },
+ /**
+ * Returns wrapper's children collection. Once you have the collection you can
+ * add other Components(Models) inside. Each component can have several nested
+ * components inside and you can nest them as more as you wish.
+ * @return {Components} Collection of components
+ * @example
+ * // Let's add some component
+ * var wrapperChildren = domComponents.getComponents();
+ * var comp1 = wrapperChildren.add({
+ * style: { 'background-color': 'red'}
+ * });
+ * var comp2 = wrapperChildren.add({
+ * tagName: 'span',
+ * attributes: { title: 'Hello!'}
+ * });
+ * // Now let's add an other one inside first component
+ * // First we have to get the collection inside. Each
+ * // component has 'components' property
+ * var comp1Children = comp1.get('components');
+ * // Procede as before. You could also add multiple objects
+ * comp1Children.add([
+ * { style: { 'background-color': 'blue'}},
+ * { style: { height: '100px', width: '100px'}}
+ * ]);
+ * // Remove comp2
+ * wrapperChildren.remove(comp2);
+ */
+ getComponents: function(){
+ return this.getWrapper().get('components');
+ },
- /**
- * Add new components to the wrapper's children. It's the same
- * as 'domComponents.getComponents().add(...)'
- * @param {Object|Component|Array