Browse Source

Convert ComponentViews to classes

pull/4312/head
Alex 4 years ago
parent
commit
c21b3a568e
  1. 10
      src/dom_components/model/ToolbarButton.js
  2. 4
      src/dom_components/view/ComponentCommentView.js
  3. 14
      src/dom_components/view/ComponentFrameView.js
  4. 26
      src/dom_components/view/ComponentImageView.js
  5. 6
      src/dom_components/view/ComponentLabelView.js
  6. 4
      src/dom_components/view/ComponentLinkView.js
  7. 15
      src/dom_components/view/ComponentMapView.js
  8. 8
      src/dom_components/view/ComponentScriptView.js
  9. 6
      src/dom_components/view/ComponentSvgView.js
  10. 2
      src/dom_components/view/ComponentTableBodyView.js
  11. 26
      src/dom_components/view/ComponentTextNodeView.js
  12. 32
      src/dom_components/view/ComponentTextView.js
  13. 38
      src/dom_components/view/ComponentVideoView.js
  14. 80
      src/dom_components/view/ComponentView.js
  15. 16
      src/dom_components/view/ComponentsView.js
  16. 16
      src/dom_components/view/ToolbarButtonView.js

10
src/dom_components/model/ToolbarButton.js

@ -1,8 +1,8 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
export default Backbone.Model.extend({ export default class ToolbarButton extends Backbone.Model {
defaults: { defaults = {
command: '', command: '',
attributes: {} attributes: {},
} };
}); }

4
src/dom_components/view/ComponentCommentView.js

@ -1,7 +1,7 @@
import ComponentView from './ComponentTextNodeView'; import ComponentView from './ComponentTextNodeView';
export default ComponentView.extend({ export default class ComponentCommentView extends ComponentView {
_createElement() { _createElement() {
return document.createComment(this.model.get('content')); return document.createComment(this.model.get('content'));
} }
}); }

14
src/dom_components/view/ComponentFrameView.js

@ -1,31 +1,31 @@
import ComponentView from './ComponentView'; import ComponentView from './ComponentView';
import { createEl, find, attrUp } from 'utils/dom'; import { createEl, find, attrUp } from 'utils/dom';
export default ComponentView.extend({ export default class ComponentFrameView extends ComponentView.extend {
tagName: 'div', tagName = 'div';
initialize(...args) { initialize(...args) {
ComponentView.prototype.initialize.apply(this, args); ComponentView.prototype.initialize.apply(this, args);
this.listenTo(this.model, 'change:attributes:src', this.updateSrc); this.listenTo(this.model, 'change:attributes:src', this.updateSrc);
}, }
updateSrc() { updateSrc() {
const frame = find(this.el, 'iframe')[0]; const frame = find(this.el, 'iframe')[0];
frame && attrUp(frame, { src: this.__getSrc() }); frame && attrUp(frame, { src: this.__getSrc() });
}, }
render(...args) { render(...args) {
ComponentView.prototype.render.apply(this, args); ComponentView.prototype.render.apply(this, args);
const frame = createEl('iframe', { const frame = createEl('iframe', {
class: `${this.ppfx}no-pointer`, class: `${this.ppfx}no-pointer`,
style: 'width: 100%; height: 100%; border: none', style: 'width: 100%; height: 100%; border: none',
src: this.__getSrc() src: this.__getSrc(),
}); });
this.el.appendChild(frame); this.el.appendChild(frame);
return this; return this;
}, }
__getSrc() { __getSrc() {
return this.model.getAttributes().src || ''; return this.model.getAttributes().src || '';
} }
}); }

26
src/dom_components/view/ComponentImageView.js

