Browse Source

Refactor more modules with new loader

pull/36/head
Artur Arseniev 10 years ago
parent
commit
1c5db4d86c
  1. 99
      src/editor/model/Editor.js
  2. 1
      src/rich_text_editor/main.js
  3. 65
      src/style_manager/main.js
  4. 4
      test/specs/style_manager/main.js

99
src/editor/model/Editor.js

@ -1,11 +1,10 @@
var deps = ['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'DeviceManager', 'Parser',
'SelectorManager', 'ModalDialog', 'AssetManager', 'CodeManager', 'Panels', 'RichTextEditor',
var deps = ['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'DeviceManager', 'Parser', 'SelectorManager',
'ModalDialog', 'AssetManager', 'CodeManager', 'Panels', 'RichTextEditor', 'StyleManager',
'BlockManager',
'CssComposer',
'Commands',
'Canvas',
'DomComponents',
'StyleManager'];
'DomComponents'];
define([
'backbone',
'backboneUndo',
@ -78,13 +77,12 @@ define([
this.loadModule('CodeManager'); // no deps
this.loadModule('Panels'); // no deps
this.loadModule('RichTextEditor'); // no deps
this.loadModule('StyleManager'); // no deps
this.initCommands();
//this.initRichTextEditor();
this.initCssComposer();
this.initComponents(); // Requires AssetManager and Dialog for images components
this.initCanvas(); // Requires RTE
this.initCanvas(); // Requires RTE and Components
this.initUndoManager();
this.initStyleManager();
this.loadModule('BlockManager'); // Requires utils, canvas
this.on('change:selectedComponent', this.componentSelected, this);
@ -123,26 +121,50 @@ define([
},
/**
* Initialize editor model and set editor instance
* @param {Editor} editor Editor instance
* @return {this}
* Initialize Commands
* @private
*/
init: function(editor){
this.set('Editor', editor);
* */
initCommands: function() {
var cfg = this.config.commands,
pfx = cfg.stylePrefix || 'com-';
cfg.pStylePrefix = this.config.stylePrefix;
cfg.stylePrefix = this.config.stylePrefix + pfx;
cfg.em = this;
cfg.canvasId = this.config.idCanvas;
cfg.wrapperId = this.config.idWrapper;
this.com = new Commands(cfg);
this.Commands = this.com;
this.com.loadDefaultCommands();
this.set('Commands', this.com);
},
/**
* Initialize Style Manager
* Initialize canvas
* @private
* */
initStyleManager: function(){
var cfg = this.config.styleManager,
pfx = cfg.stylePrefix || 'sm-';
cfg.pStylePrefix = this.config.stylePrefix;
initCanvas: function() {
var cfg = this.config.canvas,
pfx = cfg.stylePrefix || 'cv-';
cfg.pStylePrefix = this.config.stylePrefix;
cfg.stylePrefix = this.config.stylePrefix + pfx;
cfg.target = this;
this.set('StyleManager', new StyleManager(cfg));
cfg.canvasId = this.config.idCanvas;
cfg.em = this;
this.cv = new Canvas(cfg);
if(this.cmp)
this.cv.setWrapper(this.cmp);
this.Canvas = this.cv;
this.set('Canvas', this.cv);
},
/**
* Initialize editor model and set editor instance
* @param {Editor} editor Editor instance
* @return {this}
* @private
*/
init: function(editor){
this.set('Editor', editor);
},
/**
@ -256,43 +278,6 @@ define([
this.set('Components', this.cmp);
},
/**
* Initialize canvas
* @private
* */
initCanvas: function() {
var cfg = this.config.canvas,
pfx = cfg.stylePrefix || 'cv-';
cfg.pStylePrefix = this.config.stylePrefix;
cfg.stylePrefix = this.config.stylePrefix + pfx;
cfg.canvasId = this.config.idCanvas;
cfg.em = this;
this.cv = new Canvas(cfg);
if(this.cmp)
this.cv.setWrapper(this.cmp);
this.Canvas = this.cv;
this.set('Canvas', this.cv);
},
/**
* Initialize Commands
* @private
* */
initCommands: function() {
var cfg = this.config.commands,
pfx = cfg.stylePrefix || 'com-';
cfg.pStylePrefix = this.config.stylePrefix;
cfg.stylePrefix = this.config.stylePrefix + pfx;
cfg.em = this;
cfg.canvasId = this.config.idCanvas;
cfg.wrapperId = this.config.idWrapper;
this.com = new Commands(cfg);
this.Commands = this.com;
this.com.loadDefaultCommands();
this.set('Commands', this.com);
},
/**
* Initialize Undo manager
* @private

1
src/rich_text_editor/main.js

@ -69,7 +69,6 @@ define(function(require) {
* @param {View} view
* */
attach: function(view){
console.log('attatch');
view.$el.wysiwyg({}).focus();
this.lastEl = view.el;

65
src/style_manager/main.js

@ -49,28 +49,53 @@
*/
define(function(require) {
var StyleManager = function(config){
var c = config || {},
defaults = require('./config/config'),
Sectors = require('./model/Sectors'),
SectorsView = require('./view/SectorsView');
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}
var sectors = new Sectors(c.sectors);
var obj = {
collection: sectors,
target: c.target,
config: c,
};
var SectView = new SectorsView(obj);
return function(){
var c = {},
defaults = require('./config/config'),
Sectors = require('./model/Sectors'),
SectorsView = require('./view/SectorsView');
var sectors, SectView;
return {
/**
* Name of the module
* @type {String}
* @private
*/
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
*/
init: function(config) {
c = config || {};
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}
var ppfx = c.pStylePrefix;
if(ppfx)
c.stylePrefix = ppfx + c.stylePrefix;
sectors = new Sectors(c.sectors);
SectView = new SectorsView({
collection: sectors,
target: c.em,
config: c,
});
return this;
},
/**
* Add new sector to the collection. If the sector with the same id already exists,
* that one will be returned
@ -208,6 +233,4 @@ define(function(require) {
};
};
return StyleManager;
});

4
test/specs/style_manager/main.js

@ -36,7 +36,7 @@ define([
var obj;
beforeEach(function () {
obj = new StyleManager({
obj = new StyleManager().init({
sectors: []
});
});
@ -148,7 +148,7 @@ define([
describe('Init with configuration', function() {
beforeEach(function () {
obj = new StyleManager({
obj = new StyleManager().init({
sectors: [{
id: 'dim',
name: 'Dimension',

Loading…
Cancel
Save