mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
fix: resolve issues from previous commit about feat(score tag)
This commit is contained in:
63
layout/includes/third-party/abcjs/abcjs.pug
vendored
63
layout/includes/third-party/abcjs/abcjs.pug
vendored
@@ -1,51 +1,46 @@
|
||||
script.
|
||||
(function() {
|
||||
var abcjsInit = function() {
|
||||
var abcjsFn = function() {
|
||||
const abcjsInit = function() {
|
||||
const abcjsFn = function() {
|
||||
setTimeout(function() {
|
||||
var sheets = document.querySelectorAll(".abc-music-sheet");
|
||||
for (var i = 0; i < sheets.length; i++) {
|
||||
var ele = sheets[i];
|
||||
if (ele.children.length > 0) continue;
|
||||
|
||||
// 从 data-params 属性中解析参数
|
||||
var params = {};
|
||||
var dp = ele.getAttribute("data-params");
|
||||
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);
|
||||
params = JSON.parse(dp)
|
||||
} catch (e) {
|
||||
console.error("解析 data-params 失败:", e);
|
||||
console.error("Failed to parse data-params:", e)
|
||||
}
|
||||
}
|
||||
|
||||
// 将解析出的参数与 responsive 参数合并,
|
||||
// 保证 params 中的内容在 responsive 之前
|
||||
var options = {};
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
options[key] = params[key];
|
||||
}
|
||||
}
|
||||
options.responsive = "resize";
|
||||
|
||||
// 使用 ABCJS.renderAbc 渲染乐谱
|
||||
ABCJS.renderAbc(ele, ele.innerHTML, options);
|
||||
|
||||
// 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);
|
||||
};
|
||||
}, 100)
|
||||
}
|
||||
|
||||
if (typeof ABCJS === "object") {
|
||||
abcjsFn();
|
||||
abcjsFn()
|
||||
} else {
|
||||
btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn);
|
||||
btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (window.pjax) {
|
||||
abcjsInit();
|
||||
abcjsInit()
|
||||
} else {
|
||||
window.addEventListener("load", abcjsInit);
|
||||
window.addEventListener("load", abcjsInit)
|
||||
}
|
||||
btf.addGlobalFn("encrypt", abcjsInit, "abcjs");
|
||||
})();
|
||||
|
||||
btf.addGlobalFn("encrypt", abcjsInit, "abcjs")
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user