Browse Source

Cleanup

pull/2429/head
adriangroch 7 years ago
parent
commit
5f4491173e
  1. 30
      src/rich_text_editor/index.js
  2. 2
      src/rich_text_editor/model/RichTextEditor.js

30
src/rich_text_editor/index.js

@ -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)">&supdsub;</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;

2
src/rich_text_editor/model/RichTextEditor.js

@ -143,8 +143,6 @@ export default class RichTextEditor {
btn.className = btn.className.replace(inactive, '').trim();
btn.className = btn.className.replace(disabled, '').trim();
console.log(this);
// if there is a state function, which depicts the state,
// i.e. `active`, `disabled`, then call it
if (state) {

Loading…
Cancel
Save