commit 703e52fe9660f1b4cb54e2103d3e2086d4ddbfbb
parent 5e415790af48a8d2760424c34d68b189ecc9429c
Author: unitehenry <unitehenry@gmail.com>
Date: Wed, 30 Oct 2019 15:12:30 -0400
more toolbar state update events
Diffstat:
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -180,7 +180,7 @@ export default class StrivenEditor {
window.getSelection().removeAllRanges();
window.getSelection().addRange(this.range);
-
+
const command = optionEl.id.split("-")[1];
switch (command) {
@@ -250,11 +250,10 @@ export default class StrivenEditor {
else {
document.execCommand(command, true);
}
-
- this.toolbarState();
break;
}
+ this.toolbarState();
optionElClick && optionElClick();
};
@@ -537,7 +536,7 @@ export default class StrivenEditor {
this.options.onEnter(e);
}
-
+
this.toolbarState();
}
@@ -547,6 +546,19 @@ export default class StrivenEditor {
this.range = this.getRange();
}
+ const bodyFocus = body.onfocus;
+ body.onfocus = () => {
+ window.getSelection().removeAllRanges();
+ this.toolbarState();
+ bodyFocus && bodyFocus();
+ }
+
+ const bodyBlur = body.onblur;
+ body.onblur = () => {
+ this.toolbarState();
+ bodyBlur && bodyBlur();
+ }
+
return body;
}
@@ -1171,7 +1183,7 @@ export default class StrivenEditor {
toolbarState() {
this.options.toolbarOptions.forEach(option => {
const toolbarOption = this.toolbar.querySelector(`#toolbar-${option}`);
- if (!option.includes('justify') && !option.includes('list')) {
+ if (!option.toLowerCase().includes('justify') && !option.toLowerCase().includes('list')) {
if (document.queryCommandState(option)) {
toolbarOption.querySelector('path').setAttribute('fill', this.options.activeOptionColor);
} else {