|
|
@ -6,14 +6,14 @@ import Selectors from 'selector_manager/model/Selectors'; |
|
|
import { replaceWith } from 'utils/dom'; |
|
|
import { replaceWith } from 'utils/dom'; |
|
|
import { setViewEl } from 'utils/mixins'; |
|
|
import { setViewEl } from 'utils/mixins'; |
|
|
|
|
|
|
|
|
export default Backbone.View.extend({ |
|
|
export default class ComponentView extends Backbone.View { |
|
|
className() { |
|
|
className() { |
|
|
return this.getClasses(); |
|
|
return this.getClasses(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
tagName() { |
|
|
tagName() { |
|
|
return this.model.get('tagName'); |
|
|
return this.model.get('tagName'); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
initialize(opt = {}) { |
|
|
initialize(opt = {}) { |
|
|
const model = this.model; |
|
|
const model = this.model; |
|
|
@ -50,13 +50,13 @@ export default Backbone.View.extend({ |
|
|
}; |
|
|
}; |
|
|
this.delegateEvents(); |
|
|
this.delegateEvents(); |
|
|
!modelOpt.temporary && this.init(this._clbObj()); |
|
|
!modelOpt.temporary && this.init(this._clbObj()); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
__isDraggable() { |
|
|
__isDraggable() { |
|
|
const { model, config } = this; |
|
|
const { model, config } = this; |
|
|
const { draggable } = model.attributes; |
|
|
const { draggable } = model.attributes; |
|
|
return config.draggableComponents && draggable; |
|
|
return config.draggableComponents && draggable; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
_clbObj() { |
|
|
_clbObj() { |
|
|
const { em, model, el } = this; |
|
|
const { em, model, el } = this; |
|
|
@ -65,27 +65,27 @@ export default Backbone.View.extend({ |
|
|
model, |
|
|
model, |
|
|
el, |
|
|
el, |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Initialize callback |
|
|
* Initialize callback |
|
|
*/ |
|
|
*/ |
|
|
init() {}, |
|
|
init() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Remove callback |
|
|
* Remove callback |
|
|
*/ |
|
|
*/ |
|
|
removed() {}, |
|
|
removed() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Callback executed when the `active` event is triggered on component |
|
|
* Callback executed when the `active` event is triggered on component |
|
|
*/ |
|
|
*/ |
|
|
onActive() {}, |
|
|
onActive() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Callback executed when the `disable` event is triggered on component |
|
|
* Callback executed when the `disable` event is triggered on component |
|
|
*/ |
|
|
*/ |
|
|
onDisable() {}, |
|
|
onDisable() {} |
|
|
|
|
|
|
|
|
remove() { |
|
|
remove() { |
|
|
Backbone.View.prototype.remove.apply(this, arguments); |
|
|
Backbone.View.prototype.remove.apply(this, arguments); |
|
|
@ -102,7 +102,7 @@ export default Backbone.View.extend({ |
|
|
$el.data({ model: '', collection: '', view: '' }); |
|
|
$el.data({ model: '', collection: '', view: '' }); |
|
|
// delete model.view; // Sorter relies on this property
|
|
|
// delete model.view; // Sorter relies on this property
|
|
|
return this; |
|
|
return this; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
handleDragStart(event) { |
|
|
handleDragStart(event) { |
|
|
if (!this.__isDraggable()) return false; |
|
|
if (!this.__isDraggable()) return false; |
|
|
@ -112,7 +112,7 @@ export default Backbone.View.extend({ |
|
|
target: this.model, |
|
|
target: this.model, |
|
|
event, |
|
|
event, |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
initClasses() { |
|
|
initClasses() { |
|
|
const { model } = this; |
|
|
const { model } = this; |
|
|
@ -125,7 +125,7 @@ export default Backbone.View.extend({ |
|
|
this.listenTo(classes, 'add remove change', this.updateClasses); |
|
|
this.listenTo(classes, 'add remove change', this.updateClasses); |
|
|
classes.length && this.importClasses(); |
|
|
classes.length && this.importClasses(); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
initComponents(opts = {}) { |
|
|
initComponents(opts = {}) { |
|
|
const { model, $el, childrenView } = this; |
|
|
const { model, $el, childrenView } = this; |
|
|
@ -140,7 +140,7 @@ export default Backbone.View.extend({ |
|
|
!opts.avoidRender && this.renderChildren(); |
|
|
!opts.avoidRender && this.renderChildren(); |
|
|
this.listenTo(...toListen); |
|
|
this.listenTo(...toListen); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle any property change |
|
|
* Handle any property change |
|
|
@ -155,7 +155,7 @@ export default Backbone.View.extend({ |
|
|
for (let prop in model.changed) { |
|
|
for (let prop in model.changed) { |
|
|
model.emitUpdate(prop); |
|
|
model.emitUpdate(prop); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Import, if possible, classes inside main container |
|
|
* Import, if possible, classes inside main container |
|
|
@ -169,7 +169,7 @@ export default Backbone.View.extend({ |
|
|
clm.add(m.get('name')); |
|
|
clm.add(m.get('name')); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update item on status change |
|
|
* Update item on status change |
|
|
@ -212,7 +212,7 @@ export default Backbone.View.extend({ |
|
|
|
|
|
|
|
|
cls = cls.trim(); |
|
|
cls = cls.trim(); |
|
|
cls && el.setAttribute('class', cls); |
|
|
cls && el.setAttribute('class', cls); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update highlight attribute |
|
|
* Update highlight attribute |
|
|
@ -223,7 +223,7 @@ export default Backbone.View.extend({ |
|
|
const isTextable = model.get('textable'); |
|
|
const isTextable = model.get('textable'); |
|
|
const hl = model.get('highlightable') && (isTextable || !model.isChildOf('text')); |
|
|
const hl = model.get('highlightable') && (isTextable || !model.isChildOf('text')); |
|
|
this.setAttribute('data-gjs-highlightable', hl ? true : ''); |
|
|
this.setAttribute('data-gjs-highlightable', hl ? true : ''); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update style attribute |
|
|
* Update style attribute |
|
|
@ -238,7 +238,7 @@ export default Backbone.View.extend({ |
|
|
} else { |
|
|
} else { |
|
|
this.setAttribute('style', model.styleToString(opts)); |
|
|
this.setAttribute('style', model.styleToString(opts)); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update classe attribute |
|
|
* Update classe attribute |
|
|
@ -251,7 +251,7 @@ export default Backbone.View.extend({ |
|
|
// Regenerate status class
|
|
|
// Regenerate status class
|
|
|
this.updateStatus(); |
|
|
this.updateStatus(); |
|
|
this.onAttrUpdate(); |
|
|
this.onAttrUpdate(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update single attribute |
|
|
* Update single attribute |
|
|
@ -261,7 +261,7 @@ export default Backbone.View.extend({ |
|
|
setAttribute(name, value) { |
|
|
setAttribute(name, value) { |
|
|
const el = this.$el; |
|
|
const el = this.$el; |
|
|
value ? el.attr(name, value) : el.removeAttr(name); |
|
|
value ? el.attr(name, value) : el.removeAttr(name); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Get classes from attributes. |
|
|
* Get classes from attributes. |
|
|
@ -272,7 +272,7 @@ export default Backbone.View.extend({ |
|
|
* */ |
|
|
* */ |
|
|
getClasses() { |
|
|
getClasses() { |
|
|
return this.model.getClasses().join(' '); |
|
|
return this.model.getClasses().join(' '); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update attributes |
|
|
* Update attributes |
|
|
@ -304,7 +304,7 @@ export default Backbone.View.extend({ |
|
|
keys(attr).forEach(key => attr[key] === false && delete attr[key]); |
|
|
keys(attr).forEach(key => attr[key] === false && delete attr[key]); |
|
|
|
|
|
|
|
|
$el.attr(attr); |
|
|
$el.attr(attr); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update component content |
|
|
* Update component content |
|
|
@ -314,7 +314,7 @@ export default Backbone.View.extend({ |
|
|
const content = this.model.get('content'); |
|
|
const content = this.model.get('content'); |
|
|
const hasComps = this.model.components().length; |
|
|
const hasComps = this.model.components().length; |
|
|
this.getChildrenContainer().innerHTML = hasComps ? '' : content; |
|
|
this.getChildrenContainer().innerHTML = hasComps ? '' : content; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Prevent default helper |
|
|
* Prevent default helper |
|
|
@ -323,7 +323,7 @@ export default Backbone.View.extend({ |
|
|
*/ |
|
|
*/ |
|
|
prevDef(e) { |
|
|
prevDef(e) { |
|
|
e.preventDefault(); |
|
|
e.preventDefault(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Render component's script |
|
|
* Render component's script |
|
|
@ -333,7 +333,7 @@ export default Backbone.View.extend({ |
|
|
const { model, em } = this; |
|
|
const { model, em } = this; |
|
|
if (!model.get('script')) return; |
|
|
if (!model.get('script')) return; |
|
|
em && em.get('Canvas').getCanvasView().updateScript(this); |
|
|
em && em.get('Canvas').getCanvasView().updateScript(this); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Return children container |
|
|
* Return children container |
|
|
@ -369,7 +369,7 @@ export default Backbone.View.extend({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return container; |
|
|
return container; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This returns rect informations not affected by the canvas zoom. |
|
|
* This returns rect informations not affected by the canvas zoom. |
|
|
@ -399,7 +399,7 @@ export default Backbone.View.extend({ |
|
|
assignRect(target); |
|
|
assignRect(target); |
|
|
|
|
|
|
|
|
return rect; |
|
|
return rect; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
isInViewport({ rect } = {}) { |
|
|
isInViewport({ rect } = {}) { |
|
|
const { el } = this; |
|
|
const { el } = this; |
|
|
@ -415,7 +415,7 @@ export default Backbone.View.extend({ |
|
|
top <= frame.scrollBottom && |
|
|
top <= frame.scrollBottom && |
|
|
left <= frameElement.offsetWidth + body.scrollLeft |
|
|
left <= frameElement.offsetWidth + body.scrollLeft |
|
|
); |
|
|
); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
scrollIntoView(opts = {}) { |
|
|
scrollIntoView(opts = {}) { |
|
|
const rect = this.getOffsetRect(); |
|
|
const rect = this.getOffsetRect(); |
|
|
@ -435,7 +435,7 @@ export default Backbone.View.extend({ |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Recreate the element of the view |
|
|
* Recreate the element of the view |
|
|
@ -447,18 +447,18 @@ export default Backbone.View.extend({ |
|
|
this._setData(); |
|
|
this._setData(); |
|
|
replaceWith(el, this.el); |
|
|
replaceWith(el, this.el); |
|
|
this.render(); |
|
|
this.render(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
_setData() { |
|
|
_setData() { |
|
|
const { model } = this; |
|
|
const { model } = this; |
|
|
const collection = model.components(); |
|
|
const collection = model.components(); |
|
|
const view = this; |
|
|
const view = this; |
|
|
this.$el.data({ model, collection, view }); |
|
|
this.$el.data({ model, collection, view }); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
_getFrame() { |
|
|
_getFrame() { |
|
|
return this.config.frameView; |
|
|
return this.config.frameView; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Render children components |
|
|
* Render children components |
|
|
@ -482,14 +482,14 @@ export default Backbone.View.extend({ |
|
|
for (var i = 0, len = childNodes.length; i < len; i++) { |
|
|
for (var i = 0, len = childNodes.length; i < len; i++) { |
|
|
container.appendChild(childNodes.shift()); |
|
|
container.appendChild(childNodes.shift()); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
renderAttributes() { |
|
|
renderAttributes() { |
|
|
this.updateAttributes(); |
|
|
this.updateAttributes(); |
|
|
this.updateClasses(); |
|
|
this.updateClasses(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
onAttrUpdate() {}, |
|
|
onAttrUpdate() {} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
this.renderAttributes(); |
|
|
this.renderAttributes(); |
|
|
@ -500,13 +500,13 @@ export default Backbone.View.extend({ |
|
|
this.postRender(); |
|
|
this.postRender(); |
|
|
|
|
|
|
|
|
return this; |
|
|
return this; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
postRender() { |
|
|
postRender() { |
|
|
if (!this.modelOpt.temporary) { |
|
|
if (!this.modelOpt.temporary) { |
|
|
this.onRender(this._clbObj()); |
|
|
this.onRender(this._clbObj()); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
onRender() {}, |
|
|
onRender() {} |
|
|
}); |
|
|
} |
|
|
|