|
|
|
@ -109,7 +109,9 @@ export default () => { |
|
|
|
const classes = { |
|
|
|
actionbar: `${pfx}actionbar`, |
|
|
|
button: `${pfx}action`, |
|
|
|
active: `${pfx}active` |
|
|
|
active: `${pfx}active`, |
|
|
|
inactive: `${pfx}inactive`, |
|
|
|
disabled: `${pfx}disabled` |
|
|
|
}; |
|
|
|
const rte = new RichTextEditor({ |
|
|
|
el, |
|
|
|
@ -165,6 +167,32 @@ export default () => { |
|
|
|
* } |
|
|
|
* } |
|
|
|
* }) |
|
|
|
* // An example with state
|
|
|
|
* const isValidAnchor = (rte) => { |
|
|
|
* // a utility function to help determine if the selected is a valid anchor node
|
|
|
|
* const anchor = rte.selection().anchorNode; |
|
|
|
* const parentNode = anchor && anchor.parentNode; |
|
|
|
* const nextSibling = anchor && anchor.nextSibling; |
|
|
|
* return (parentNode && parentNode.nodeName == 'A') || (nextSibling && nextSibling.nodeName == 'A') |
|
|
|
* } |
|
|
|
* rte.add('toggleAnchor', { |
|
|
|
* icon: `<span style="transform:rotate(45deg)">⫘</span>`, |
|
|
|
* state: (rte, doc) => { |
|
|
|
* if (rte && rte.selection()) { |
|
|
|
* // `btnState` is a integer, -1 for disabled, 0 for inactive, 1 for active
|
|
|
|
* return isValidAnchor(rte) ? btnState.ACTIVE : btnState.INACTIVE; |
|
|
|
* } else { |
|
|
|
* return btnState.INACTIVE; |
|
|
|
* } |
|
|
|
* }, |
|
|
|
* result: (rte, action) => { |
|
|
|
* if (isValidAnchor(rte)) { |
|
|
|
* rte.exec('unlink'); |
|
|
|
* } else { |
|
|
|
* rte.insertHTML(`<a class="link" href="">${rte.selection()}</a>`); |
|
|
|
* } |
|
|
|
* } |
|
|
|
* }) |
|
|
|
*/ |
|
|
|
add(name, action = {}) { |
|
|
|
action.name = name; |
|
|
|
|