3,716
个编辑
第18行: | 第18行: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// 确保仅在有时间轴的页面中执行 | // 确保仅在有时间轴的页面中执行 | ||
if ($(" | if ($("#visualization").length) { | ||
const container = document.getElementById("visualization"); | |||
// 解析项目和日期 | |||
const itemsArray = $(container).data("items").split(";"); | |||
const convertToLink = function(text) { | |||
return text.replace(/\[\[(.*?)\]\]/g, '<a href="/index.php?title=$1">$1</a>'); | |||
}; | |||
const items = new vis.DataSet(itemsArray.map(function(item, index) { | |||
const parts = item.split(","); | |||
const start = parts[0].trim(); | |||
const content = convertToLink(parts[1].trim()); // 使用转换函数 | |||
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); | |||
} | } | ||
}); | }); |