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 4d75e70394f02a8ecce225e98cf94be288090928
parent 6d7f1e2fafc34c5d356164b6719ae4a765be8004
Author: unitehenry <unitehenry@gmail.com>
Date:   Fri,  1 Nov 2019 10:14:17 -0400

se-toolbar-option-active

Diffstat:
Msrc/striveneditor.css | 26+++++++++++++++++++-------
Msrc/striveneditor.js | 18++++++++++++------
2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -62,7 +62,7 @@ .striven-editor .se-toolbar { display: flex; justify-content: space-between; - align-items: center; + align-items: flex-end; flex-wrap: wrap; height: 40px; transition: height 200ms; @@ -73,13 +73,24 @@ } .striven-editor .se-toolbar-options { - margin: 0 10px; + margin-right: 10px; } .striven-editor .se-toolbar-option { + border: 1px solid transparent; + display: inline-block; padding: 8px; } +.striven-editor .se-toolbar-option.se-toolbar-option-active { + border: 1px solid rgba(0, 0, 0, .25); + background-color: #d4e7fc; +} + +.striven-editor .se-toolbar-option:hover.se-toolbar-option-active { + background-color: #b6d6fa; +} + .striven-editor .se-toolbar-group { display: inline-block; } @@ -94,7 +105,7 @@ } .striven-editor .se-toolbar-group[data-open="true"] .se-toolbar-option:hover { - background-color: #ddd; + background-color: #eee; } .striven-editor .se-toolbar-option > svg { @@ -105,7 +116,7 @@ .striven-editor .se-toolbar-option:hover, .striven-editor .se-toolbar-option:focus, .striven-editor .se-toolbar-option:active { - background-color: #ddd; + background-color: #eee; } .striven-editor .se-toolbar #toolbar-template { @@ -186,10 +197,10 @@ position: absolute; background-color: #fff; border: 1px solid #ddd; - padding: 10px 20px; + padding: 5px; z-index: 1000; opacity: 0; - transition: opacity 500ms, transform 500ms; + transition: opacity, transform, box-shadow, 500ms; } .striven-editor .se-popup.se-popup-top { @@ -205,6 +216,7 @@ .striven-editor .se-popup.se-popup-open { visibility: visible; transform: translateY(0); + box-shadow: 5px 5px 5px #ddd; opacity: 1; } @@ -224,7 +236,7 @@ .striven-editor .se-popup > .se-popup-form >.se-form-input { outline: none; - padding: 0 5px; + padding: 5px; } diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -256,8 +256,7 @@ export default class StrivenEditor { // keep enabled options on initial selection if (!this.body.textContent) { this.toolbarOptions.forEach((opt) => { - const path = opt.getElementsByTagName('path')[0]; - if (path.getAttribute('fill') === this.options.activeOptionColor) { + if (opt.classList.contains('se-toolbar-option-active')) { if(this.browser.isFirefox() || this.browser.isEdge()) { document.execCommand(opt.id.split('-')[1]); } else { @@ -565,6 +564,11 @@ export default class StrivenEditor { bodyBlur && bodyBlur(); } + const bodyClick = body.onclick; + body.onclick = () => { + body.textContent && this.toolbarState(); + bodyClick && bodyClick; + } return body; } @@ -596,7 +600,7 @@ export default class StrivenEditor { linkMenuButtons.classList.add('se-popup-button-container'); linkMenuButton.classList.add('se-popup-button', 'se-button-primary'); - linkMenuButton.textContent = "Insert Link"; + linkMenuButton.textContent = "Insert"; linkMenuCloseButton.classList.add('se-popup-button', 'se-button-secondary'); linkMenuCloseButton.textContent = "Close"; @@ -657,7 +661,7 @@ export default class StrivenEditor { this.closeLinkMenu(); } - linkMenuForm.appendChild(linkMenuFormLabel); + // linkMenuForm.appendChild(linkMenuFormLabel); linkMenuForm.appendChild(linkMenuFormInput); linkMenu.appendChild(linkMenuForm); @@ -1227,9 +1231,11 @@ export default class StrivenEditor { const toolbarOption = this.toolbar.querySelector(`#toolbar-${option}`); if (!option.toLowerCase().includes('justify') && !option.toLowerCase().includes('list')) { if (document.queryCommandState(option)) { - toolbarOption.querySelector('path').setAttribute('fill', this.options.activeOptionColor); + toolbarOption.classList.add('se-toolbar-option-active'); + // toolbarOption.querySelector('path').setAttribute('fill', this.options.activeOptionColor); } else { - toolbarOption.querySelector('path').setAttribute('fill', '#333'); + toolbarOption.classList.remove('se-toolbar-option-active'); + // toolbarOption.querySelector('path').setAttribute('fill', '#333'); } } })