@ -1,23 +1,23 @@
import { isString } from 'underscore'; import { isString } from 'underscore';
import ComponentView from './ComponentView'; import ComponentView from './ComponentView';
export default ComponentView.extend({ export default class ComponentImageView extends ComponentView {
tagName: 'img', tagName = 'img';
events: { events = {
dblclick: 'onActive', dblclick: 'onActive',
click: 'initResize', click: 'initResize',
error: 'onError', error: 'onError',
load: 'onLoad', load: 'onLoad',
dragstart: 'noDrag', dragstart: 'noDrag',
}, };
initialize(o) { initialize(o) {
ComponentView.prototype.initialize.apply(this, arguments); ComponentView.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, 'change:src', this.updateSrc); this.listenTo(this.model, 'change:src', this.updateSrc);
this.classEmpty = `${this.ppfx}plh-image`; this.classEmpty = `${this.ppfx}plh-image`;
this.fetchFile(); this.fetchFile();
}, }
/** /**
* Fetch file if exists * Fetch file if exists
@ -36,7 +36,7 @@ export default ComponentView.extend({
}); });
model.set('file', ''); model.set('file', '');
} }
}, }
/** /**
* Update src attribute * Update src attribute
@ -48,7 +48,7 @@ export default ComponentView.extend({
const srcExists = src && !model.isDefaultSrc(); const srcExists = src && !model.isDefaultSrc();
model.addAttributes({ src }); model.addAttributes({ src });
$el[srcExists ? 'removeClass' : 'addClass'](classEmpty); $el[srcExists ? 'removeClass' : 'addClass'](classEmpty);
}, }
/** /**
* Open dialog for image changing * Open dialog for image changing
@ -71,22 +71,22 @@ export default ComponentView.extend({
accept: 'image/*', accept: 'image/*',
}); });
} }
}, }
onError() { onError() {
const fallback = this.model.getSrcResult({ fallback: 1 }); const fallback = this.model.getSrcResult({ fallback: 1 });
if (fallback) this.el.src = fallback; if (fallback) this.el.src = fallback;
}, }
onLoad() { onLoad() {
// Used to update component tools box (eg. toolbar, resizer) once the image is loaded // Used to update component tools box (eg. toolbar, resizer) once the image is loaded
this.em.trigger('change:canvasOffset'); this.em.trigger('change:canvasOffset');
}, }
noDrag(ev) { noDrag(ev) {
ev.preventDefault(); ev.preventDefault();
return false; return false;
}, }
render() { render() {
this.renderAttributes(); this.renderAttributes();
@ -98,5 +98,5 @@ export default ComponentView.extend({
this.postRender(); this.postRender();
return this; return this;
}, }
}); }

6
src/dom_components/view/ComponentLabelView.js

@ -1,5 +1,5 @@
import ComponentLinkView from './ComponentLinkView'; import ComponentLinkView from './ComponentLinkView';
export default ComponentLinkView.extend({ export default class ComponentLabelView extends ComponentLinkView {
tagName: 'span' // Avoid Firefox bug with label editing #2332 tagName = 'span'; // Avoid Firefox bug with label editing #2332
}); }

4
src/dom_components/view/ComponentLinkView.js

@ -1,6 +1,6 @@
import ComponentView from './ComponentTextView'; import ComponentView from './ComponentTextView';
export default ComponentView.extend({ export default class ComponentLinkView extends ComponentView {
render(...args) { render(...args) {
ComponentView.prototype.render.apply(this, args); ComponentView.prototype.render.apply(this, args);
@ -10,4 +10,4 @@ export default ComponentView.extend({
return this; return this;
} }
}); }

15
src/dom_components/view/ComponentMapView.js

@ -1,15 +1,14 @@
import Backbone from 'backbone';
import ComponentView from './ComponentImageView'; import ComponentView from './ComponentImageView';
export default ComponentView.extend({ export default class ComponentMapView extends ComponentView {
tagName: 'div', tagName = 'div';
events: {}, events = {};
initialize(o) { initialize(o) {
ComponentView.prototype.initialize.apply(this, arguments); ComponentView.prototype.initialize.apply(this, arguments);
this.classEmpty = this.ppfx + 'plh-map'; this.classEmpty = this.ppfx + 'plh-map';
}, }
/** /**
* Update the map on the canvas * Update the map on the canvas
@ -17,7 +16,7 @@ export default ComponentView.extend({
*/ */
updateSrc() { updateSrc() {
this.getIframe().src = this.model.get('src'); this.getIframe().src = this.model.get('src');
}, }
getIframe() { getIframe() {
if (!this.iframe) { if (!this.iframe) {
@ -30,7 +29,7 @@ export default ComponentView.extend({
this.iframe = ifrm; this.iframe = ifrm;
} }
return this.iframe; return this.iframe;
}, }
render(...args) { render(...args) {
ComponentView.prototype.render.apply(this, args); ComponentView.prototype.render.apply(this, args);
@ -38,4 +37,4 @@ export default ComponentView.extend({
this.el.appendChild(this.getIframe()); this.el.appendChild(this.getIframe());
return this; return this;
} }
}); }

8
src/dom_components/view/ComponentScriptView.js

@ -1,9 +1,9 @@
import ComponentView from './ComponentImageView'; import ComponentView from './ComponentImageView';
export default ComponentView.extend({ export default class ComponentScriptView extends ComponentView {
tagName: 'script', tagName = 'script';
events: {}, events = {};
render() { render() {
const { model, em } = this; const { model, em } = this;
@ -39,4 +39,4 @@ export default ComponentView.extend({
this.postRender(); this.postRender();
return this; return this;
} }
}); }

6
src/dom_components/view/ComponentSvgView.js

@ -1,7 +1,7 @@
import ComponentView from './ComponentView'; import ComponentView from './ComponentView';
export default ComponentView.extend({ export default class ComponentSvgView extends ComponentView {
_createElement: function(tagName) { _createElement(tagName) {
return document.createElementNS('http://www.w3.org/2000/svg', tagName); return document.createElementNS('http://www.w3.org/2000/svg', tagName);
} }
}); }

2
src/dom_components/view/ComponentTableBodyView.js

@ -1,3 +1,3 @@
import ComponentView from './ComponentView'; import ComponentView from './ComponentView';
export default ComponentView.extend({}); export default class ComponentTableBodyView extends ComponentView {}

26
src/dom_components/view/ComponentTextNodeView.js

@ -1,24 +1,24 @@
import ComponentView from './ComponentView'; import ComponentView from './ComponentView';
export default ComponentView.extend({ export default class ComponentTextNodeView extends ComponentView {
initialize() { initialize() {
ComponentView.prototype.initialize.apply(this, arguments); ComponentView.prototype.initialize.apply(this, arguments);
}, }
// Clear methods used on Nodes with attributes // Clear methods used on Nodes with attributes
_setAttributes() {}, _setAttributes() {}
renderAttributes() {}, renderAttributes() {}
updateStatus() {}, updateStatus() {}
updateClasses() {}, updateClasses() {}
setAttribute() {}, setAttribute() {}
updateAttributes() {}, updateAttributes() {}
initClasses() {}, initClasses() {}
initComponents() {}, initComponents() {}
delegateEvents() {}, delegateEvents() {}
_createElement() { _createElement() {
return document.createTextNode(''); return document.createTextNode('');
}, }
render() { render() {
const { model, el } = this; const { model, el } = this;
@ -26,4 +26,4 @@ export default ComponentView.extend({
el.textContent = model.get('content'); el.textContent = model.get('content');
return this; return this;
} }
}); }

32
src/dom_components/view/ComponentTextView.js

@ -4,11 +4,11 @@ import { bindAll } from 'underscore';
const compProt = ComponentView.prototype; const compProt = ComponentView.prototype;
export default ComponentView.extend({ export default class ComponentTextView extends ComponentView {
events: { events = {
dblclick: 'onActive', dblclick: 'onActive',
input: 'onInput', input: 'onInput',
}, };
initialize(o) { initialize(o) {
compProt.initialize.apply(this, arguments); compProt.initialize.apply(this, arguments);
@ -19,11 +19,11 @@ export default ComponentView.extend({
this.listenTo(model, 'change:content', this.updateContentText); this.listenTo(model, 'change:content', this.updateContentText);
this.listenTo(model, 'sync:content', this.syncContent); this.listenTo(model, 'sync:content', this.syncContent);
this.rte = em && em.get('RichTextEditor'); this.rte = em && em.get('RichTextEditor');
}, }
updateContentText(m, v, opts = {}) { updateContentText(m, v, opts = {}) {
!opts.fromDisable && this.disableEditing(); !opts.fromDisable && this.disableEditing();
}, }
canActivate() { canActivate() {
const { model, rteEnabled, em } = this; const { model, rteEnabled, em } = this;
@ -52,7 +52,7 @@ export default ComponentView.extend({
} }
return { result, delegate }; return { result, delegate };
}, }
/** /**
* Enable element content editing * Enable element content editing
@ -85,11 +85,11 @@ export default ComponentView.extend({
} }
this.toggleEvents(1); this.toggleEvents(1);
}, }
onDisable() { onDisable() {
this.disableEditing(); this.disableEditing();
}, }
/** /**
* Disable element content editing * Disable element content editing
@ -115,7 +115,7 @@ export default ComponentView.extend({
} }
this.toggleEvents(); this.toggleEvents();
}, }
/** /**
* get content from RTE * get content from RTE
@ -126,7 +126,7 @@ export default ComponentView.extend({
const canGetRteContent = activeRte && typeof activeRte.getContent === 'function'; const canGetRteContent = activeRte && typeof activeRte.getContent === 'function';
return canGetRteContent ? activeRte.getContent() : this.getChildrenContainer().innerHTML; return canGetRteContent ? activeRte.getContent() : this.getChildrenContainer().innerHTML;
}, }
/** /**
* Merge content from the DOM to the model * Merge content from the DOM to the model
@ -147,7 +147,7 @@ export default ComponentView.extend({
} else { } else {
comps.resetFromString(content, opts); comps.resetFromString(content, opts);
} }
}, }
insertComponent(content, opts = {}) { insertComponent(content, opts = {}) {
const { model, el } = this; const { model, el } = this;
@ -184,7 +184,7 @@ export default ComponentView.extend({
} }
return model.append(content, opts); return model.append(content, opts);
}, }
/** /**
* Callback on input event * Callback on input event
@ -197,7 +197,7 @@ export default ComponentView.extend({
// Update toolbars // Update toolbars
em && em.trigger(ev, this.model); em && em.trigger(ev, this.model);
}, }
/** /**
* Isolate disable propagation method * Isolate disable propagation method
@ -206,7 +206,7 @@ export default ComponentView.extend({
* */ * */
disablePropagation(e) { disablePropagation(e) {
e.stopPropagation(); e.stopPropagation();
}, }
/** /**
* Enable/Disable events * Enable/Disable events
@ -245,5 +245,5 @@ export default ComponentView.extend({
el && el.tagName == 'BODY' && (el = 0); el && el.tagName == 'BODY' && (el = 0);
} }
} }
}, }
}); }

38
src/dom_components/view/ComponentVideoView.js

@ -1,28 +1,20 @@
import ComponentView from './ComponentImageView'; import ComponentView from './ComponentImageView';
import OComponentView from './ComponentView'; import OComponentView from './ComponentView';
export default ComponentView.extend({ export default class ComponentVideoView extends ComponentView {
tagName: 'div', tagName = 'div';
events: {}, events = {};
initialize(o) { initialize(o) {
OComponentView.prototype.initialize.apply(this, arguments); OComponentView.prototype.initialize.apply(this, arguments);
const { model } = this; const { model } = this;
const props = [ const props = ['loop', 'autoplay', 'controls', 'color', 'rel', 'modestbranding', 'poster'];
'loop',
'autoplay',
'controls',
'color',
'rel',
'modestbranding',
'poster'
];
const events = props.map(p => `change:${p}`).join(' '); const events = props.map(p => `change:${p}`).join(' ');
this.listenTo(model, 'change:provider', this.updateProvider); this.listenTo(model, 'change:provider', this.updateProvider);
this.listenTo(model, 'change:src', this.updateSrc); this.listenTo(model, 'change:src', this.updateSrc);
this.listenTo(model, events, this.updateVideo); this.listenTo(model, events, this.updateVideo);
}, }
/** /**
* Rerender on update of the provider * Rerender on update of the provider
@ -32,7 +24,7 @@ export default ComponentView.extend({
var prov = this.model.get('provider'); var prov = this.model.get('provider');
this.el.innerHTML = ''; this.el.innerHTML = '';
this.el.appendChild(this.renderByProvider(prov)); this.el.appendChild(this.renderByProvider(prov));
}, }
/** /**
* Update the source of the video * Update the source of the video
@ -57,7 +49,7 @@ export default ComponentView.extend({
} }
videoEl.src = src; videoEl.src = src;
}, }
/** /**
* Update video parameters * Update video parameters
@ -79,7 +71,7 @@ export default ComponentView.extend({
videoEl.controls = md.get('controls'); videoEl.controls = md.get('controls');
videoEl.poster = md.get('poster'); videoEl.poster = md.get('poster');
} }
}, }
renderByProvider(prov) { renderByProvider(prov) {
var videoEl; var videoEl;
@ -98,14 +90,14 @@ export default ComponentView.extend({
} }
this.videoEl = videoEl; this.videoEl = videoEl;
return videoEl; return videoEl;
}, }
renderSource() { renderSource() {
var el = document.createElement('video'); var el = document.createElement('video');
el.src = this.model.get('src'); el.src = this.model.get('src');
this.initVideoEl(el); this.initVideoEl(el);
return el; return el;
}, }
renderYoutube() { renderYoutube() {
var el = document.createElement('iframe'); var el = document.createElement('iframe');
@ -114,7 +106,7 @@ export default ComponentView.extend({
el.setAttribute('allowfullscreen', true); el.setAttribute('allowfullscreen', true);
this.initVideoEl(el); this.initVideoEl(el);
return el; return el;
}, }
renderYoutubeNoCookie() { renderYoutubeNoCookie() {
var el = document.createElement('iframe'); var el = document.createElement('iframe');
@ -123,7 +115,7 @@ export default ComponentView.extend({
el.setAttribute('allowfullscreen', true); el.setAttribute('allowfullscreen', true);
this.initVideoEl(el); this.initVideoEl(el);
return el; return el;
}, }
renderVimeo() { renderVimeo() {
var el = document.createElement('iframe'); var el = document.createElement('iframe');
@ -132,13 +124,13 @@ export default ComponentView.extend({
el.setAttribute('allowfullscreen', true); el.setAttribute('allowfullscreen', true);
this.initVideoEl(el); this.initVideoEl(el);
return el; return el;
}, }
initVideoEl(el) { initVideoEl(el) {
el.className = this.ppfx + 'no-pointer'; el.className = this.ppfx + 'no-pointer';
el.style.height = '100%'; el.style.height = '100%';
el.style.width = '100%'; el.style.width = '100%';
}, }
render(...args) { render(...args) {
ComponentView.prototype.render.apply(this, args); ComponentView.prototype.render.apply(this, args);
@ -148,4 +140,4 @@ export default ComponentView.extend({
this.updateVideo(); this.updateVideo();
return this; return this;
} }
}); }

80
src/dom_components/view/ComponentView.js

@ -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() {}
}); }

16
src/dom_components/view/ComponentsView.js

@ -2,7 +2,7 @@ import Backbone from 'backbone';
import { isUndefined } from 'underscore'; import { isUndefined } from 'underscore';
import { removeEl } from '../../utils/dom'; import { removeEl } from '../../utils/dom';
export default Backbone.View.extend({ export default class ComponentsView extends Backbone.View {
initialize(o) { initialize(o) {
this.opts = o || {}; this.opts = o || {};
this.config = o.config || {}; this.config = o.config || {};
@ -11,7 +11,7 @@ export default Backbone.View.extend({
this.listenTo(coll, 'add', this.addTo); this.listenTo(coll, 'add', this.addTo);
this.listenTo(coll, 'reset', this.resetChildren); this.listenTo(coll, 'reset', this.resetChildren);
this.listenTo(coll, 'remove', this.removeChildren); this.listenTo(coll, 'remove', this.removeChildren);
}, }
removeChildren(removed, coll, opts = {}) { removeChildren(removed, coll, opts = {}) {
removed.views.forEach(view => { removed.views.forEach(view => {
@ -24,7 +24,7 @@ export default Backbone.View.extend({
const inner = removed.components(); const inner = removed.components();
inner.forEach(it => this.removeChildren(it, coll, opts)); inner.forEach(it => this.removeChildren(it, coll, opts));
}, }
/** /**
* Add to collection * Add to collection
@ -45,7 +45,7 @@ export default Backbone.View.extend({
}; };
triggerAdd(model); triggerAdd(model);
} }
}, }
/** /**
* Add new object to collection * Add new object to collection
@ -120,13 +120,13 @@ export default Backbone.View.extend({
} }
return rendered; return rendered;
}, }
resetChildren(models, { previousModels = [] } = {}) { resetChildren(models, { previousModels = [] } = {}) {
this.parentEl.innerHTML = ''; this.parentEl.innerHTML = '';
previousModels.forEach(md => this.removeChildren(md, this.collection)); previousModels.forEach(md => this.removeChildren(md, this.collection));
models.each(model => this.addToCollection(model)); models.each(model => this.addToCollection(model));
}, }
render(parent) { render(parent) {
const el = this.el; const el = this.el;
@ -136,5 +136,5 @@ export default Backbone.View.extend({
el.innerHTML = ''; el.innerHTML = '';
el.appendChild(frag); el.appendChild(frag);
return this; return this;
}, }
}); }

16
src/dom_components/view/ToolbarButtonView.js

@ -1,23 +1,23 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
export default Backbone.View.extend({ export default class ToolbarButtonView extends Backbone.View {
events() { events() {
return ( return (
this.model.get('events') || { this.model.get('events') || {
mousedown: 'handleClick', mousedown: 'handleClick',
} }
); );
}, }
attributes() { attributes() {
return this.model.get('attributes'); return this.model.get('attributes');
}, }
initialize(opts = {}) { initialize(opts = {}) {
const { config = {} } = opts; const { config = {} } = opts;
this.em = config.em; this.em = config.em;
this.editor = config.editor; this.editor = config.editor;
}, }
handleClick(event) { handleClick(event) {
event.preventDefault(); event.preventDefault();
@ -48,7 +48,7 @@ export default Backbone.View.extend({
em.trigger('toolbar:run:before'); em.trigger('toolbar:run:before');
this.execCommand(calibrated); this.execCommand(calibrated);
}, }
execCommand(event) { execCommand(event) {
const opts = { event }; const opts = { event };
@ -62,7 +62,7 @@ export default Backbone.View.extend({
if (typeof command === 'string') { if (typeof command === 'string') {
editor.runCommand(command, opts); editor.runCommand(command, opts);
} }
}, }
render() { render() {
const { editor, $el, model } = this; const { editor, $el, model } = this;
@ -73,5 +73,5 @@ export default Backbone.View.extend({
id && $el.addClass(`${pfx}toolbar-item__${id}`); id && $el.addClass(`${pfx}toolbar-item__${id}`);
label && $el.append(label); label && $el.append(label);
return this; return this;
}, }
}); }

Loading…
Cancel
Save