Browse Source

Merge branch 'dev' into multi-frame

pull/2524/head
Artur Arseniev 7 years ago
parent
commit
b215528a3e
  1. 3
      src/commands/view/SelectComponent.js
  2. 32
      src/dom_components/view/ComponentTextView.js
  3. 8
      src/dom_components/view/ToolbarButtonView.js
  4. 4
      src/dom_components/view/ToolbarView.js

3
src/commands/view/SelectComponent.js

@ -570,7 +570,8 @@ export default {
this.toolbar = new Toolbar(toolbar); this.toolbar = new Toolbar(toolbar);
var toolbarView = new ToolbarView({ var toolbarView = new ToolbarView({
collection: this.toolbar, collection: this.toolbar,
editor: this.editor editor: this.editor,
em
}); });
toolbarEl.appendChild(toolbarView.render().el); toolbarEl.appendChild(toolbarView.render().el);
} }

32
src/dom_components/view/ComponentTextView.js

@ -45,7 +45,6 @@ export default ComponentView.extend({
} }
} }
this.rteEnabled = 1;
this.toggleEvents(1); this.toggleEvents(1);
}, },
@ -67,17 +66,34 @@ export default ComponentView.extend({
this.syncContent(); this.syncContent();
} }
this.rteEnabled = 0;
this.toggleEvents(); this.toggleEvents();
}, },
/**
* get content from RTE
* @return string
*/
getContent() {
const { rte } = this;
const { activeRte } = rte || {};
let content = '';
if (activeRte && typeof activeRte.getContent === 'function') {
content = activeRte.getContent();
} else {
content = this.getChildrenContainer().innerHTML;
}
return content;
},
/** /**
* Merge content from the DOM to the model * Merge content from the DOM to the model
*/ */
syncContent(opts = {}) { syncContent(opts = {}) {
const { model, rte, rteEnabled } = this; const { model, rte, rteEnabled } = this;
if (!rteEnabled && !opts.force) return; if (!rteEnabled && !opts.force) return;
const content = this.getChildrenContainer().innerHTML; const content = this.getContent();
const comps = model.components(); const comps = model.components();
const contentOpt = { fromDisable: 1, ...opts }; const contentOpt = { fromDisable: 1, ...opts };
comps.length && comps.reset(null, opts); comps.length && comps.reset(null, opts);
@ -141,14 +157,17 @@ export default ComponentView.extend({
* @param {Boolean} enable * @param {Boolean} enable
*/ */
toggleEvents(enable) { toggleEvents(enable) {
var method = enable ? 'on' : 'off'; const { em } = this;
const mixins = { on, off }; const mixins = { on, off };
this.em.setEditing(enable); const method = enable ? 'on' : 'off';
em.setEditing(enable);
this.rteEnabled = !!enable;
// The ownerDocument is from the frame // The ownerDocument is from the frame
var elDocs = [this.el.ownerDocument, document]; var elDocs = [this.el.ownerDocument, document];
mixins.off(elDocs, 'mousedown', this.disableEditing); mixins.off(elDocs, 'mousedown', this.disableEditing);
mixins[method](elDocs, 'mousedown', this.disableEditing); mixins[method](elDocs, 'mousedown', this.disableEditing);
em[method]('toolbar:run:before', this.disableEditing);
// Avoid closing edit mode on component click // Avoid closing edit mode on component click
this.$el.off('mousedown', this.disablePropagation); this.$el.off('mousedown', this.disablePropagation);
@ -161,8 +180,9 @@ export default ComponentView.extend({
while (el) { while (el) {
el.draggable = enable ? !1 : !0; el.draggable = enable ? !1 : !0;
// Note: el.parentNode is sometimes null here
el = el.parentNode; el = el.parentNode;
el.tagName == 'BODY' && (el = 0); el && el.tagName == 'BODY' && (el = 0);
} }
} }
} }

8
src/dom_components/view/ToolbarButtonView.js

@ -13,13 +13,17 @@ export default Backbone.View.extend({
return this.model.get('attributes'); return this.model.get('attributes');
}, },
initialize(opts) { initialize(opts = {}) {
this.editor = opts.config.editor; const { config = {} } = opts;
this.em = config.em;
this.editor = config.editor;
}, },
handleClick(event) { handleClick(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
const { em } = this;
em.trigger('toolbar:run:before');
this.execCommand(event); this.execCommand(event);
}, },

4
src/dom_components/view/ToolbarView.js

@ -4,8 +4,8 @@ import ToolbarButtonView from './ToolbarButtonView';
export default DomainViews.extend({ export default DomainViews.extend({
itemView: ToolbarButtonView, itemView: ToolbarButtonView,
initialize(opts) { initialize(opts = {}) {
this.config = { editor: opts.editor || '' }; this.config = { editor: opts.editor || '', em: opts.em };
this.listenTo(this.collection, 'reset', this.render); this.listenTo(this.collection, 'reset', this.render);
} }
}); });

Loading…
Cancel
Save