Spaces:
Paused
Paused
Delete c
Browse files- c/assets/custom.js +0 -120
c/assets/custom.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
(function () {
|
| 2 |
-
function checkIsEditPage() {
|
| 3 |
-
return window.location.href.includes("/functions");
|
| 4 |
-
}
|
| 5 |
-
let isCurrentlyEditPage = checkIsEditPage();
|
| 6 |
-
function onRouteChange() {
|
| 7 |
-
isCurrentlyEditPage = checkIsEditPage();
|
| 8 |
-
if (isCurrentlyEditPage) {
|
| 9 |
-
if (mutationObserverActive) {
|
| 10 |
-
mutationObserver.disconnect();
|
| 11 |
-
mutationObserverActive = false;
|
| 12 |
-
}
|
| 13 |
-
} else {
|
| 14 |
-
initializeAllCodeBlocks();
|
| 15 |
-
if (!mutationObserverActive) {
|
| 16 |
-
mutationObserver.observe(document.body, {
|
| 17 |
-
childList: true,
|
| 18 |
-
subtree: true,
|
| 19 |
-
});
|
| 20 |
-
mutationObserverActive = true;
|
| 21 |
-
}
|
| 22 |
-
}
|
| 23 |
-
}
|
| 24 |
-
const originalPushState = history.pushState;
|
| 25 |
-
history.pushState = function (state, title, url) {
|
| 26 |
-
originalPushState.apply(history, arguments);
|
| 27 |
-
onRouteChange();
|
| 28 |
-
};
|
| 29 |
-
window.addEventListener("popstate", onRouteChange);
|
| 30 |
-
const observedCodeBlocks = new WeakSet();
|
| 31 |
-
const resizeObserver = new ResizeObserver((entries) => {
|
| 32 |
-
if (isCurrentlyEditPage) return;
|
| 33 |
-
for (const entry of entries) {
|
| 34 |
-
const editorRoot = entry.target;
|
| 35 |
-
if (!editorRoot.classList.contains("cm-editor")) continue;
|
| 36 |
-
updateCodeBlock(editorRoot);
|
| 37 |
-
}
|
| 38 |
-
});
|
| 39 |
-
function updateCodeBlock(editorRoot) {
|
| 40 |
-
if (editorRoot.querySelector(".code-expand-btn")) return;
|
| 41 |
-
const height = editorRoot.scrollHeight;
|
| 42 |
-
if (height > 400) {
|
| 43 |
-
editorRoot.id = "collapsed";
|
| 44 |
-
const expandBtn = document.createElement("button");
|
| 45 |
-
expandBtn.className = "code-expand-btn";
|
| 46 |
-
expandBtn.id = "collapsed";
|
| 47 |
-
editorRoot.appendChild(expandBtn);
|
| 48 |
-
editorRoot.style.height = "400px";
|
| 49 |
-
}
|
| 50 |
-
}
|
| 51 |
-
function initializeCodeBlock(editorRoot) {
|
| 52 |
-
if (observedCodeBlocks.has(editorRoot)) return;
|
| 53 |
-
observedCodeBlocks.add(editorRoot);
|
| 54 |
-
resizeObserver.observe(editorRoot);
|
| 55 |
-
updateCodeBlock(editorRoot);
|
| 56 |
-
}
|
| 57 |
-
function initializeAllCodeBlocks() {
|
| 58 |
-
if (isCurrentlyEditPage) return;
|
| 59 |
-
document.querySelectorAll(".cm-editor").forEach(initializeCodeBlock);
|
| 60 |
-
}
|
| 61 |
-
const mutationObserver = new MutationObserver((mutations) => {
|
| 62 |
-
if (isCurrentlyEditPage) return;
|
| 63 |
-
let hasNewCodeBlocks = false;
|
| 64 |
-
mutations.forEach((mutation) => {
|
| 65 |
-
mutation.addedNodes.forEach((node) => {
|
| 66 |
-
if (node.nodeType !== 1) return;
|
| 67 |
-
if (node.classList?.contains("cm-editor")) {
|
| 68 |
-
initializeCodeBlock(node);
|
| 69 |
-
hasNewCodeBlocks = true;
|
| 70 |
-
} else {
|
| 71 |
-
const matches = node.querySelectorAll?.(".cm-editor") || [];
|
| 72 |
-
matches.forEach((el) => {
|
| 73 |
-
initializeCodeBlock(el);
|
| 74 |
-
hasNewCodeBlocks = true;
|
| 75 |
-
});
|
| 76 |
-
}
|
| 77 |
-
});
|
| 78 |
-
});
|
| 79 |
-
if (hasNewCodeBlocks) requestAnimationFrame(initializeAllCodeBlocks);
|
| 80 |
-
});
|
| 81 |
-
let mutationObserverActive = false;
|
| 82 |
-
document.addEventListener("click", function (evt) {
|
| 83 |
-
if (!evt.target.classList.contains("code-expand-btn")) return;
|
| 84 |
-
const editorRoot = evt.target.closest(".cm-editor");
|
| 85 |
-
if (!editorRoot) return;
|
| 86 |
-
const isCollapsed = editorRoot.id === "collapsed";
|
| 87 |
-
requestAnimationFrame(() => {
|
| 88 |
-
if (isCollapsed) {
|
| 89 |
-
const scroller = editorRoot.querySelector(".cm-scroller");
|
| 90 |
-
editorRoot.style.height = `${scroller.scrollHeight}px`;
|
| 91 |
-
editorRoot.id = "expanded";
|
| 92 |
-
evt.target.id = "expanded";
|
| 93 |
-
} else {
|
| 94 |
-
editorRoot.style.height = "400px";
|
| 95 |
-
editorRoot.id = "collapsed";
|
| 96 |
-
evt.target.id = "collapsed";
|
| 97 |
-
const scrollTarget =
|
| 98 |
-
editorRoot.closest(".relative.my-2")?.parentElement;
|
| 99 |
-
scrollTarget?.scrollIntoView({ behavior: "smooth", block: "start" });
|
| 100 |
-
}
|
| 101 |
-
});
|
| 102 |
-
});
|
| 103 |
-
function init() {
|
| 104 |
-
isCurrentlyEditPage = checkIsEditPage();
|
| 105 |
-
if (!isCurrentlyEditPage) initializeAllCodeBlocks();
|
| 106 |
-
mutationObserver.observe(document.body, { childList: true, subtree: true });
|
| 107 |
-
mutationObserverActive = true;
|
| 108 |
-
}
|
| 109 |
-
if (document.readyState === "loading") {
|
| 110 |
-
document.addEventListener("DOMContentLoaded", init);
|
| 111 |
-
} else {
|
| 112 |
-
init();
|
| 113 |
-
}
|
| 114 |
-
window.addEventListener("error", (error) => {
|
| 115 |
-
console.error("Code block error:", error);
|
| 116 |
-
});
|
| 117 |
-
window.addEventListener("unhandledrejection", (event) => {
|
| 118 |
-
console.error("Unhandled rejection:", event.reason);
|
| 119 |
-
});
|
| 120 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|