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 cdnList = [ | var cdnList = [ | ||
'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js' | 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js' | ||
]; | ]; | ||
tryLoadCDN( | tryLoadCDN(); | ||
function tryLoadCDN( | function tryLoadCDN() { | ||
var script = document.createElement('script'); | var script = document.createElement('script'); | ||
script.src = | script.src = 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js'; | ||
script.onload = initCountdown; | script.onload = initCountdown; | ||
script.onerror = function() { | script.onerror = function() { | ||
return; | |||
}; | }; | ||
document.head.appendChild(script); | document.head.appendChild(script); | ||
| 第47行: | 第32行: | ||
function initCountdown() { | function initCountdown() { | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', setupCountdown); | document.addEventListener('DOMContentLoaded', setupCountdown); | ||
| 第130行: | 第114行: | ||
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行: | 第121行: | ||
}); | }); | ||
} else { | } else { | ||
jQuery(".countdownNode:not(.disabled)").each((_, ele) => { | jQuery(".countdownNode:not(.disabled)").each((_, ele) => { | ||
const self = jQuery(ele); | const self = jQuery(ele); | ||
| 第146行: | 第128行: | ||
}; | }; | ||
if (typeof jQuery === 'undefined') { | if (typeof jQuery === 'undefined') { | ||
// 原生方式 | // 原生方式 | ||
| 第159行: | 第140行: | ||
}); | }); | ||
} else { | } else { | ||
jQuery(".countdownNode").each((_, ele) => { | jQuery(".countdownNode").each((_, ele) => { | ||
const self = jQuery(ele), | const self = jQuery(ele), | ||
2026年3月4日 (三) 12:19的版本
仅供{{Countdown}}使用。