MediaWiki:Gadget-RightToolbar.js:修订间差异
MediaWiki界面页面
更多操作
删除的内容 添加的内容
Maintenance script(留言 | 贡献) Inline fallback styles for RightToolbar |
Maintenance script(留言 | 贡献) 添加JavaScript代码 |
||
| 第1行: | 第1行: | ||
/* ================================================================ |
/* ================================================================ |
||
MediaWiki Gadget: Localized Clock Bar |
MediaWiki Gadget: Localized Clock Bar |
||
| 第86行: | 第87行: | ||
var isMobile = window.innerWidth <= 768; |
var isMobile = window.innerWidth <= 768; |
||
var |
var container = document.getElementById( 'mw-right-toolbar' ); |
||
if ( ! |
if ( !container ) { |
||
container = document.createElement( 'div' ); |
|||
container.id = 'mw-right-toolbar'; |
|||
container.className = 'mw-right-toolbar'; |
|||
document.body.appendChild( container ); |
|||
} |
} |
||
function createButton( id, text, tooltip, clickHandler ) { |
function createButton( id, text, tooltip, clickHandler ) { |
||
var button = document.createElement( 'button' ); |
|||
button.id = id; |
|||
button.className = 'mw-rt-button'; |
|||
button.title = tooltip; |
|||
button.textContent = text; |
|||
button.type = 'button'; |
|||
button.addEventListener( 'click', clickHandler ); |
|||
return button; |
|||
} |
} |
||
var |
var topButton = document.getElementById( 'mw-scroll-top' ); |
||
if ( ! |
if ( !topButton ) { |
||
topButton = createButton( 'mw-scroll-top', '▲', '回到顶部', function () { |
|||
window.scrollTo( { |
|||
top: 0, |
|||
behavior: 'smooth' |
|||
} ); |
|||
} ); |
} ); |
||
container.appendChild( topButton ); |
|||
} |
} |
||
var |
var bottomButton = document.getElementById( 'mw-scroll-bottom' ); |
||
if ( ! |
if ( !bottomButton ) { |
||
bottomButton = createButton( 'mw-scroll-bottom', '▼', '回到底部', function () { |
|||
window.scrollTo( { |
|||
$( 'html, body' ).animate( { scrollTop: $( document ).height() }, { duration: 500, easing: 'swing' } ); |
|||
top: document.body.scrollHeight, |
|||
behavior: 'smooth' |
|||
} ); |
|||
} ); |
} ); |
||
container.appendChild( bottomButton ); |
|||
} |
} |
||
var |
var clockDiv = document.getElementById( 'mw-right-toolbar-clock' ); |
||
if ( !isMobile && ! |
if ( !isMobile && !clockDiv ) { |
||
clockDiv = document.createElement( 'div' ); |
|||
clockDiv.id = 'mw-right-toolbar-clock'; |
|||
clockDiv.className = 'mw-rt-clock'; |
|||
); |
var localDateDiv = document.createElement( 'div' ); |
||
localDateDiv.id = 'mw-local-date'; |
|||
localDateDiv.textContent = '加载中...'; |
|||
var localTimeDiv = document.createElement( 'div' ); |
|||
localTimeDiv.id = 'mw-local-time'; |
|||
var utcTimeDiv = document.createElement( 'div' ); |
|||
utcTimeDiv.id = 'mw-utc-time'; |
|||
clockDiv.appendChild( localDateDiv ); |
|||
clockDiv.appendChild( localTimeDiv ); |
|||
clockDiv.appendChild( utcTimeDiv ); |
|||
container.appendChild( clockDiv ); |
|||
} |
} |
||
topButton.style.display = 'none'; |
|||
var ticking = false; |
var ticking = false; |
||
window.addEventListener( 'scroll', function () { |
|||
if ( ticking ) { |
if ( ticking ) { |
||
return; |
return; |
||
| 第136行: | 第160行: | ||
ticking = true; |
ticking = true; |
||
window.requestAnimationFrame( function () { |
window.requestAnimationFrame( function () { |
||
var scrollTop = |
var scrollTop = window.pageYOffset || document.documentElement.scrollTop; |
||
if ( scrollTop > 200 ) { |
if ( scrollTop > 200 ) { |
||
topButton.style.display = 'block'; |
|||
} else { |
} else { |
||
topButton.style.display = 'none'; |
|||
} |
} |
||
ticking = false; |
ticking = false; |
||
| 第147行: | 第171行: | ||
window.requestAnimationFrame( function () { |
window.requestAnimationFrame( function () { |
||
container.classList.add( 'is-visible' ); |
|||
} ); |
} ); |
||
| 第178行: | 第202行: | ||
} ).join( ':' ); |
} ).join( ':' ); |
||
var localDateEl = document.getElementById( 'mw-local-date' ); |
|||
var localTimeEl = document.getElementById( 'mw-local-time' ); |
|||
if ( localDateEl ) localDateEl.textContent = localDateStr; |
|||
if ( localTimeEl ) localTimeEl.textContent = localTimeStr; |
|||
var utcFormatter = new Intl.DateTimeFormat( userLang, { |
var utcFormatter = new Intl.DateTimeFormat( userLang, { |
||
| 第205行: | 第231行: | ||
} ).join( ':' ); |
} ).join( ':' ); |
||
var utcTimeEl = document.getElementById( 'mw-utc-time' ); |
|||
if ( utcTimeEl ) utcTimeEl.textContent = 'UTC: ' + utcDateStr + ' ' + utcTimeStr; |
|||
} |
} |
||
| 第226行: | 第253行: | ||
} |
} |
||
// 页面加载完成后初始化 |
|||
$( function () { |
|||
if ( document.readyState === 'loading' ) { |
|||
ensureToolbarStyles(); |
|||
document.addEventListener( 'DOMContentLoaded', initClockBar ); |
|||
} else { |
|||
initClockBar(); |
initClockBar(); |
||
} |
} |
||
} ); |
} ); |
||