Browse Source

- General fixes

- Fixed sector view
- Added Style Manager switcher that hides it in case no element selected
- Added possibility to copy & paste components. It also possible to disable this feature
pull/4/head
Artur Arseniev 10 years ago
parent
commit
bc223d9bf6
  1. 22
      src/commands/config/config.js
  2. 23
      src/commands/view/CommandAbstract.js
  3. 96
      src/commands/view/DeleteComponent.js
  4. 24
      src/commands/view/MoveComponent.js
  5. 27
      src/commands/view/OpenLayers.js
  6. 53
      src/commands/view/OpenStyleManager.js
  7. 163
      src/commands/view/SelectComponent.js
  8. 14
      src/demo.js
  9. 17
      src/dom_components/config/config.js
  10. 18
      src/dom_components/main.js
  11. 31
      src/dom_components/model/Component.js
  12. 21
      src/editor/config/config.js
  13. 125
      src/editor/model/Editor.js
  14. 29
      src/style_manager/config/config.js
  15. 48
      src/style_manager/view/SectorView.js
  16. 22
      src/style_manager/view/SectorsView.js
  17. 7
      styles/css/main.css
  18. 2
      styles/css/main.css.map
  19. 7
      styles/scss/main.scss

22
src/commands/config/config.js

@ -1,25 +1,25 @@
define(function () {
return {
ESCAPE_KEY : 27,
stylePrefix : 'com-',
defaults : [],
// Editor model
em : null,
// If true center new first-level components
firstCentered : true,
// If true the new component will created with 'height', else 'min-height'
newFixedH : false,
newFixedH : false,
// Minimum height (in px) of new component
minComponentH : 50,
// Minimum width (in px) of component on creation
minComponentW : 50,
// Minimum width (in px) of component on creation
minComponentW : 50,
};
});

23
src/commands/view/CommandAbstract.js

