|
|
第8行: |
第8行: |
| } | | } |
| appendCSS(); | | appendCSS(); |
|
| |
| // 引入 Vis Timeline 库
| |
| function appendTimeline() {
| |
| var script = document.createElement('script');
| |
| script.src = 'https://unpkg.com/vis-timeline@7.7.3/standalone/umd/vis-timeline-graph2d.min.js';
| |
| document.head.appendChild(script);
| |
| }
| |
| appendTimeline();
| |
| $(document).ready(function() {
| |
| // 确保仅在有时间轴的页面中执行
| |
| if ($("#visualization").length) {
| |
| const container = document.getElementById("visualization");
| |
|
| |
| // 解析项目和日期
| |
| const itemsArray = $(container).data("items").split(";");
| |
|
| |
| const convertToLink = function(text) {
| |
| // 处理文件链接
| |
| text = text.replace(/(\[\[文件:(.*?)\|)(\d+x\d+)(\]\])/g, function(match, p1, p2, p3, p4) {
| |
| return p1 + p2 + p4 + ' style="width:' + p3.split('x')[0] + 'px; height:' + p3.split('x')[1] + 'px;"';
| |
| });
| |
|
| |
| // 处理普通链接
| |
| 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);
| |
| }
| |
| });
| |