Skip to content

Commit

Permalink
fix #679
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed May 25, 2016
1 parent b788549 commit e2cd8e6
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,29 @@ class Toolbar extends Module {
return;
}
}
let eventName = input.tagName === 'SELECT' ? 'change' : 'click';
input.addEventListener(eventName, () => {
this.quill.focus();
let value;
if (input.tagName === 'SELECT') {
if (input.selectedIndex < 0) return;
let selected = input.options[input.selectedIndex];
if (selected.hasAttribute('selected')) {
value = false;
let eventNames = input.tagName === 'SELECT' ? ['change'] : ['mousedown', 'touchstart'];
eventNames.forEach((eventName) => {
input.addEventListener(eventName, (e) => {
this.quill.focus();
let value;
if (input.tagName === 'SELECT') {
if (input.selectedIndex < 0) return;
let selected = input.options[input.selectedIndex];
if (selected.hasAttribute('selected')) {
value = false;
} else {
value = selected.value || false;
}
} else {
value = selected.value || false;
value = input.classList.contains('ql-active') ? false : input.value || true;
e.preventDefault();
}
} else {
value = input.classList.contains('ql-active') ? false : input.value || true;
}
if (this.handlers[format] != null) {
this.handlers[format].call(this, value);
} else {
this.quill.format(format, value, Quill.sources.USER);
}
if (this.handlers[format] != null) {
this.handlers[format].call(this, value);
} else {
this.quill.format(format, value, Quill.sources.USER);
}
});
});
// TODO use weakmap
this.controls.push([format, input]);
Expand Down

0 comments on commit e2cd8e6

Please sign in to comment.