Widget:Countdown:修订间差异
来自OGAS数据中枢
更多语言
更多操作
imported>弃权者 |
imported>弃权者 无编辑摘要 |
||
| 第2行: | 第2行: | ||
"use strict"; | "use strict"; | ||
(function() { | (function() { | ||
if (typeof moment !== 'undefined') { | if (typeof moment !== 'undefined') { | ||
initCountdown(); | initCountdown(); | ||
| 第8行: | 第7行: | ||
} | } | ||
if (typeof mw !== 'undefined' && mw.loader && typeof mw.loader.using === 'function') { | if (typeof mw !== 'undefined' && mw.loader && typeof mw.loader.using === 'function') { | ||
mw.loader.using('moment').then(initCountdown).catch(loadFromCDN); | mw.loader.using('moment').then(initCountdown).catch(loadFromCDN); | ||
} else { | } else { | ||
loadFromCDN(); | loadFromCDN(); | ||
} | } | ||
function loadFromCDN() { | function loadFromCDN() { | ||
var script = document.createElement('script'); | |||
var | script.src = 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js'; | ||
script.onload = initCountdown; | |||
script.onerror = function() { | |||
document.querySelectorAll('.countdownNode').forEach(el => { | |||
el.textContent = '(无法加载时间库)'; | |||
el.classList.add('error'); | |||
}); | |||
}; | |||
document.head.appendChild(script); | |||
} | |||
} | } | ||
function initCountdown() { | function initCountdown() { | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', setupCountdown); | document.addEventListener('DOMContentLoaded', setupCountdown); | ||
| 第130行: | 第109行: | ||
const run = () => { | const run = () => { | ||
if (typeof jQuery === 'undefined') { | if (typeof jQuery === 'undefined') { | ||
document.querySelectorAll(".countdownNode:not(.disabled)").forEach(ele => { | document.querySelectorAll(".countdownNode:not(.disabled)").forEach(ele => { | ||
const time = moment(ele.dataset.target); | const time = moment(ele.dataset.target); | ||
| 第138行: | 第116行: | ||
}); | }); | ||
} else { | } else { | ||
jQuery(".countdownNode:not(.disabled)").each((_, ele) => { | jQuery(".countdownNode:not(.disabled)").each((_, ele) => { | ||
const self = jQuery(ele); | const self = jQuery(ele); | ||
| 第146行: | 第123行: | ||
}; | }; | ||
if (typeof jQuery === 'undefined') { | if (typeof jQuery === 'undefined') { | ||
document.querySelectorAll(".countdownNode").forEach(ele => { | document.querySelectorAll(".countdownNode").forEach(ele => { | ||
const time = moment(ele.dataset.target); | const time = moment(ele.dataset.target); | ||
| 第159行: | 第134行: | ||
}); | }); | ||
} else { | } else { | ||
jQuery(".countdownNode").each((_, ele) => { | jQuery(".countdownNode").each((_, ele) => { | ||
const self = jQuery(ele), | const self = jQuery(ele), | ||
2026年3月4日 (三) 12:31的版本
仅供{{Countdown}}使用。