Files
hexo-theme-butterfly/layout/includes/third-party/abcjs/abcjs.pug
T
2026-07-16 16:53:38 +08:00

50 lines
1.5 KiB
Plaintext

script.
(() => {
const abcjsInit = () => {
const abcjsFn = () => {
const $article = document.getElementById("article-container")
if (!$article || $article.querySelector(".hbe-container")) return
setTimeout(() => {
const sheets = $article.querySelectorAll(".abc-music-sheet")
for (let i = 0; i < sheets.length; i++) {
const ele = sheets[i]
if (ele.children.length > 0) continue
// Parse parameters from data-params attribute
let params = {}
const dp = ele.getAttribute("data-params")
if (dp) {
try {
params = JSON.parse(dp)
} catch (e) {
console.error("Failed to parse data-params:", e)
}
}
// Merge parsed parameters with the responsive option
// Ensures params content appears before responsive
const options = { ...params, responsive: "resize" }
// Render the music score using ABCJS.renderAbc
ABCJS.renderAbc(ele, ele.textContent, options)
}
}, 100)
}
if (typeof ABCJS === "object" && ABCJS !== null) {
abcjsFn()
} else {
btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn)
}
}
if (window.pjax) {
abcjsInit()
} else {
window.addEventListener("load", abcjsInit)
}
btf.addGlobalFn("encrypt", abcjsInit, "abcjs")
})()