striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 48386d2d339343f8f3fbfa0fce607648635ad0d6
parent 3aa8ba8e3a49ae0efd56e69fdec1bd8880a44bdd
Author: unitehenry <unitehenry@gmail.com>
Date:   Fri,  1 Nov 2019 16:22:23 -0400

close all menus

Diffstat:
Msrc/striveneditor.js | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -996,8 +996,7 @@ export default class StrivenEditor { const windowResize = window.onresize; window.onresize = () => { this.toolbarGroups.forEach(group => (group && (group.style.padding = "0"))); - this.closeLinkMenu(); - this.closeImageMenu(); + this.closeAllMenus(); setResponsive(); windowResize && windowResize(); } @@ -1007,6 +1006,8 @@ export default class StrivenEditor { const textDecorationGroup = that.toolbar.querySelector('#group-textDecoration'); textDecorationMenu.onclick = () => { + that.closeAllMenus(); + let isOpen = (textDecorationMenu.dataset.open === 'true'); textDecorationMenu.dataset.open = (isOpen ? 'false' : 'true'); isOpen = (textDecorationMenu.dataset.open === 'true'); @@ -1051,8 +1052,7 @@ export default class StrivenEditor { const windowResize = window.onresize; window.onresize = () => { - this.closeLinkMenu(); - this.closeImageMenu(); + this.closeAllMenus(); setResponsive(); windowResize && windowResize(); } @@ -1206,11 +1206,11 @@ export default class StrivenEditor { } openLinkMenu() { + this.closeAllMenus(); + this.setMenuOffset(this.toolbar.querySelector('#toolbar-link'), this.linkMenu); this.linkMenu.classList.add('se-popup-open'); - //close other open popups - this.closeImageMenu(); this.linkMenu.dataset.active = "true"; this.addPopupEscapeHandler(); } @@ -1220,7 +1220,7 @@ export default class StrivenEditor { this.imageMenu.classList.add('se-popup-open'); //close other open popups - this.closeLinkMenu(); + this.closeAllMenus(); this.imageMenu.dataset.active = "true"; this.addPopupEscapeHandler(); } @@ -1237,11 +1237,15 @@ export default class StrivenEditor { this.removePopupEscapeHandler(); } + closeAllMenus() { + const popups = this.editor.getElementsByClassName('se-popup'); + [...popups].forEach(popup => popup.classList.remove('se-popup-open')); + } + popupEscapeHandler(evt) { if (evt.which === 27) { //close all open popups - this.closeImageMenu(); - this.closeLinkMenu(); + this.closeAllMenus(); } }