Browse Source

Update components

pull/36/head
Artur Arseniev 10 years ago
parent
commit
2014ebc40b
  1. 2
      src/canvas/view/FrameView.js
  2. 23
      src/commands/view/SelectPosition.js
  3. 9
      src/dom_components/main.js
  4. 1
      src/dom_components/model/Components.js
  5. 19
      src/editor/model/Editor.js
  6. 9
      src/utils/Sorter.js

2
src/canvas/view/FrameView.js

@ -21,7 +21,7 @@ function(Backbone) {
render: function() {
this.$el.attr({
style: 'width: 50%; display: block; height: 80%; border: medium none; margin: 50px auto 0; background-color: white',
style: 'width: 50%; display: block; height: 80%; border: medium none; margin: 0 auto 0; background-color: white',
});
return this;
},

23
src/commands/view/SelectPosition.js

@ -19,6 +19,7 @@ define(function() {
pfx: this.ppfx,
direction: 'a',
document: doc,
wmargin: 1,
nested: 1,
});
var offDim = this.getOffsetDim();
@ -79,6 +80,28 @@ define(function() {
this.canvasTool.style.left = '-' + this.bodyEl.scrollLeft + 'px';
},
/**
* Check if the pointer is near to the float component
* @param {number} index
* @param {string} method
* @param {Array<Array>} dims
* @return {Boolean}
* @private
* */
nearToFloat: function(index, method, dims) {
var i = index || 0;
var m = method || 'before';
var len = dims.length;
var isLast = len !== 0 && m == 'after' && i == len;
if(len !== 0 && (
(!isLast && !dims[i][4]) ||
(dims[i-1] && !dims[i-1][4]) ||
(isLast && !dims[i-1][4]) ) )
return 1;
else
return 0;
},
run: function() {
this.enable();

9
src/dom_components/main.js

@ -61,13 +61,12 @@ define(function(require) {
component.get('components').add(c.components);
var obj = {
this.c = c;
var componentView = new ComponentView({
model: component,
config: c,
};
this.c = c;
var componentView = new ComponentView(obj);
});
return {

1
src/dom_components/model/Components.js

@ -49,6 +49,7 @@ define([ 'backbone', 'require'],
},
add: function(models, opt){
console.log(models, opt);
if(typeof models === 'string'){
var parsed = this.editor.Parser.parseHtml(models);
models = parsed.html;

19
src/editor/model/Editor.js

@ -235,12 +235,9 @@ define([
this.Components = this.cmp;
if(this.stm.isAutosave()){
var md = this.cmp.getComponent();
this.updateComponents( md, null, { avoidStore : 1 });
// Call UndoManager here so it's possible to call it also for children inside
this.initUndoManager();
this.initChildrenComp(md);
this.initChildrenComp(this.cmp.getWrapper());
}
this.set('Components', this.cmp);
@ -548,14 +545,12 @@ define([
*/
initChildrenComp: function(model) {
var comps = model.get('components');
if(comps.length){
comps.each(function(md){
this.updateComponents(md, null, { avoidStore : 1 });
this.initChildrenComp(md);
if(this.um)
this.um.register(md);
}, this);
}
this.updateComponents(model, null, { avoidStore : 1 });
comps.each(function(md){
this.initChildrenComp(md);
if(this.um)
this.um.register(md);
}, this);
},
/**

9
src/utils/Sorter.js

@ -24,6 +24,7 @@ define(['backbone'],
this.relative = o.relative || 0;
this.plh = o.placer || '';
// Frame offset
this.wmargin = o.wmargin || 0;
this.offTop = o.offsetTop || 0;
this.offleft = o.offsetLeft || 0;
this.document = o.document || document;
@ -140,8 +141,8 @@ define(['backbone'],
// Cache all necessary positions
var eO = this.offset(this.el);
this.elT = this.offTop ? Math.abs(eO.top) : eO.top;
this.elL = this.offLeft ? Math.abs(eO.left): eO.left;
this.elT = this.wmargin ? Math.abs(eO.top) : eO.top;
this.elL = this.wmargin ? Math.abs(eO.left): eO.left;
this.rY = (e.pageY - this.elT) + this.el.scrollTop;
this.rX = (e.pageX - this.elL) + this.el.scrollLeft;
var dims = this.dimsFromTarget(e.target, this.rX, this.rY);
@ -274,8 +275,8 @@ define(['backbone'],
*/
getDim: function(el){
var o = this.offset(el);
var top = this.relative ? el.offsetTop : o.top - (this.offTop ? -1 : 1) * this.elT;
var left = this.relative ? el.offsetLeft : o.left - (this.offLeft ? -1 : 1) * this.elL;
var top = this.relative ? el.offsetTop : o.top - (this.wmargin ? -1 : 1) * this.elT;
var left = this.relative ? el.offsetLeft : o.left - (this.wmargin ? -1 : 1) * this.elL;
return [top, left, el.offsetHeight, el.offsetWidth];
},

Loading…
Cancel
Save