Fix: change disabled state after the content is set (#701)
This commit is contained in:
parent
eb6888e44c
commit
60693e8c3f
|
@ -89,17 +89,18 @@ const APPLY = (() => {
|
|||
// for getPreventDefault which got removed in FF59 https://bugzil.la/691151
|
||||
const EVENT_NAME = chrome.runtime.id;
|
||||
let ready;
|
||||
return (el, content) =>
|
||||
return (el, content, disabled) =>
|
||||
checkPageScript().then(ok => {
|
||||
if (!ok) {
|
||||
const disabled = el.disabled;
|
||||
el.textContent = content;
|
||||
// https://github.com/openstyles/stylus/issues/693
|
||||
el.disabled = disabled;
|
||||
} else {
|
||||
const detail = pageObject({
|
||||
method: 'setStyleContent',
|
||||
id: el.id,
|
||||
content
|
||||
content,
|
||||
disabled
|
||||
});
|
||||
window.dispatchEvent(new CustomEvent(EVENT_NAME, {detail}));
|
||||
}
|
||||
|
@ -119,13 +120,12 @@ const APPLY = (() => {
|
|||
const available = checkStyleApplied();
|
||||
if (available) {
|
||||
window.addEventListener(EVENT_NAME, function handler(e) {
|
||||
const {method, id, content} = e.detail;
|
||||
const {method, id, content, disabled} = e.detail;
|
||||
if (method === 'setStyleContent') {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
const disabled = el.disabled;
|
||||
el.textContent = content;
|
||||
el.disabled = disabled;
|
||||
} else if (method === 'orphan') {
|
||||
|
|
|
@ -68,7 +68,7 @@ function createStyleInjector({compare, setStyleContent, onUpdate}) {
|
|||
return update(style);
|
||||
}
|
||||
style.el = createStyle(style.id);
|
||||
const pending = setStyleContent(style.el, style.code);
|
||||
const pending = setStyleContent(style.el, style.code, !enabled);
|
||||
table.set(style.id, style);
|
||||
const nextIndex = list.findIndex(i => compare(i, style) > 0);
|
||||
if (nextIndex < 0) {
|
||||
|
@ -78,8 +78,6 @@ function createStyleInjector({compare, setStyleContent, onUpdate}) {
|
|||
document.documentElement.insertBefore(style.el, list[nextIndex].el);
|
||||
list.splice(nextIndex, 0, style);
|
||||
}
|
||||
// disabled flag is read-only when not attached to a document
|
||||
style.el.disabled = !enabled;
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
@ -110,7 +108,7 @@ function createStyleInjector({compare, setStyleContent, onUpdate}) {
|
|||
oldEl.parentNode.insertBefore(style.el, oldEl.nextSibling);
|
||||
style.el.disabled = !enabled;
|
||||
}
|
||||
return setStyleContent(style.el, code)
|
||||
return setStyleContent(style.el, code, !enabled)
|
||||
.then(() => oldEl && oldEl.remove());
|
||||
}
|
||||
|
||||
|
@ -153,13 +151,12 @@ function createStyleInjector({compare, setStyleContent, onUpdate}) {
|
|||
function sort() {
|
||||
list.sort(compare);
|
||||
for (const style of list) {
|
||||
// moving an element resets its 'disabled' state
|
||||
const disabled = style.el.disabled;
|
||||
// FIXME: do we need this?
|
||||
// const copy = document.importNode(el, true);
|
||||
// el.textContent += ' '; // invalidate CSSOM cache
|
||||
document.documentElement.appendChild(style.el);
|
||||
style.el.disabled = disabled;
|
||||
// moving an element resets its 'disabled' state
|
||||
style.el.disabled = !enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user