Browse Source

Update load method

pull/36/head
Artur Arseniev 10 years ago
parent
commit
eee82b5722
  1. 19
      dist/grapes.min.js
  2. 7
      src/asset_manager/main.js
  3. 7
      src/block_manager/main.js
  4. 7
      src/canvas/main.js
  5. 7
      src/code_manager/main.js
  6. 7
      src/commands/main.js
  7. 23
      src/css_composer/main.js
  8. 2
      src/demo.js
  9. 7
      src/device_manager/main.js
  10. 33
      src/dom_components/main.js
  11. 198
      src/editor/model/Editor.js
  12. 7
      src/modal_dialog/main.js
  13. 7
      src/panels/main.js
  14. 7
      src/parser/main.js
  15. 7
      src/rich_text_editor/main.js
  16. 7
      src/selector_manager/main.js
  17. 7
      src/storage_manager/main.js
  18. 7
      src/style_manager/main.js
  19. 7
      src/utils/main.js

19
dist/grapes.min.js

File diff suppressed because one or more lines are too long

7
src/asset_manager/main.js

@ -33,13 +33,6 @@ define(function(require) {
*/
name: 'AssetManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Mandatory for the storage manager
* @type {String}

7
src/block_manager/main.js

@ -33,13 +33,6 @@ define(function(require) {
*/
name: 'BlockManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/canvas/main.js

@ -26,13 +26,6 @@ define(function(require) {
*/
name: 'Canvas',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/code_manager/main.js

@ -51,13 +51,6 @@ define(function(require) {
*/
name: 'CodeManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/commands/main.js

@ -62,13 +62,6 @@ define(function(require) {
*/
name: 'Commands',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

23
src/css_composer/main.js

@ -25,19 +25,20 @@ define(function(require) {
*/
name: 'CssComposer',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Mandatory for the storage manager
* @type {String}
* @private
*/
storageKey: 'css', // [css, style] ??
storageKey: function(){
var keys = [];
var smc = c.stm.getConfig() || {};
if(smc.storeCss)
keys.push('css');
if(smc.storeStyles)
keys.push('style');
return keys;
},
/**
* Initialize module. Automatically called with a new instance of the editor
@ -109,10 +110,10 @@ define(function(require) {
if(!c.stm)
return;
var obj = {};
var smc = c.stm.getConfig();
if(smc.storeCss)
var keys = this.storageKey();
if(keys.indexOf('css') >= 0)
obj.css = c.em.getCss();
if(smc.storeStyles)
if(keys.indexOf('style') >= 0)
obj.styles = JSON.stringify(rules);
if(!noStore)
c.stm.store(obj);

2
src/demo.js

@ -10,7 +10,7 @@ require(['config/require-config'], function() {
container : '#gjs',
height: '100%',
fromElement: true,
storageManager:{ autoload: 1},
storageManager:{ autoload: 0},
commands: {
defaults : [{

7
src/device_manager/main.js

@ -30,13 +30,6 @@ define(function(require) {
*/
name: 'DeviceManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

33
src/dom_components/main.js

@ -57,19 +57,20 @@ define(function(require) {
*/
name: 'DomComponents',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Mandatory for the storage manager
* @type {String}
* @private
*/
storageKey: 'html', // [css, style] ??
storageKey: function(){
var keys = [];
var smc = c.stm.getConfig() || {};
if(smc.storeHtml)
keys.push('html');
if(smc.storeComponents)
keys.push('components');
return keys;
},
/**
* Initialize module. Automatically called with a new instance of the editor
@ -100,15 +101,21 @@ define(function(require) {
model: component,
config: c,
});
return this;
},
/**
* On load callback
* @private
*/
onLoad: function(){
if(c.stm && c.stm.getConfig().autoload)
this.load();
if(c.stm && c.stm.isAutosave()){
c.em.initUndoManager();
c.em.initUndoManager();
c.em.initChildrenComp(this.getWrapper());
}
return this;
},
/**
@ -145,10 +152,10 @@ define(function(require) {
if(!c.stm)
return;
var obj = {};
var smc = c.stm.getConfig();
if(smc.storeHtml)
var keys = this.storageKey();
if(keys.indexOf('html') >= 0)
obj.html = c.em.getHtml();
if(smc.storeComponents)
if(keys.indexOf('components') >= 0)
obj.components = JSON.stringify(c.em.getComponents());
if(!noStore)
c.stm.store(obj);

198
src/editor/model/Editor.js

@ -1,47 +1,9 @@
var deps = ['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'DeviceManager', 'Parser', 'SelectorManager',
'ModalDialog', 'AssetManager', 'CodeManager', 'Panels', 'RichTextEditor', 'StyleManager', 'Commands', 'CssComposer',
'DomComponents', 'Canvas', 'BlockManager'];
define([
'backbone',
'backboneUndo',
'keymaster',
'AssetManager',
'BlockManager',
'StorageManager',
'DeviceManager',
'ModalDialog',
'CodeManager',
'CssComposer',
'Commands',
'Canvas',
'RichTextEditor',
'DomComponents',
'SelectorManager',
'StyleManager',
'Panels',
'Parser',
'Utils'],
function(
Backbone,
UndoManager,
Keymaster,
AssetManager,
BlockManager,
StorageManager,
DeviceManager,
ModalDialog,
CodeManager,
CssComposer,
Commands,
Canvas,
RichTextEditor,
DomComponents,
SelectorManager,
StyleManager,
Panels,
Parser,
Utils
){
'ModalDialog', 'CodeManager', 'Panels', 'RichTextEditor', 'StyleManager', 'AssetManager', 'CssComposer',
'DomComponents', 'Canvas', 'Commands', 'BlockManager'];
define(deps, function(backbone, backboneUndo, keymaster, Utils, StorageManager, DeviceManager, Parser, SelectorManager,
ModalDialog, CodeManager, Panels, RichTextEditor, StyleManager, AssetManager, CssComposer,
DomComponents, Canvas, Commands, BlockManager){
return Backbone.Model.extend({
defaults: {
@ -55,31 +17,41 @@ define([
initialize: function(c) {
this.config = c;
this.pfx = this.config.storagePrefix;
this.compName = this.pfx + 'components' + this.config.id;
this.rulesName = this.pfx + 'rules' + this.config.id;
this.set('Config', c);
if(c.el && c.fromElement)
this.config.components = c.el.innerHTML;
this.loadModule('Utils'); // no dep
this.loadModule('StorageManager'); // No dep
this.loadModule('DeviceManager'); // No dep
this.loadModule('Parser'); // No dep
this.loadModule('SelectorManager'); // No dep
this.loadModule('ModalDialog'); // No dep
this.loadModule('AssetManager'); // requires SelectorManager
this.loadModule('CodeManager'); // no deps
this.loadModule('Panels'); // no deps
this.loadModule('RichTextEditor'); // no deps
this.loadModule('StyleManager'); // no deps
this.loadModule('Commands'); // dep Canvas
this.loadModule('CssComposer'); // dep Canvas
this.loadModule('DomComponents'); // Requires AssetManager and Dialog for images components
this.loadModule('Canvas'); // Requires RTE and Components
this.loadModule('BlockManager'); // Requires utils, canvas
this.initUndoManager(); // Is already called (components and css composer)
// Load modules
/*
deps.forEach(function(name){
if(['backbone','backboneUndo','keymaster'].indexOf(name) >= 0)
return;
this.loadModule(name);
}, this);
*/
/*
var t = new DomComponents();
this.loadModule(Utils);
this.loadModule(StorageManager);
this.loadModule(DeviceManager);
this.loadModule(Parser);
this.loadModule(SelectorManager);
this.loadModule(ModalDialog);
this.loadModule(CodeManager);
this.loadModule(Panels);
this.loadModule(RichTextEditor);
this.loadModule(StyleManager);
this.loadModule(AssetManager);
this.loadModule(CssComposer);
this.loadModule(DomComponents);
this.loadModule(Canvas);
this.loadModule(Commands);
this.loadModule(BlockManager);
*/
this.initUndoManager(); // Is already called (inside components and css composer)
this.on('change:selectedComponent', this.componentSelected, this);
},
@ -92,9 +64,10 @@ define([
loadModule: function(moduleName) {
var c = this.config;
var M = new require(moduleName)();
//var M = new moduleName();
var name = M.name.charAt(0).toLowerCase() + M.name.slice(1);
var cfg = c[name] || c[M.name] || {};
cfg.pStylePrefix = c.stylePrefix;
cfg.pStylePrefix = c.stylePrefix || '';
// Check if module is storable
var sm = this.get('StorageManager');
@ -107,12 +80,14 @@ define([
cfg.em = this;
M.init(cfg);
// Bind the module to the editor model if public
if(!M.private)
this.set(M.name, M);
// Load callback
if(M.onLoad)
M.onLoad();
// Bind the module to the editor model if public
if(M.public)
this.set(M.name, M);
return this;
},
@ -177,10 +152,11 @@ define([
initUndoManager: function() {
if(this.um)
return;
if(this.cmp && this.config.undoManager){
var cmp = this.get('DomComponents');
if(cmp && this.config.undoManager){
var that = this;
this.um = new Backbone.UndoManager({
register: [this.cmp.getComponents(), this.get('CssComposer').getRules()],
register: [cmp.getComponents(), this.get('CssComposer').getRules()],
track: true
});
this.UndoManager = this.um;
@ -256,44 +232,6 @@ define([
this.trigger('select-comp',[model,val,options]);
},
/**
* Load components from storage
* @return {Object}
* @private
* *
loadComponents: function() {
var comps = '';
var result = this.getCacheLoad();
if(result.components){
try{
comps = JSON.parse(result.components);
}catch(err){}
}else if(result.html)
comps = result.html;
return comps;
},*/
/**
* Load rules from storage
* @return {Array<Object>}
* @private
* *
loadRules: function() {
var comps = '';
var result = this.getCacheLoad();
if(result.style){
try{
comps = JSON.parse(result.style);
}catch(err){}
}else if(result.css)
comps = this.get('Parser').parseCss(result.css);
return comps;
},*/
/**
* Triggered when components are updated
* @param {Object} model
@ -454,31 +392,17 @@ define([
*/
store: function(){
var sm = this.get('StorageManager');
var store = {};
if(!sm)
return;
var smc = sm.getConfig();
var store = {};
/*
if(smc.storeHtml)
store.html = this.getHtml();
if(smc.storeComponents)
store.components = JSON.stringify(this.getComponents());
if(smc.storeCss)
store.css = this.getCss();
if(smc.storeStyles)
store.styles = JSON.stringify(this.getStyle());
*/
// Fetch what to store
this.get('storables').forEach(function(m){
var obj = m.store(1);
for(var el in obj)
store[el] = obj[el];
});
console.log('TO STORE', store);
sm.store(store);
return store;
},
@ -493,8 +417,6 @@ define([
this.get('storables').forEach(function(m){
m.load(result);
});
//this.setComponents(result.components || result.html);
//this.setStyle(result.styles || result.css);
return result;
},
@ -506,36 +428,24 @@ define([
*/
getCacheLoad: function(force){
var f = force ? 1 : 0;
if(this.cacheLoad && !f)
return this.cacheLoad;
var sm = this.get('StorageManager');
var load = [];
if(!sm)
return {};
var smc = sm.getConfig();
if(smc.storeHtml)
load.push('html');
if(smc.storeComponents)
load.push('components');
if(smc.storeCss)
load.push('css');
if(smc.storeStyles)
load.push('styles');
this.get('storables').forEach(function(m){
load.push(m.storageKey);
var key = m.storageKey;
key = typeof key === 'function' ? key() : key;
keys = key instanceof Array ? key : [key];
keys.forEach(function(k){
load.push(k);
});
});
this.cacheLoad = sm.load(load);
return this.cacheLoad;
},

7
src/modal_dialog/main.js

@ -18,13 +18,6 @@ define(function(require) {
*/
name: 'Modal',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/panels/main.js

@ -64,13 +64,6 @@ define(function(require) {
*/
name: 'Panels',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/parser/main.js

@ -16,13 +16,6 @@ define(function(require) {
*/
name: 'Parser',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/rich_text_editor/main.js

@ -17,13 +17,6 @@ define(function(require) {
*/
name: 'rte',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/selector_manager/main.js

@ -52,13 +52,6 @@ define(function(require) {
*/
name: 'SelectorManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/storage_manager/main.js

@ -40,13 +40,6 @@ define(function(require) {
*/
name: 'StorageManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/style_manager/main.js

@ -65,13 +65,6 @@ define(function(require) {
*/
name: 'StyleManager',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations

7
src/utils/main.js

@ -12,13 +12,6 @@ define(function(require) {
*/
name: 'Utils',
/**
* Indicates if module is public
* @type {Boolean}
* @private
*/
public: true,
/**
* Initialize module
*/

Loading…
Cancel
Save