Skip to content

Commit

Permalink
fix: close #532
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Aug 17, 2023
1 parent cbff2bf commit a1df190
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/toolbars/Bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default class Bubble extends Toolbar {
this.editorDom.querySelector('.CodeMirror').appendChild(this.bubbleDom);
}

appendMenusToDom(menus) {
this.options.dom.appendChild(menus);
}

/**
* 计算编辑区域的偏移量
* @returns {number} 编辑区域的滚动区域
Expand Down
4 changes: 4 additions & 0 deletions src/toolbars/FloatMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default class FloatMenu extends Toolbar {
this.initAction();
}

appendMenusToDom(menus) {
this.options.dom.appendChild(menus);
}

initAction() {
const self = this;
this.editor.addListener('cursorActivity', (codemirror, evt) => {
Expand Down
3 changes: 3 additions & 0 deletions src/toolbars/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ export default class Sidebar extends Toolbar {
// constructor(options) {
// super(options);
// }
appendMenusToDom(menus) {
this.options.dom.appendChild(menus);
}
}
8 changes: 6 additions & 2 deletions src/toolbars/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default class Toolbar {
*/
drawMenus() {
const fragLeft = document.createDocumentFragment();
const toolbarLeft = createElement('div', 'toolbar-left');

this.menus.level1MenusName.forEach((name) => {
const btn = this.menus.hooks[name].createBtn();
Expand All @@ -104,7 +103,12 @@ export default class Toolbar {
fragLeft.appendChild(btn);
});

toolbarLeft.appendChild(fragLeft);
this.appendMenusToDom(fragLeft);
}

appendMenusToDom(menus) {
const toolbarLeft = createElement('div', 'toolbar-left');
toolbarLeft.appendChild(menus);
this.options.dom.appendChild(toolbarLeft);
}

Expand Down
25 changes: 4 additions & 21 deletions src/toolbars/ToolbarRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,9 @@ export default class ToolbarRight extends Toolbar {
/**
* 根据配置画出来一级工具栏
*/
drawMenus() {
const fragRight = document.createDocumentFragment();
const toolbarRight = createElement('div', 'toolbar-right');

this.menus.level1MenusName.forEach((name) => {
const btn = this.menus.hooks[name].createBtn();
btn.addEventListener(
'click',
(event) => {
this.onClick(event, name);
},
false,
);
if (this.isHasSubMenu(name)) {
btn.classList.add('cherry-toolbar-dropdown');
}
fragRight.appendChild(btn);
});

toolbarRight.appendChild(fragRight);
this.options.dom.appendChild(toolbarRight);
appendMenusToDom(menus) {
const toolbarLeft = createElement('div', 'toolbar-right');
toolbarLeft.appendChild(menus);
this.options.dom.appendChild(toolbarLeft);
}
}

0 comments on commit a1df190

Please sign in to comment.