@ -1,34 +1,35 @@
define(['backbone'],
function(Backbone) {
/**
/**
* @class CommandAbstract
* */
return Backbone.View.extend({
/**
* Initialize method that can't be removed
* @param {Object} o Options
* */
initialize: function(o) {
this.config = o;
this.editorModel = this.em = o.em || {};
this.canvasId = o.canvasId || '';
this.canvasId = o.canvasId || '';
this.wrapperId = o.wrapperId || 'wrapper';
this.pfx = o.stylePrefix;
this.pfx = o.stylePrefix;
this.hoverClass = this.pfx + 'hover';
this.badgeClass = this.pfx + 'badge';
this.plhClass = this.pfx + 'placeholder';
this.plhClass = this.pfx + 'placeholder';
this.setElement(this.editorModel.get('$editor').find('#'+this.canvasId));
this.$canvas = this.$el;
this.$wrapper = this.$canvas.find('#'+this.wrapperId);
this.$canvas = this.$el;
this.$wrapper = this.$canvas.find('#'+this.wrapperId);
this.init(o);
},
/**
* Callback triggered after initialize
* @param {Object} o Options
* */
init: function(o){},
/**
* Method that run command
* @param {Object} em Editor model
@ -37,7 +38,7 @@ define(['backbone'],
run: function(em, sender) {
console.warn("No run method found");
},
/**
* Method that stop command
* @param {Object} em Editor model
@ -46,6 +47,6 @@ define(['backbone'],
stop: function(em, sender) {
console.warn("No stop method found");
}
});
});

96
src/commands/view/DeleteComponent.js

@ -1,55 +1,83 @@
define(['backbone', './SelectComponent'],
function(Backbone, SelectComponent) {
/**
/**
* @class DeleteComponent
* */
return _.extend({},SelectComponent,{
init: function(o){
_.bindAll(this, 'startDelete', 'stopDelete', 'onDelete');
this.hoverClass = this.pfx + 'hover-delete';
this.badgeClass = this.pfx + 'badge-red';
},
enable: function(){
enable: function()
{
var that = this;
this.$el.find('*').mouseover(function (e){
e.stopPropagation();
if($(this).data('model').get('removable')){ //Show badge if possible
$(this).addClass(that.hoverClass);
that.attachBadge(this);
}
}).mouseout(function (e){ //hover out
e.stopPropagation();
$(this).removeClass(that.hoverClass);
if(that.badge) //Hide badge if possible
that.badge.css({ left: -1000, top:-1000 });
}).click(function(e){
that.onSelect(e,this); //Callback on select
});
this.$el.find('*')
.mouseover(this.startDelete)
.mouseout(this.stopDelete)
.click(this.onDelete);
},
/**
* Say what to do after the component was selected
* @param Event
* @param Object Selected element
* */
onSelect: function(e, el){
/**
* Start command
* @param {Object} e
*/
startDelete: function(e)
{
e.stopPropagation();
var $this = $(e.target);
// Show badge if possible
if($this.data('model').get('removable')){
$this.addClass(this.hoverClass);
this.attachBadge($this.get(0));
}
},
/**
* Stop command
* @param {Object} e
*/
stopDelete: function(e)
{
e.stopPropagation();
var $this = $(e.target);
$this.removeClass(this.hoverClass);
// Hide badge if possible
if(this.badge)
this.badge.css({ left: -1000, top:-1000 });
},
/**
* Delete command
* @param {Object} e
*/
onDelete: function(e)
{
e.stopPropagation();
var $selected = $(el);
if(!$selected.data('model').get('removable')) //Do nothing in case can't remove
var $this = $(e.target);
// Do nothing in case can't remove
if(!$this.data('model').get('removable'))
return;
$selected.data('model').destroy();
$this.data('model').destroy();
this.removeBadge();
this.clean();
},
/**
/**
* Updates badge label
* @param Object Model
* @return void
* @param {Object} model
* */
updateBadgeLabel: function (model){
this.badge.html( 'Remove '+model.getName() );
updateBadgeLabel: function (model)
{
this.badge.html( 'Remove ' + model.getName() );
},
});
});

24
src/commands/view/MoveComponent.js

@ -6,7 +6,8 @@ define(['backbone', './SelectComponent','./SelectPosition'],
return _.extend({},SelectComponent, SelectPosition,{
init: function(o){
_.bindAll(this,'startMove','onMove','endMove','rollback','selectingPosition','itemLeft');//to mantein 'this' context
SelectComponent.init.apply(this, arguments);
_.bindAll(this,'startMove','onMove','endMove','rollback','selectingPosition','itemLeft');
this.opt = o;
this.hoverClass = this.pfx + 'hover-move';
this.badgeClass = this.pfx + 'badge-yellow';
@ -19,20 +20,23 @@ define(['backbone', './SelectComponent','./SelectPosition'],
this.$el.css('cursor','move');
this.$el.on('mousedown', this.startMove);
this.startSelectComponent();
//Avoid strange moving behavior
this.$el.addClass(this.noSelClass);
},
/** Highlight component when pointer is over it
* @param Event
* @param Object Component
* @return void
* */
highlightComponent: function(e, el){
/**
* Hover command
* @param {Object} e
*/
onHover: function(e)
{
e.stopPropagation();
if($(el).data('model').get('movable')){ //Show badge if possible
$(el).addClass(this.hoverClass);
this.attachBadge(el);
var $this = $(e.target);
if($this.data('model').get('movable')){ //Show badge if possible
$this.addClass(this.hoverClass);
this.attachBadge(e.target);
}
},

27
src/commands/view/OpenLayers.js

@ -1,31 +1,32 @@
define(['Navigator'], function(Layers) {
/**
/**
* @class OpenStyleManager
* */
return {
run: function(em, sender)
{
if(!this.$layers){
var collection = em.get('Components').getComponent().get('components'),
config = em.get('Config'),
panels = em.get('Panels'),
lyStylePfx = config.layers.stylePrefix || 'nv-';
config = em.get('Config'),
panels = em.get('Panels'),
lyStylePfx = config.layers.stylePrefix || 'nv-';
config.layers.stylePrefix = config.stylePrefix + lyStylePfx;
var layers = new Layers(collection, config.layers);
this.$layers = layers.render();
var layers = new Layers(collection, config.layers);
this.$layers = layers.render();
// Check if panel exists otherwise crate it
if(!panels.getPanel('views-container'))
this.panel = panels.addPanel({ id: 'views-container'});
this.panel = panels.addPanel({ id: 'views-container'});
else
this.panel = panels.getPanel('views-container');
this.panel = panels.getPanel('views-container');
this.panel.set('appendContent', this.$layers).trigger('change:appendContent');
}
this.$layers.show();
},
stop: function()
{
if(this.$layers)

53
src/commands/view/OpenStyleManager.js

@ -1,36 +1,65 @@
define(['StyleManager'], function(StyleManager) {
/**
/**
* @class OpenStyleManager
* */
return {
run: function(em, sender)
{
this.sender = sender;
if(!this.$sm){
var config = em.get('Config'),
panels = em.get('Panels'),
smStylePfx = config.styleManager.stylePrefix || 'sm-';
config.styleManager.stylePrefix = config.stylePrefix + smStylePfx;
panels = em.get('Panels'),
pfx = config.styleManager.stylePrefix || 'sm-';
config.styleManager.stylePrefix = config.stylePrefix + pfx;
config.styleManager.target = em;
var sm = new StyleManager(config.styleManager);
this.$sm = sm.render();
if(!panels.getPanel('views-container'))
this.panel = panels.addPanel({ id: 'views-container'});
else
this.panel = panels.getPanel('views-container');
this.panel.set('appendContent', this.$sm).trigger('change:appendContent');
// Create header
this.$header = $('<div>', {
class : config.styleManager.stylePrefix + 'header',
text : config.styleManager.textNoElement,
});
// Add all to the panel
this.panel.set('appendContent', this.$sm.add(this.$header) ).trigger('change:appendContent');
this.target = em;
this.listenTo( this.target ,'change:selectedComponent', this.toggleSm);
}
this.$sm.show();
this.toggleSm();
},
/**
* Toggle Style Manager visibility
*/
toggleSm: function()
{
if(!this.sender.get('active'))
return;
if(this.target.get('selectedComponent')){
this.$sm.show();
this.$header.hide();
}else{
this.$sm.hide();
this.$header.show();
}
},
stop: function()
{
if(this.$sm)
this.$sm.hide();
if(this.$header)
this.$header.hide();
}
};
});

163
src/commands/view/SelectComponent.js

@ -1,24 +1,96 @@
define(function() {
/**
/**
* @class SelectComponent
* */
return {
enable: function(){
init: function(o){
_.bindAll(this, 'onHover', 'onOut', 'onClick');
},
enable: function()
{
_.bindAll(this,'copyComp','pasteComp');
var confMain = this.config.em.get('Config');
this.startSelectComponent();
if(confMain.copyPaste){
key('⌘+c, ctrl+c', this.copyComp);
key('⌘+v, ctrl+v', this.pasteComp);
}
},
/**
* Copy component to clipboard
*/
copyComp: function()
{
var sel = this.editorModel.get('selectedComponent');
if(sel && sel.get('copyable'))
this.editorModel.set('clipboard', sel);
},
/**
* Paste component from clipboard
*/
pasteComp: function()
{
var clp = this.editorModel.get('clipboard'),
sel = this.editorModel.get('selectedComponent');
if(clp && sel && sel.collection){
var index = sel.collection.indexOf(sel),
clone = clp.clone();
sel.collection.add(clone, { at: index + 1 });
}
},
/** Start select component event
* @return void
* */
startSelectComponent: function(){
var that = this;
this.$el.find('*').on('mouseover',function(e){ that.highlightComponent(e,this); })
.on('mouseout' ,function(e){ that.removeHighlightComponent(e,this); })
.on('click' ,function(e){ that.selectComponent(e,this); });
this.$el.find('*')
.on('mouseover',this.onHover)
.on('mouseout', this.onOut)
.on('click', this.onClick);
this.selEl = this.$el.find('*');
},
/**
* Hover command
* @param {Object} e
*/
onHover: function(e)
{
e.stopPropagation();
$(e.target).addClass(this.hoverClass);
this.attachBadge(e.target);
},
/**
* Out command
* @param {Object} e
*/
onOut: function(e)
{
e.stopPropagation();
$(e.target).removeClass(this.hoverClass);
if(this.badge)
this.badge.css({ left: -10000, top:-10000 });
},
/**
* Hover command
* @param {Object} e
*/
onClick: function(e)
{
var s = $(e.target).data('model').get('stylable');
if(!(s instanceof Array) && !s)
return;
this.onSelect(e, e.target);
},
/** Stop select component event
* @param Event
* @return void
@ -28,45 +100,14 @@ define(function() {
this.selEl.trigger('mouseout').off('mouseover mouseout click');
this.selEl = null;
},
/** Highlight component when pointer is over it
* @param Event
* @param Object Component
* @return void
* */
highlightComponent: function(e, el){
e.stopPropagation();
$(el).addClass(this.hoverClass);
this.attachBadge(el);
},
/** Remove highlight from component
* @param Event
* @param Object Component
* @return void
* */
removeHighlightComponent: function(e, el){
e.stopPropagation();
$(el).removeClass(this.hoverClass);
if(this.badge) //Hide badge if possible
this.badge.css({ left: -10000, top:-10000 }); //TODO HIDE
},
/** Select highlighted component
* @param Event
* @param Object Component
* @return void
* */
selectComponent: function(e, el){
var s = $(el).data('model').get('stylable');
if(!(s instanceof Array) && !s)
return;
this.onSelect(e,el); //Callback on select
},
/** Say what to do after the component was selected
* @param Event
* @param Object Selected element
/**
* Say what to do after the component was selected
* @param {Object} e
* @param {Object} el
* */
onSelect: function(e, el){
onSelect: function(e, el)
{
e.stopPropagation();
if(this.$selected) //Check if already selected before
this.$selected.removeClass('selected-component');
@ -78,14 +119,14 @@ define(function() {
this.$selected.data('model').set('status','selected');
}
},
/** Removes all highlighting effects on components
* @return void
* */
clean: function(){
this.$el.find('*').removeClass(this.hoverClass);
},
/** Attach badge to component
* @param Object Component
* @return void
@ -111,24 +152,24 @@ define(function() {
relativeT -= badgeH;
this.badge.css({ left: relativeL, top:relativeT });
},
/** Create badge for the component
* @return void
* */
createBadge: function (){
this.badge = $('<div>', {class: this.badgeClass + " no-dots"}).appendTo(this.$wrapper);
},
/** Remove badge
* @return void
* */
removeBadge: function (){
if(this.badge){
if(this.badge){
this.badge.remove();
delete this.badge;
}
},
/** Updates badge label
* @param Object Model
* @return void
@ -137,16 +178,17 @@ define(function() {
if(model)
this.badge.html( model.getName() );
},
/** Run method
/**
* Run method
* */
run: function(){
run: function(em, sender){
this.enable();
this.render();
this.active = true;
},
/** Stop method
/**
* Stop method
* */
stop: function(){
if(this.editorModel.get('selectedComponent'))
@ -154,11 +196,12 @@ define(function() {
this.$el.unbind(); //removes all attached events
if(this.$selected) //check if already selected before
this.$selected.removeClass('selected-component');
this.removeBadge();
this.removeBadge();
this.clean();
this.$el.find('*').unbind('mouseover').unbind('mouseout').unbind('click');
this.editorModel.set('selectedComponent',null);
this.active = false;
key.unbind('⌘+c, ctrl+c');
key.unbind('⌘+v, ctrl+v');
}
};
});

14
src/demo.js

@ -1,7 +1,9 @@
require(['src/config/require-config.js'], function() {
require(['editor/main'],function (Grapes){
var grapes = new Grapes({
var grapes = new Grapes(
{
container : '#wte-app',
@ -46,7 +48,7 @@ require(['src/config/require-config.js'], function() {
{ id: 'box100', className: 'fa fa-square-o', command: 'insert-custom',
attributes : { title : 'Create all-width box' },
options: {
content : { style: { width: '100%', 'min-height': '75px'}},
content : { style: { width: '100%', 'min-height': '75px', 'padding': '7px'}},
terminateAfterInsert : false,
},},
]
@ -158,6 +160,7 @@ require(['src/config/require-config.js'], function() {
}],
},{
name: 'Dimension',
open: false,
properties:[{
name : 'Width',
property : 'width',
@ -263,6 +266,7 @@ require(['src/config/require-config.js'], function() {
},],
},{
name: 'Typography',
open: false,
properties:[{
name : 'Font',
property : 'font-family',
@ -371,6 +375,7 @@ require(['src/config/require-config.js'], function() {
}],
},{
name: 'Decorations',
open: false,
properties: [{
name : 'Border radius',
property : 'border-radius',
@ -534,6 +539,7 @@ require(['src/config/require-config.js'], function() {
},],
},{
name: 'Extra',
open: false,
properties: [{
name: 'Transition',
property: 'transition',
@ -603,7 +609,9 @@ require(['src/config/require-config.js'], function() {
],
},
});
}
);
grapes.render();

17
src/dom_components/config/config.js

@ -1,27 +1,28 @@
define(function () {
return {
stylePrefix : 'comp-',
wrapperId : 'wrapper',
// Default wrapper configuration
wrapper : {
removable : false,
removable : false,
copyable : false,
stylable : ['background','background-color','background-image', 'background-repeat','background-attachment','background-position'],
movable : false,
badgable : false,
},
// Could be used for default components
components : {},
rte : {},
em : {},
// Class for new image component
imageCompClass : 'fa fa-picture-o',
// Open assets manager on create of image component
oAssetsOnCreate : true,
};

18
src/dom_components/main.js

@ -2,7 +2,7 @@ define(function(require) {
/**
* @class Components
* @param {Object} Configurations
*
*
* @return {Object}
* */
function Components(config)
@ -21,34 +21,34 @@ define(function(require) {
if (!(name in c))
c[name] = defaults[name];
}
if(!c.wrapper.attributes)
c.wrapper.attributes = {};
c.wrapper.attributes.id = 'wrapper';
if(!c.wrapper.style)
c.wrapper.style = {};
c.wrapper.style.position = 'relative';
this.component = new Component(c.wrapper);
var obj = {
model : this.component,
config : c,
};
this.ComponentView = new ComponentView(obj);
}
Components.prototype = {
render : function(){
return this.ComponentView.render().$el;
},
getComponent : function(){
return this.component;
},
};
return Components;
});

31
src/dom_components/model/Component.js

@ -1,10 +1,10 @@
define(['backbone','./Components'],
define(['backbone','./Components'],
function (Backbone, Components) {
/**
* @class Component
* */
return Backbone.Model.extend({
return Backbone.Model.extend({
defaults: {
tagName : 'div',
type : '',
@ -14,22 +14,39 @@ define(['backbone','./Components'],
droppable : true,
badgable : true,
stylable : true,
copyable : true,
status : '',
previousModel : '',
content : '',
style : {},
attributes : {},
},
initialize: function(options) {
this.defaultC = options.components || [];
this.components = new Components(this.defaultC);
this.set('components', this.components);
},
/**
* Override original clone method
*/
clone: function()
{
var attr = _.clone(this.attributes),
comp = this.get('components');
attr.components = [];
if(comp.length){
comp.each(function(md,i){
attr.components[i] = md.clone();
});
}
return new this.constructor(attr);
},
/**
* Get name of the component
*
*
* @return string
* */
getName: function(){
@ -40,6 +57,6 @@ define(['backbone','./Components'],
}
return this.name;
},
});
});

21
src/editor/config/config.js

@ -13,12 +13,15 @@ define(function () {
// Where render the editor
container : '',
idCanvas : 'canvas',
idCanvas : 'canvas',
idCanvasOverlay : 'canvas-overlay',
idCanvasOverlay : 'canvas-overlay',
idWrapper : 'wrapper',
// Enable/Disable possibility to copy(ctrl + c) & paste(ctrl + v) components
copyPaste : true,
// Enable/Disable undo manager
undoManager : true,
@ -29,34 +32,34 @@ define(function () {
assetManager : {},
//Configurations for Canvas
canvas : {},
canvas : {},
//Configurations for Style Manager
styleManager : {},
//Configurations for Layers
layers : {},
layers : {},
//Configurations for Storage Manager
storageManager : {},
storageManager : {},
//Configurations for Rich Text Editor
rte : {},
rte : {},
//Configurations for Components
components : {},
//Configurations for Modal Dialog
modal : {},
modal : {},
//Configurations for Code Manager
codeManager : {},
//Configurations for Panels
panels : {},
panels : {},
//Configurations for Commands
commands : {},
commands : {},
};
return config;

125
src/editor/model/Editor.js

@ -2,9 +2,9 @@ define([
'backbone',
'backboneUndo',
'keymaster',
'AssetManager',
'StorageManager',
'ModalDialog',
'AssetManager',
'StorageManager',
'ModalDialog',
'CodeManager',
'Commands',
'Canvas',
@ -15,10 +15,10 @@ define([
Backbone,
UndoManager,
Keymaster,
AssetManager,
StorageManager,
ModalDialog,
CodeManager,
AssetManager,
StorageManager,
ModalDialog,
CodeManager,
Commands,
Canvas,
RichTextEditor,
@ -26,18 +26,19 @@ define([
Panels
){
return Backbone.Model.extend({
defaults:{
selectedComponent: null,
changesCount: 0,
clipboard : null,
selectedComponent : null,
changesCount : 0,
},
initialize: function(c)
{
this.config = c;
this.compName = this.config.storagePrefix + 'components' + this.config.id;
this.set('Config', c);
this.initStorage();
this.initModal();
this.initAssetManager();
@ -48,10 +49,10 @@ define([
this.initComponents();
this.initCanvas();
this.initUndoManager();
this.on('change:selectedComponent', this.componentSelected, this);
},
/**
* Initialize components
* */
@ -60,31 +61,31 @@ define([
var cfg = this.config.components,
comp = this.loadComponentsTree(),
cmpStylePfx = cfg.stylePrefix || 'comp-';
cfg.stylePrefix = this.config.stylePrefix + cmpStylePfx;
if(comp)
cfg.wrapper = comp;
if(this.rte)
cfg.rte = this.rte;
if(this.modal)
cfg.modal = this.modal;
if(this.am)
cfg.am = this.am;
cfg.em = this;
this.cmp = new DomComponents(cfg);
if(this.stm.isAutosave()){ // TODO Currently doesn't listen already created models
this.updateComponents( this.cmp.getComponent(), null, { avoidStore : 1 });
}
this.set('Components', this.cmp);
},
/**
* Initialize canvas
* */
@ -98,10 +99,10 @@ define([
if(this.cmp)
this.cv.setWrapper(this.cmp);
this.set('Canvas', this.cv);
},
/**
* Initialize rich text editor
* */
@ -113,7 +114,7 @@ define([
this.rte = new RichTextEditor(cfg);
this.set('RichTextEditor', this.rte);
},
/**
* Initialize storage
* */
@ -123,7 +124,7 @@ define([
this.stm.loadDefaultProviders().setCurrentProvider(this.config.storageType);
this.set('StorageManager', this.stm);
},
/**
* Initialize asset manager
* */
@ -132,14 +133,14 @@ define([
var cfg = this.config.assetManager,
pfx = cfg.stylePrefix || 'am-';
cfg.stylePrefix = this.config.stylePrefix + pfx;
if(this.stm)
cfg.stm = this.stm;
this.am = new AssetManager(cfg);
this.set('AssetManager', this.am);
},
/**
* Initialize modal
* */
@ -152,7 +153,7 @@ define([
this.modal.render().appendTo('body');
this.set('Modal', this.modal);
},
/**
* Initialize Code Manager
* */
@ -165,7 +166,7 @@ define([
this.cm.loadDefaultGenerators().loadDefaultEditors();
this.set('CodeManager', this.cm);
},
/**
* Initialize Commands
* */
@ -181,7 +182,7 @@ define([
this.com.loadDefaultCommands();
this.set('Commands', this.com);
},
/**
* Initialize Panels
* */
@ -195,23 +196,25 @@ define([
this.pn.addPanel({ id: 'views-container'});
this.set('Panels', this.pn);
},
/**
* Initialize Undo manager
* */
initUndoManager: function(){
if(this.cmp && this.config.undoManager){
var backboneUndo = new Backbone.UndoManager({
var that = this;
this.um = new Backbone.UndoManager({
register: [this.cmp.getComponent().get('components')],
track: true
});
this.set('UndoManager', this.um);
key('⌘+z, ctrl+z', function(){
backboneUndo.undo();
that.um.undo();
});
key('⌘+shift+z, ctrl+shift+z', function(){
backboneUndo.redo();
that.um.redo();
});
Backbone.UndoManager.removeUndoType("change");
var beforeCache;
Backbone.UndoManager.addUndoType("change:style", {
@ -237,12 +240,12 @@ define([
model.set(af);
}
});
//TODO when, for example, undo delete cant redelete it, so need to
//TODO when, for example, undo delete cant redelete it, so need to
//recall 'remove command'
}
},
/**
* Triggered when components are updated
* */
@ -256,13 +259,13 @@ define([
this.storeComponentsTree();
this.set('changesCount', 0 );
},
/**
/**
* Callback on component selection
* @param {Object} Model
* @param {Mixed} New value
* @param {Object} Options
*
*
* */
componentSelected: function(model, val, options)
{
@ -271,10 +274,10 @@ define([
else
this.trigger('select-comp',[model,val,options]);
},
/**
/**
* Load components from storage
*
*
* @return {Object}
* */
loadComponentsTree: function(){
@ -286,10 +289,10 @@ define([
}
return result;
},
/**
/**
* Save components to storage
*
*
* @return void
* */
storeComponentsTree: function(){
@ -299,44 +302,48 @@ define([
this.stm.store(this.compName, JSON.stringify(res));
}
},
/**
* Triggered when components are updated
* @param {Object} model
* @param {Mixed} val Value
* @param {Object} opt Options
*
*
* */
updateComponents: function(model, val, opt){
var comps = model.get('components'),
avSt = opt ? opt.avoidStore : 0;
// Call stopListening for not creating nested listenings
// Observe component with Undo Manager
if(this.um)
this.um.register(model.get('components'));
// Call stopListening for not creating nested listenings
this.stopListening(comps, 'add', this.updateComponents);
this.stopListening(comps, 'remove', this.rmComponents);
this.listenTo(comps, 'add', this.updateComponents);
this.listenTo(comps, 'remove', this.rmComponents);
this.stopListening(model, 'change:style change:content', this.updateComponents);
this.listenTo(model, 'change:style change:content', this.updateComponents);
if(!avSt)
this.componentsUpdated();
},
/**
* Triggered when some component is removed updated
* @param {Object} model
* @param {Mixed} val Value
* @param {Object} opt Options
*
*
* */
rmComponents: function(model, val, opt){
var avSt = opt ? opt.avoidStore : 0;
if(!avSt)
this.componentsUpdated();
}
});
});

29
src/style_manager/config/config.js

@ -1,11 +1,26 @@
define(function () {
return {
stylePrefix : 'sm-',
target : null,
sectors : [],
stylePrefix : 'sm-',
// Default sectors, which could include also properties
//
// Example:
// sectors: [{
// name: 'Some sector name',
// properties:[{
// name : 'Width',
// property : 'width',
// type : 'integer',
// units : ['px','%'],
// defaults : 'auto',
// min : 0,
// }],
// }]
sectors : [],
// Text to show in case no element selected
textNoElement : 'Select element before using Style Manager',
};
});

48
src/style_manager/view/SectorView.js

@ -9,60 +9,70 @@ define(['backbone','./PropertiesView'],
initialize: function(o) {
this.config = o.config;
this.pfx = this.config.stylePrefix;
this.pfx = this.config.stylePrefix;
this.target = o.target || {};
this.open = this.model.get('open');
this.listenTo( this.model ,'change:open', this.updateOpen);
this.events['click .' + this.pfx + 'title'] = 'toggle';
this.delegateEvents();
},
/**
* Update visibility
*/
updateOpen: function()
{
if(this.model.get('open'))
this.show();
else
this.hide();
},
/**
* Show the content of the sector
* */
show : function(){
show : function()
{
this.$el.addClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').show();
this.open = true;
},
/**
* Hide the content of the sector
* */
hide : function(){
hide : function()
{
this.$el.removeClass(this.pfx + "open");
this.$el.find('.' + this.pfx + 'properties').hide();
this.open = false;
},
/**
* Toggle visibility of the content
* Toggle visibility
* */
toggle: function(){
if(this.open)
this.hide();
else
this.show();
toggle: function()
{
var v = this.model.get('open') ? 0 : 1;
this.model.set('open', v);
},
render : function(){
if(this.open)
this.show();
else
this.hide();
render : function()
{
this.$el.html('<div class="' + this.pfx + 'title">'+this.model.get('name')+'</div>');
this.renderProperties();
this.$el.attr('class', this.pfx + 'sector no-select');
this.updateOpen();
return this;
},
renderProperties: function(){
renderProperties: function()
{
var objs = this.model.get('properties');
if(objs){
var view = new PropertiesView({
collection : objs,
target : this.target,
config : this.config,
target : this.target,
config : this.config,
});
this.$el.append(view.render().el);
}

22
src/style_manager/view/SectorsView.js

@ -1,31 +1,31 @@
define(['backbone','./SectorView'],
define(['backbone','./SectorView'],
function (Backbone, SectorView) {
/**
/**
* @class sectorsView
* */
return Backbone.View.extend({
initialize: function(o) {
this.config = o.config;
this.pfx = this.config.stylePrefix;
this.target = o.target || {};
},
render: function() {
var fragment = document.createDocumentFragment();
this.collection.each(function(obj){
var view = new SectorView({
model : obj,
id : this.pfx + obj.get('name').replace(' ','_').toLowerCase(),
name : obj.get('name'),
model : obj,
id : this.pfx + obj.get('name').replace(' ','_').toLowerCase(),
name : obj.get('name'),
properties : obj.get('properties'),
target : this.target,
config : this.config,
target : this.target,
config : this.config,
});
fragment.appendChild(view.render().el);
}, this);
this.$el.attr('id', this.pfx + 'sectors');
this.$el.append(fragment);
return this;

7
styles/css/main.css

@ -2928,6 +2928,13 @@ div.wte-com-hover-move {
opacity: 0.7;
filter: alpha(opacity=70); }
.wte-sm-header {
color: #eee;
font-size: 11px;
font-weight: lighter;
padding: 10px;
text-shadow: 0 1px 0 #252525; }
.wte-sm-sector {
clear: both;
border-bottom: 1px solid #303030;

2
styles/css/main.css.map

File diff suppressed because one or more lines are too long

7
styles/scss/main.scss

@ -422,6 +422,13 @@ $arrowColor: darken($fontColor,24%); /*b1b1b1*/
&:hover{ @include opacity(0.7); }
}
.#{$sm-prefix}header {
color: $fontColor;
font-size: 11px;
font-weight: lighter;
padding: 10px;
text-shadow: 0 1px 0 $darkTextShadow;
}
.#{$sm-prefix}sector {
clear:both;
border-bottom: 1px solid $darkBorder;

Loading…
Cancel
Save