Browse Source

First integration of scripts inside Components

pull/67/head
Artur Arseniev 10 years ago
parent
commit
9cd774f9d8
  1. 293
      src/canvas/view/CanvasView.js
  2. 37
      src/demo.js
  3. 3
      src/dom_components/model/Component.js
  4. 569
      src/dom_components/view/ComponentView.js

293
src/canvas/view/CanvasView.js

@ -1,22 +1,22 @@
define(['backbone','./FrameView'], define(['backbone','./FrameView'],
function(Backbone, FrameView) { function(Backbone, FrameView) {
/** /**
* @class CanvasView * @class CanvasView
* */ * */
return Backbone.View.extend({ return Backbone.View.extend({
initialize: function(o) { initialize: function(o) {
_.bindAll(this, 'renderBody', 'onFrameScroll', 'clearOff'); _.bindAll(this, 'renderBody', 'onFrameScroll', 'clearOff');
this.config = o.config || {}; this.config = o.config || {};
this.em = this.config.em || {}; this.em = this.config.em || {};
this.ppfx = this.config.pStylePrefix || ''; this.ppfx = this.config.pStylePrefix || '';
this.className = this.config.stylePrefix + 'canvas'; this.className = this.config.stylePrefix + 'canvas';
this.listenTo(this.em, 'change:canvasOffset', this.clearOff); this.listenTo(this.em, 'change:canvasOffset', this.clearOff);
this.frame = new FrameView({ this.frame = new FrameView({
model: this.model.get('frame'), model: this.model.get('frame'),
config: this.config config: this.config
}); });
}, },
/** /**
* Update tools position * Update tools position
@ -27,36 +27,38 @@ function(Backbone, FrameView) {
var body = this.frame.el.contentDocument.body; var body = this.frame.el.contentDocument.body;
this.toolsEl.style.top = '-' + body.scrollTop + u; this.toolsEl.style.top = '-' + body.scrollTop + u;
this.toolsEl.style.left = '-' + body.scrollLeft + u; this.toolsEl.style.left = '-' + body.scrollLeft + u;
this.em.trigger('canvasScroll'); this.em.trigger('canvasScroll');
}, },
/** /**
* Render inside frame's body * Render inside frame's body
* @private * @private
*/ */
renderBody: function(){ renderBody: function(){
var wrap = this.model.get('frame').get('wrapper'); var wrap = this.model.get('frame').get('wrapper');
if(wrap){ var em = this.config.em;
var ppfx = this.ppfx; if(wrap) {
var ppfx = this.ppfx;
var body = this.frame.$el.contents().find('body'); var body = this.frame.$el.contents().find('body');
var cssc = this.config.em.get('CssComposer'); var cssc = em.get('CssComposer');
var conf = this.config.em.get('Config'); var conf = em.get('Config');
body.append(wrap.render()).append(cssc.render()); body.append(wrap.render()).append(cssc.render());
var protCss = conf.protectedCss; var protCss = conf.protectedCss;
var frameCss = '.' + ppfx + 'dashed :not([contenteditable]) > *{outline: 1px dashed rgba(170,170,170,0.7); outline-offset: -2px}' + var frameCss = '.' + ppfx + 'dashed :not([contenteditable]) > *{outline: 1px dashed rgba(170,170,170,0.7); outline-offset: -2px}' +
'.' + ppfx + 'comp-selected{outline: 3px solid #3b97e3 !important}' + '.' + ppfx + 'comp-selected{outline: 3px solid #3b97e3 !important}' +
'.' + ppfx + 'no-select{user-select: none; -webkit-user-select:none; -moz-user-select: none}'+ '.' + ppfx + 'no-select{user-select: none; -webkit-user-select:none; -moz-user-select: none}'+
'.' + ppfx + 'freezed{opacity: 0.5; pointer-events: none}' + '.' + ppfx + 'freezed{opacity: 0.5; pointer-events: none}' +
'.' + ppfx + 'no-pointer{pointer-events: none}' + '.' + ppfx + 'no-pointer{pointer-events: none}' +
'.' + ppfx + 'plh-image{background:#f5f5f5; border:none; height:50px; width:50px; display:block; outline:3px solid #ffca6f; cursor:pointer}' + '.' + ppfx + 'plh-image{background:#f5f5f5; border:none; height:50px; width:50px; display:block; outline:3px solid #ffca6f; cursor:pointer}' +
'.' + ppfx + 'grabbing{cursor: grabbing; cursor: -webkit-grabbing}' + '.' + ppfx + 'grabbing{cursor: grabbing; cursor: -webkit-grabbing}' +
'* ::-webkit-scrollbar-track {background: rgba(0, 0, 0, 0.1)}' + '* ::-webkit-scrollbar-track {background: rgba(0, 0, 0, 0.1)}' +
'* ::-webkit-scrollbar-thumb {background: rgba(255, 255, 255, 0.2)}' + '* ::-webkit-scrollbar-thumb {background: rgba(255, 255, 255, 0.2)}' +
'* ::-webkit-scrollbar {width: 10px}' + '* ::-webkit-scrollbar {width: 10px}' +
(conf.canvasCss || ''); (conf.canvasCss || '');
if(protCss) if(protCss)
body.append('<style>' + frameCss + protCss + '</style>'); body.append('<style>' + frameCss + protCss + '</style>');
this.config.em.trigger('loaded'); body.append(this.getJsContainer());
em.trigger('loaded');
this.frame.el.contentWindow.onscroll = this.onFrameScroll; this.frame.el.contentWindow.onscroll = this.onFrameScroll;
this.frame.udpateOffset(); this.frame.udpateOffset();
@ -71,7 +73,7 @@ function(Backbone, FrameView) {
doc.dispatchEvent(new KeyboardEvent(e.type, e)); doc.dispatchEvent(new KeyboardEvent(e.type, e));
}); });
} }
}, },
/** /**
* Get the offset of the element * Get the offset of the element
@ -87,111 +89,146 @@ function(Backbone, FrameView) {
}; };
}, },
/** /**
* Cleare cached offsets * Cleare cached offsets
* @private * @private
*/ */
clearOff: function(){ clearOff: function(){
this.frmOff = null; this.frmOff = null;
this.cvsOff = null; this.cvsOff = null;
}, },
/** /**
* Return frame offset * Return frame offset
* @return {Object} * @return {Object}
* @private * @private
*/ */
getFrameOffset: function () { getFrameOffset: function () {
if(!this.frmOff) if(!this.frmOff)
this.frmOff = this.offset(this.frame.el); this.frmOff = this.offset(this.frame.el);
return this.frmOff; return this.frmOff;
}, },
/** /**
* Return canvas offset * Return canvas offset
* @return {Object} * @return {Object}
* @private * @private
*/ */
getCanvasOffset: function () { getCanvasOffset: function () {
if(!this.cvsOff) if(!this.cvsOff)
this.cvsOff = this.offset(this.el); this.cvsOff = this.offset(this.el);
return this.cvsOff; return this.cvsOff;
}, },
/** /**
* Returns element's data info * Returns element's data info
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @return {Object}
* @private * @private
*/ */
getElementPos: function(el) { getElementPos: function(el) {
var frmOff = this.getFrameOffset(); var frmOff = this.getFrameOffset();
var cvsOff = this.getCanvasOffset(); var cvsOff = this.getCanvasOffset();
var eo = this.offset(el); var eo = this.offset(el);
var top = eo.top + frmOff.top - cvsOff.top; var top = eo.top + frmOff.top - cvsOff.top;
var left = eo.left + frmOff.left - cvsOff.left; var left = eo.left + frmOff.left - cvsOff.left;
return { return {
top: top, top: top,
left: left, left: left,
height: el.offsetHeight, height: el.offsetHeight,
width: el.offsetWidth width: el.offsetWidth
}; };
}, },
/** /**
* Returns position data of the canvas element * Returns position data of the canvas element
* @return {Object} obj Position object * @return {Object} obj Position object
*/ * @private
getPosition: function() { */
var bEl = this.frame.el.contentDocument.body; getPosition: function() {
var fo = this.getFrameOffset(); var bEl = this.frame.el.contentDocument.body;
var co = this.getCanvasOffset(); var fo = this.getFrameOffset();
return { var co = this.getCanvasOffset();
top: fo.top + bEl.scrollTop - co.top, return {
left: fo.left + bEl.scrollLeft - co.left top: fo.top + bEl.scrollTop - co.top,
}; left: fo.left + bEl.scrollLeft - co.left
}, };
},
render: function() { /**
this.wrapper = this.model.get('wrapper'); * Update javascript of a specific component passed by its View
* @param {View} view Component's View
if(this.wrapper && typeof this.wrapper.render == 'function'){ * @private
this.model.get('frame').set('wrapper', this.wrapper); */
this.$el.append(this.frame.render().el); updateScript: function(view) {
var frame = this.frame; var scriptsContainer = this.getJsContainer();
frame.el.onload = this.renderBody;
} if(!view.scriptContainer) {
var ppfx = this.ppfx; view.scriptContainer = $('<div>');
toolsEl = $('<div>', { id: ppfx + 'tools' }).get(0); scriptsContainer.append(view.scriptContainer.get(0));
this.hlEl = $('<div>', { class: ppfx + 'highlighter' }).get(0); }
this.badgeEl = $('<div>', {class: ppfx + 'badge'}).get(0);
this.placerEl = $('<div>', {class: ppfx + 'placeholder'}).get(0); var id = view.model.cid;
this.placerIntEl = $('<div>', {class: ppfx + 'placeholder-int'}).get(0); var script = view.model.get('script');
this.ghostEl = $('<div>', {class: ppfx + 'ghost'}).get(0);
this.toolbarEl = $('<div>', {class: ppfx + 'toolbar'}).get(0); view.el.id = id;
this.resizerEl = $('<div>', {class: ppfx + 'resizer'}).get(0); view.scriptContainer.html('');
view.scriptContainer.append('<script>'+
'var item = document.getElementById("'+id+'");'+
'(function(){' + script + '}.bind(item))()</script>');
},
/**
* Get javascript container
* @private
*/
getJsContainer: function () {
if (!this.jsContainer) {
this.jsContainer = $('<div>', {class: this.ppfx + 'js-cont'}).get(0);
}
return this.jsContainer;
},
render: function() {
this.wrapper = this.model.get('wrapper');
if(this.wrapper && typeof this.wrapper.render == 'function'){
this.model.get('frame').set('wrapper', this.wrapper);
this.$el.append(this.frame.render().el);
var frame = this.frame;
frame.el.onload = this.renderBody;
}
var ppfx = this.ppfx;
toolsEl = $('<div>', { id: ppfx + 'tools' }).get(0);
this.hlEl = $('<div>', { class: ppfx + 'highlighter' }).get(0);
this.badgeEl = $('<div>', {class: ppfx + 'badge'}).get(0);
this.placerEl = $('<div>', {class: ppfx + 'placeholder'}).get(0);
this.placerIntEl = $('<div>', {class: ppfx + 'placeholder-int'}).get(0);
this.ghostEl = $('<div>', {class: ppfx + 'ghost'}).get(0);
this.toolbarEl = $('<div>', {class: ppfx + 'toolbar'}).get(0);
this.resizerEl = $('<div>', {class: ppfx + 'resizer'}).get(0);
this.offsetEl = $('<div>', {class: ppfx + 'offset-v'}).get(0); this.offsetEl = $('<div>', {class: ppfx + 'offset-v'}).get(0);
this.fixedOffsetEl = $('<div>', {class: ppfx + 'offset-fixed-v'}).get(0); this.fixedOffsetEl = $('<div>', {class: ppfx + 'offset-fixed-v'}).get(0);
this.placerEl.appendChild(this.placerIntEl); this.placerEl.appendChild(this.placerIntEl);
toolsEl.appendChild(this.hlEl); toolsEl.appendChild(this.hlEl);
toolsEl.appendChild(this.badgeEl); toolsEl.appendChild(this.badgeEl);
toolsEl.appendChild(this.placerEl); toolsEl.appendChild(this.placerEl);
toolsEl.appendChild(this.ghostEl); toolsEl.appendChild(this.ghostEl);
toolsEl.appendChild(this.toolbarEl); toolsEl.appendChild(this.toolbarEl);
toolsEl.appendChild(this.resizerEl); toolsEl.appendChild(this.resizerEl);
toolsEl.appendChild(this.offsetEl); toolsEl.appendChild(this.offsetEl);
toolsEl.appendChild(this.fixedOffsetEl); toolsEl.appendChild(this.fixedOffsetEl);
this.$el.append(toolsEl); this.$el.append(toolsEl);
var rte = this.em.get('rte'); var rte = this.em.get('rte');
if(rte) if(rte)
toolsEl.appendChild(rte.render()); toolsEl.appendChild(rte.render());
this.toolsEl = toolsEl; this.toolsEl = toolsEl;
this.$el.attr({class: this.className}); this.$el.attr({class: this.className});
return this; return this;
}, },
}); });
}); });

