mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
47 lines
1.4 KiB
Plaintext
47 lines
1.4 KiB
Plaintext
script.
|
|
(function() {
|
|
const abcjsInit = function() {
|
|
const abcjsFn = function() {
|
|
setTimeout(function() {
|
|
const sheets = document.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.innerHTML, options)
|
|
}
|
|
}, 100)
|
|
}
|
|
|
|
if (typeof ABCJS === "object") {
|
|
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")
|
|
})()
|