|
|
@ -78,8 +78,8 @@ const defActions = { |
|
|
|
|
|
|
|
|
export default class RichTextEditor { |
|
|
export default class RichTextEditor { |
|
|
constructor(settings = {}) { |
|
|
constructor(settings = {}) { |
|
|
const el = settings.el; |
|
|
const { el, em } = settings; |
|
|
this.em = settings.em; |
|
|
this.em = em; |
|
|
|
|
|
|
|
|
if (el[RTE_KEY]) { |
|
|
if (el[RTE_KEY]) { |
|
|
return el[RTE_KEY]; |
|
|
return el[RTE_KEY]; |
|
|
@ -241,7 +241,7 @@ export default class RichTextEditor { |
|
|
*/ |
|
|
*/ |
|
|
syncActions() { |
|
|
syncActions() { |
|
|
this.getActions().forEach(action => { |
|
|
this.getActions().forEach(action => { |
|
|
if (this.settings.actionbar) { |
|
|
if (this.actionbar) { |
|
|
if (!action.state || (action.state && action.state(this, this.doc) >= 0)) { |
|
|
if (!action.state || (action.state && action.state(this, this.doc) >= 0)) { |
|
|
const event = action.event || 'click'; |
|
|
const event = action.event || 'click'; |
|
|
action.btn[`on${event}`] = e => { |
|
|
action.btn[`on${event}`] = e => { |
|
|
@ -323,7 +323,7 @@ export default class RichTextEditor { |
|
|
* @param {string} value HTML string |
|
|
* @param {string} value HTML string |
|
|
*/ |
|
|
*/ |
|
|
insertHTML(value, { select } = {}) { |
|
|
insertHTML(value, { select } = {}) { |
|
|
const { em, doc } = this; |
|
|
const { em, doc, el } = this; |
|
|
const sel = doc.getSelection(); |
|
|
const sel = doc.getSelection(); |
|
|
|
|
|
|
|
|
if (sel && sel.rangeCount) { |
|
|
if (sel && sel.rangeCount) { |
|
|
@ -343,7 +343,7 @@ export default class RichTextEditor { |
|
|
|
|
|
|
|
|
sel.removeAllRanges(); |
|
|
sel.removeAllRanges(); |
|
|
sel.addRange(range); |
|
|
sel.addRange(range); |
|
|
this.el.focus(); |
|
|
el.focus(); |
|
|
|
|
|
|
|
|
if (select) { |
|
|
if (select) { |
|
|
const cmp = em.getSelected(); |
|
|
const cmp = em.getSelected(); |
|
|
@ -351,7 +351,7 @@ export default class RichTextEditor { |
|
|
const toSel = cmp.find(`[${customElAttr}]`)[0]; |
|
|
const toSel = cmp.find(`[${customElAttr}]`)[0]; |
|
|
if (!toSel) return; |
|
|
if (!toSel) return; |
|
|
toSel.removeAttributes(customElAttr); |
|
|
toSel.removeAttributes(customElAttr); |
|
|
editor.select(toSel); |
|
|
em.setSelected(toSel); |
|
|
}); |
|
|
}); |
|
|
cmp.trigger('disable'); |
|
|
cmp.trigger('disable'); |
|
|
} |
|
|
} |
|
|
|