MediaWiki:Vector.js:修订间差异
Salt lovely(留言 | 贡献) (左侧栏折叠) |
小 (// Edit via Wikiplus) |
||
(未显示3个用户的12个中间版本) | |||
第1行: | 第1行: | ||
/* 这里的任何JavaScript将为使用Vector皮肤的用户加载 */ |
/* 这里的任何JavaScript将为使用Vector皮肤的用户加载 */ |
||
// 左侧栏可折叠 |
|||
"use strict"; |
|||
//mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:Vector-leftPanel.js&action=raw&ctype=text/javascript", "text/javascript"); |
|||
/* |
|||
//mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:Vector-ThemeLoader.js&action=raw&ctype=text/javascript", "text/javascript"); |
|||
搬运须知: 您必须在**显眼处**标识来源“MCBBS Wiki”与作者“Salt_lovely”, **不**接受任何形式的简称或不署名。 |
|||
// mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:ThemeLoader.js&action=raw&ctype=text/javascript", "text/javascript"); |
|||
Notice: You have to mark origin "MCBBS Wiki" and author "Salt_lovely" in CONSPICUOS PLACE, abbreviation or omissions are NOT allowed. |
|||
// $('#pt-logout').before('<li><a title="切换主题" href="/wiki/MediaWiki:ThemeSwitch">主题</a></li>'); |
|||
许可证: CC BY-NC-SA 4.0 |
|||
License: CC BY-NC-SA 4.0 |
|||
*/ |
|||
(function () { |
|||
// 主过程 |
|||
function main() { |
|||
let panel = document.getElementById('mw-panel'); |
|||
if (!panel /*|| !(panel instanceof HTMLElement)*/) { |
|||
return; |
|||
} |
|||
let portals = HTMLElementFliter(Array.from(panel.getElementsByClassName('portal'))); |
|||
// let screenHeight = document.documentElement.clientHeight, panelHeight = panel.offsetHeight |
|||
/**左侧栏是不是比屏幕高度还要高了 */ |
|||
let overHeight = document.documentElement.clientHeight < panel.offsetHeight + 36; |
|||
/**是的话默认闭合,不是的话默认打开 */ |
|||
let defaultClass = overHeight ? 'salt-close' : 'salt-open'; |
|||
for (let portal of portals) { |
|||
let h3 = portal.querySelector('h1,h2,h3,h4,h5,h6'); |
|||
let body = portal.querySelector('.body'); |
|||
if (!h3 || !(h3 instanceof HTMLElement) |
|||
|| !body || !(body instanceof HTMLElement)) |
|||
continue; // 没有的话就算了 |
|||
if (h3.textContent == '导航') |
|||
continue; // 这个'导航'的h3是没不显示的 |
|||
let openHeight = body.offsetHeight; //, closeHeight = h3.offsetTop + h3.offsetHeight |
|||
portal.style.setProperty('--salt-open-height', openHeight + 'px'); |
|||
// portal.style.setProperty('--salt-close-height', closeHeight + 'px') |
|||
portal.classList.add(defaultClass); |
|||
h3.addEventListener('click', () => { |
|||
portal.toggleClass('salt-open'); |
|||
portal.toggleClass('salt-close'); |
|||
}); |
|||
} |
|||
} |
|||
function HTMLElementFliter(el) { |
|||
let hel = []; |
|||
for (let e of el) |
|||
if (e instanceof HTMLElement) |
|||
hel.push(e); |
|||
return hel; |
|||
} |
|||
// 执行 |
|||
function exec() { |
|||
if (!HTMLElement.prototype.toggleClass) { |
|||
HTMLElement.prototype.toggleClass = function (classes) { |
|||
var cls = String(classes).replace(/[\s\,\;]+/gm, ',').split(','); |
|||
for (var c of cls) { |
|||
if (this.classList.contains(c)) { |
|||
this.classList.remove(c); |
|||
} |
|||
else { |
|||
this.classList.add(c); |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
if (document.readyState == 'loading') { |
|||
document.addEventListener('DOMContentLoaded', () => { setTimeout(main, 500); }); |
|||
} |
|||
else { |
|||
setTimeout(main, 500); |
|||
} |
|||
} |
|||
exec(); |
|||
})(); |
2022年11月10日 (四) 16:34的最新版本
/* 这里的任何JavaScript将为使用Vector皮肤的用户加载 */
// 左侧栏可折叠
//mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:Vector-leftPanel.js&action=raw&ctype=text/javascript", "text/javascript");
//mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:Vector-ThemeLoader.js&action=raw&ctype=text/javascript", "text/javascript");
// mw.loader.load("//mcbbs.wiki/index.php?title=MediaWiki:ThemeLoader.js&action=raw&ctype=text/javascript", "text/javascript");
// $('#pt-logout').before('<li><a title="切换主题" href="/wiki/MediaWiki:ThemeSwitch">主题</a></li>');