3,716
个编辑
第16行: | 第16行: | ||
} | } | ||
appendTimeline(); | appendTimeline(); | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// 确保仅在有时间轴的页面中执行 | // 确保仅在有时间轴的页面中执行 | ||
if ($(" | if ($(".visualization").length) { | ||
const | const containers = document.getElementsByClassName("visualization"); | ||
// 解析项目和日期 | Array.from(containers).forEach(container => { | ||
// 解析项目和日期 | |||
const itemsArray = $(container).data("items").split(";"); | |||
const items = new vis.DataSet(itemsArray.map(function(item, index) { | |||
const parts = item.split(","); | |||
const start = parts[0].trim(); | |||
let content = parts[1].trim(); | |||
// 处理文件链接和大小参数 | |||
content = content.replace(/(\[\[文件:(.*?)\|)(\d+x\d+)(\]\])/g, (match, p1, p2, p3, p4) => { | |||
return `${p1}${p2}${p4} style="width:${p3.split('x')[0]}px; height:${p3.split('x')[1]}px;"`; | |||
}); | |||
return { id: index + 1, content: content, start: start }; | |||
})); | |||
// Configuration for the Timeline | |||
const options = { locale: 'en' }; | |||
// Create a Timeline | |||
const timeline = new vis.Timeline(container, items, options); | |||
}); | |||
} | } | ||
}); | }); |