Skip to content

Commit

Permalink
fix #1191
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Dec 21, 2016
1 parent d80ea21 commit 1bc385a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
4 changes: 3 additions & 1 deletion modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class Toolbar extends Module {
let [format, input] = pair;
if (input.tagName === 'SELECT') {
let option;
if (range == null || formats[format] == null) {
if (range == null) {
option = null;
} else if (formats[format] == null) {
option = input.querySelector('option[selected]');
} else if (!Array.isArray(formats[format])) {
let value = formats[format];
Expand Down
42 changes: 19 additions & 23 deletions ui/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,29 @@ class Picker {
if (selected != null) {
selected.classList.remove('ql-selected');
}
if (item != null) {
item.classList.add('ql-selected');
this.select.selectedIndex = [].indexOf.call(item.parentNode.children, item);
if (item.hasAttribute('data-value')) {
this.label.setAttribute('data-value', item.getAttribute('data-value'));
} else {
this.label.removeAttribute('data-value');
}
if (item.hasAttribute('data-label')) {
this.label.setAttribute('data-label', item.getAttribute('data-label'));
} else {
this.label.removeAttribute('data-label');
}
if (trigger) {
if (typeof Event === 'function') {
this.select.dispatchEvent(new Event('change'));
} else if (typeof Event === 'object') { // IE11
let event = document.createEvent('Event');
event.initEvent('change', true, true);
this.select.dispatchEvent(event);
}
this.close();
}
if (item == null) return;
item.classList.add('ql-selected');
this.select.selectedIndex = [].indexOf.call(item.parentNode.children, item);
if (item.hasAttribute('data-value')) {
this.label.setAttribute('data-value', item.getAttribute('data-value'));
} else {
this.label.removeAttribute('data-value');
}
if (item.hasAttribute('data-label')) {
this.label.setAttribute('data-label', item.getAttribute('data-label'));
} else {
this.label.removeAttribute('data-label');
}
if (trigger) {
if (typeof Event === 'function') {
this.select.dispatchEvent(new Event('change'));
} else if (typeof Event === 'object') { // IE11
let event = document.createEvent('Event');
event.initEvent('change', true, true);
this.select.dispatchEvent(event);
}
this.close();
}
}

update() {
Expand Down

0 comments on commit 1bc385a

Please sign in to comment.