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