Disable Material copy controls before test
This commit is contained in:
1 parent
4e47ca9057
commit
c6033fecc2
2 files changed
+26
-1
No files matched your search
@@ -229,6 +229,20 @@
|
||||
});
|
||||
}
|
||||
|
||||
function setMaterialCommandCopyEnabled(root, name, enabled) {
|
||||
root.querySelectorAll('[data-command="' + name + '"]').forEach(function (code) {
|
||||
const container = code.closest(".highlight") || code.closest("pre") || code.parentElement;
|
||||
if (!container) return;
|
||||
container.querySelectorAll(
|
||||
'button.md-code__button[data-md-type="copy"], button.md-clipboard'
|
||||
).forEach(function (button) {
|
||||
button.disabled = !enabled;
|
||||
if (enabled) button.removeAttribute("aria-disabled");
|
||||
else button.setAttribute("aria-disabled", "true");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function fallbackCopy(text) {
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
@@ -341,6 +355,8 @@
|
||||
}
|
||||
setCommandEnabled(root, "stock-now", phase === "active");
|
||||
setCommandEnabled(root, "companion-now", phase === "active");
|
||||
setMaterialCommandCopyEnabled(root, "stock-now", phase === "active");
|
||||
setMaterialCommandCopyEnabled(root, "companion-now", phase === "active");
|
||||
setText(
|
||||
root,
|
||||
'[data-role="stock-now-note"]',
|
||||
@@ -362,6 +378,14 @@
|
||||
}
|
||||
|
||||
render();
|
||||
if (typeof global.MutationObserver === "function") {
|
||||
const materialCopyObserver = new global.MutationObserver(function () {
|
||||
const enabled = phaseAt(config, Date.now()) === "active";
|
||||
setMaterialCommandCopyEnabled(root, "stock-now", enabled);
|
||||
setMaterialCommandCopyEnabled(root, "companion-now", enabled);
|
||||
});
|
||||
materialCopyObserver.observe(root, { childList: true, subtree: true });
|
||||
}
|
||||
global.setInterval(render, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,8 @@
|
||||
/* Material adds its own copier to every code block. This page supplies
|
||||
state-aware copy buttons, so the generic buttons would bypass disabled
|
||||
pre-start commands and duplicate every enabled action. */
|
||||
.preset-test .md-clipboard {
|
||||
.preset-test .md-clipboard,
|
||||
.preset-test .md-code__button[data-md-type="copy"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user