37
src/demo.js

@ -12,9 +12,40 @@ require(['config/require-config'], function() {
noticeOnUnload: 0, noticeOnUnload: 0,
container : '#gjs', container : '#gjs',
height: '100%', height: '100%',
fromElement: true, //fromElement: true,
/*
components: [{ components: [{
script: 'this.innerHTML= "test1";',
style: {
background: 'red',
width:'500px',
height:'100px',
margin: '50px auto',
}
},{
script: 'this.innerHTML= "test1";',
style: {
background: 'blue',
width:'500px',
height:'100px',
margin: '50px auto',
}
},{
script: 'this.innerHTML= "test2";',
style: {
background: 'green',
width:'500px',
height:'100px',
margin: '50px auto',
}
},{
style: {
background: 'yellow',
width:'500px',
height:'100px',
margin: '50px auto',
}
},{
type: 'text', type: 'text',
style:{ style:{
width:'100px', width:'100px',
@ -35,7 +66,7 @@ require(['config/require-config'], function() {
type: 'textnode', type: 'textnode',
content: " More text node --- ", content: " More text node --- ",
}], }],
}],*/ }],
storageManager:{ storageManager:{
autoload: 0, autoload: 0,

3
src/dom_components/model/Component.js

@ -59,6 +59,9 @@ define(['backbone','./Components', 'SelectorManager/model/Selectors', 'TraitMana
// Array of classes // Array of classes
classes: '', classes: '',
// Component's javascript
script: '',
// Traits // Traits
traits: ['id', 'title'], traits: ['id', 'title'],

569
src/dom_components/view/ComponentView.js

@ -1,280 +1,301 @@
define(['backbone', './ComponentsView'], define(['backbone', './ComponentsView'],
function (Backbone, ComponentsView) { function (Backbone, ComponentsView) {
return Backbone.View.extend({ return Backbone.View.extend({
events: { events: {
'click': 'initResize', 'click': 'initResize',
}, },
className : function(){ className : function(){
return this.getClasses(); return this.getClasses();
}, },
tagName: function(){ tagName: function(){
return this.model.get('tagName'); return this.model.get('tagName');
}, },
initialize: function(opt){ initialize: function(opt) {
this.opts = opt || {}; this.opts = opt || {};
this.config = opt.config || {}; this.config = this.opts.config || {};
this.pfx = this.config.stylePrefix || ''; this.em = this.config.em || '';
this.ppfx = this.config.pStylePrefix || ''; this.pfx = this.config.stylePrefix || '';
this.components = this.model.get('components'); this.ppfx = this.config.pStylePrefix || '';
this.attr = this.model.get("attributes"); this.components = this.model.get('components');
this.classe = this.attr.class || []; this.attr = this.model.get("attributes");
this.listenTo(this.model, 'destroy remove', this.remove); this.classe = this.attr.class || [];
this.listenTo(this.model, 'change:style', this.updateStyle); this.listenTo(this.model, 'destroy remove', this.remove);
this.listenTo(this.model, 'change:attributes', this.updateAttributes); this.listenTo(this.model, 'change:style', this.updateStyle);
this.listenTo(this.model, 'change:status', this.updateStatus); this.listenTo(this.model, 'change:attributes', this.updateAttributes);
this.listenTo(this.model, 'change:state', this.updateState); this.listenTo(this.model, 'change:status', this.updateStatus);
this.listenTo(this.model.get('classes'), 'add remove change', this.updateClasses); this.listenTo(this.model, 'change:state', this.updateState);
this.$el.data('model', this.model); this.listenTo(this.model, 'change:script', this.render);
this.model.view = this; this.listenTo(this.model.get('classes'), 'add remove change', this.updateClasses);
this.$el.data("collection", this.components); this.$el.data('model', this.model);
this.model.view = this;
if(this.model.get('classes').length) this.$el.data("collection", this.components);
this.importClasses();
if(this.model.get('classes').length)
this.init(); this.importClasses();
},
this.init();
/** },
/**
* Initialize callback * Initialize callback
*/ */
init: function () {}, init: function () {},
/** /**
* Import, if possible, classes inside main container * Import, if possible, classes inside main container
* @private * @private
* */ * */
importClasses: function(){ importClasses: function(){
var clm = this.config.em.get('SelectorManager'); var clm = this.config.em.get('SelectorManager');
if(clm){ if(clm){
this.model.get('classes').each(function(m){ this.model.get('classes').each(function(m){
clm.add(m.get('name')); clm.add(m.get('name'));
}); });
} }
}, },
/** /**
* Fires on state update. If the state is not empty will add a helper class * Fires on state update. If the state is not empty will add a helper class
* @param {Event} e * @param {Event} e
* @private * @private
* */ * */
updateState: function(e){ updateState: function(e){
var cl = 'hc-state'; var cl = 'hc-state';
var state = this.model.get('state'); var state = this.model.get('state');
if(state){ if(state){
this.$el.addClass(cl); this.$el.addClass(cl);
}else{ }else{
this.$el.removeClass(cl); this.$el.removeClass(cl);
} }
}, },
/** /**
* Update item on status change * Update item on status change
* @param {Event} e * @param {Event} e
* @private * @private
* */ * */
updateStatus: function(e){ updateStatus: function(e){
var s = this.model.get('status'), var s = this.model.get('status'),
pfx = this.pfx; pfx = this.pfx;
switch(s) { switch(s) {
case 'selected': case 'selected':
this.$el.addClass(pfx + 'selected'); this.$el.addClass(pfx + 'selected');
break; break;
case 'moving': case 'moving':
break; break;
default: default:
this.$el.removeClass(pfx + 'selected'); this.$el.removeClass(pfx + 'selected');
} }
}, },
/** /**
* Get classes from attributes. * Get classes from attributes.
* This method is called before initialize * This method is called before initialize
* *
* @return {Array}|null * @return {Array}|null
* @private * @private
* */ * */
getClasses: function(){ getClasses: function(){
var attr = this.model.get("attributes"), var attr = this.model.get("attributes"),
classes = attr['class'] || []; classes = attr['class'] || [];
if(classes.length){ if(classes.length){
return classes.join(" "); return classes.join(" ");
}else }else
return null; return null;
}, },
/** /**
* Update attributes * Update attributes
* @private * @private
* */ * */
updateAttributes: function(){ updateAttributes: function(){
var attributes = {}, var attributes = {},
attr = this.model.get("attributes"); attr = this.model.get("attributes");
for(var key in attr) { for(var key in attr) {
if(attr.hasOwnProperty(key)) if(attr.hasOwnProperty(key))
attributes[key] = attr[key]; attributes[key] = attr[key];
} }
// Update src // Update src
if(this.model.get("src")) if(this.model.get("src"))
attributes.src = this.model.get("src"); attributes.src = this.model.get("src");
var styleStr = this.getStyleString(); var styleStr = this.getStyleString();
if(styleStr) if(styleStr)
attributes.style = styleStr; attributes.style = styleStr;
this.$el.attr(attributes); this.$el.attr(attributes);
}, },
/** /**
* Update style attribute * Update style attribute
* @private * @private
* */ * */
updateStyle: function(){ updateStyle: function(){
this.$el.attr('style', this.getStyleString()); this.$el.attr('style', this.getStyleString());
}, },
/** /**
* Return style string * Return style string
* @return {string} * @return {string}
* @private * @private
* */ * */
getStyleString: function(){ getStyleString: function(){
var style = ''; var style = '';
this.style = this.model.get('style'); this.style = this.model.get('style');
for(var key in this.style) { for(var key in this.style) {
if(this.style.hasOwnProperty(key)) if(this.style.hasOwnProperty(key))
style += key + ':' + this.style[key] + ';'; style += key + ':' + this.style[key] + ';';
} }
return style; return style;
}, },
/** /**
* Update classe attribute * Update classe attribute
* @private * @private
* */ * */
updateClasses: function(){ updateClasses: function(){
var str = ''; var str = '';
this.model.get('classes').each(function(model){ this.model.get('classes').each(function(model){
str += model.get('name') + ' '; str += model.get('name') + ' ';
}); });
str = str.trim(); str = str.trim();
if(str) if(str)
this.$el.attr('class', str); this.$el.attr('class', str);
else else
this.$el.removeAttr('class'); this.$el.removeAttr('class');
// Regenerate status class // Regenerate status class
this.updateStatus(); this.updateStatus();
}, },
/** /**
* Reply to event call * Reply to event call
* @param object Event that generated the request * @param object Event that generated the request
* @private * @private
* */ * */
eventCall: function(event){ eventCall: function(event){
event.viewResponse = this; event.viewResponse = this;
}, },
/** /**
* Init component for resizing * Init component for resizing
*/ */
initResize: function () { initResize: function () {
var em = this.opts.config.em; var em = this.opts.config.em;
var editor = em ? em.get('Editor') : ''; var editor = em ? em.get('Editor') : '';
var config = em ? em.get('Config') : ''; var config = em ? em.get('Config') : '';
var pfx = config.stylePrefix || ''; var pfx = config.stylePrefix || '';
var attrName = 'data-' + pfx + 'handler'; var attrName = 'data-' + pfx + 'handler';
var resizeClass = pfx + 'resizing'; var resizeClass = pfx + 'resizing';
var model = this.model; var model = this.model;
var modelToStyle; var modelToStyle;
var toggleBodyClass = function(method, e, opts) { var toggleBodyClass = function(method, e, opts) {
var handlerAttr = e.target.getAttribute(attrName); var handlerAttr = e.target.getAttribute(attrName);
var resizeHndClass = pfx + 'resizing-' + handlerAttr; var resizeHndClass = pfx + 'resizing-' + handlerAttr;
var classToAdd = resizeClass;// + ' ' +resizeHndClass; var classToAdd = resizeClass;// + ' ' +resizeHndClass;
if (opts.docs) { if (opts.docs) {
opts.docs.find('body')[method](classToAdd); opts.docs.find('body')[method](classToAdd);
} }
}; };
if(editor && this.model.get('resizable')) { if(editor && this.model.get('resizable')) {
editor.runCommand('resize', { editor.runCommand('resize', {
el: this.el, el: this.el,
options: { options: {
onStart: function (e, opts) { onStart: function (e, opts) {
toggleBodyClass('addClass', e, opts); toggleBodyClass('addClass', e, opts);
modelToStyle = em.get('StyleManager').getModelToStyle(model); modelToStyle = em.get('StyleManager').getModelToStyle(model);
}, },
// Update all positioned elements (eg. component toolbar) // Update all positioned elements (eg. component toolbar)
onMove: function () { onMove: function () {
editor.trigger('change:canvasOffset'); editor.trigger('change:canvasOffset');
}, },
onEnd: function (e, opts) { onEnd: function (e, opts) {
toggleBodyClass('removeClass', e, opts); toggleBodyClass('removeClass', e, opts);
editor.trigger('change:canvasOffset'); editor.trigger('change:canvasOffset');
}, },
updateTarget: function(el, rect, store) { updateTarget: function(el, rect, store) {
if (!modelToStyle) { if (!modelToStyle) {
return; return;
} }
var unit = 'px'; var unit = 'px';
var style = _.clone(modelToStyle.get('style')); var style = _.clone(modelToStyle.get('style'));
var width = rect.w + (store ? 1 : 0); var width = rect.w + (store ? 1 : 0);
style.width = width + unit; style.width = width + unit;
style.height = rect.h + unit; style.height = rect.h + unit;
modelToStyle.set('style', style, {avoidStore: 1}); modelToStyle.set('style', style, {avoidStore: 1});
em.trigger('targetStyleUpdated'); em.trigger('targetStyleUpdated');
// This trick will trigger the Undo Manager. To trigger "change:style" // This trick will trigger the Undo Manager. To trigger "change:style"
// on the Model you need to provide a new object and after that // on the Model you need to provide a new object and after that
// Undo Manager will trigger only if values are different (this is why // Undo Manager will trigger only if values are different (this is why
// above I've added + 1 to width if store required) // above I've added + 1 to width if store required)
if(store) { if(store) {
var style3 = _.clone(style); var style3 = _.clone(style);
style3.width = (width - 1) + unit; style3.width = (width - 1) + unit;
modelToStyle.set('style', style3); modelToStyle.set('style', style3);
} }
} }
} }
}); });
} }
}, },
/** /**
* Prevent default helper * Prevent default helper
* @param {Event} e * @param {Event} e
* @private * @private
*/ */
prevDef: function (e) { prevDef: function (e) {
e.preventDefault(); e.preventDefault();
}, },
render: function() { /**
this.updateAttributes(); * Render component's script
this.updateClasses(); * @private
this.$el.html(this.model.get('content')); */
var view = new ComponentsView({ updateScript: function () {
collection: this.model.get('components'), var em = this.em;
config: this.config, if(em) {
defaultTypes: this.opts.defaultTypes, var canvas = em.get('Canvas');
componentTypes: this.opts.componentTypes, canvas.getCanvasView().updateScript(this);
}); }
},
// With childNodes lets avoid wrapping 'div'
this.$el.append(view.render(this.$el).el.childNodes); render: function() {
return this; var model = this.model;
}, this.updateAttributes();
this.updateClasses();
}); this.$el.html(this.model.get('content'));
var view = new ComponentsView({
collection: this.model.get('components'),
config: this.config,
defaultTypes: this.opts.defaultTypes,
componentTypes: this.opts.componentTypes,
});
// With childNodes lets avoid wrapping 'div'
this.$el.append(view.render(this.$el).el.childNodes);
// Render script
if(model.get('script')) {
this.updateScript();
}
return this;
},
});
}); });

Loading…
Cancel
Save