|
|
| 第1行: |
第1行: |
| /* 这里的任何JavaScript将为使用Vector皮肤的用户加载 */ | | /* 这里的任何JavaScript将为使用Vector皮肤的用户加载 */ |
| "use strict";
| | // 左侧栏可折叠 |
| /*
| | mw.loader.load("//mcbbs-wiki.cn/index.php?title=MediaWiki:Vector-leftPanel.js&action=raw&ctype=text/javascript", "text/javascript"); |
| 搬运须知: 您必须在**显眼处**标识来源“MCBBS Wiki”与作者“Salt_lovely”, **不**接受任何形式的简称或不署名。
| |
| Notice: You have to mark origin "MCBBS Wiki" and author "Salt_lovely" in CONSPICUOS PLACE, abbreviation or omissions are NOT allowed.
| |
| 许可证: CC BY-NC-SA 4.0
| |
| License: CC BY-NC-SA 4.0
| |
| */
| |
| (function () {
| |
| // 主过程
| |
| function main() {
| |
| var panel = document.getElementById('mw-panel');
| |
| if (!panel /*|| !(panel instanceof HTMLElement)*/) {
| |
| return;
| |
| }
| |
| var portals = HTMLElementFliter(Array.from(panel.getElementsByClassName('portal')));
| |
| // let screenHeight = document.documentElement.clientHeight, panelHeight = panel.offsetHeight
| |
| /**左侧栏是不是比屏幕高度还要高了 */
| |
| var overHeight = document.documentElement.clientHeight < panel.offsetHeight + 36;
| |
| /**是的话默认闭合,不是的话默认打开 */
| |
| var defaultClass = overHeight ? 'salt-close' : 'salt-open';
| |
| var _loop_1 = function (portal) {
| |
| var h3 = portal.querySelector('h1,h2,h3,h4,h5,h6');
| |
| var body = portal.querySelector('.body');
| |
| if (!h3 || !(h3 instanceof HTMLElement)
| |
| || !body || !(body instanceof HTMLElement))
| |
| return "continue"; // 没有的话就算了
| |
| if (h3.textContent == '导航')
| |
| return "continue"; // 这个'导航'的h3是没不显示的
| |
| var 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', function () {
| |
| portal.toggleClass('salt-open');
| |
| portal.toggleClass('salt-close');
| |
| });
| |
| };
| |
| for (var _i = 0, portals_1 = portals; _i < portals_1.length; _i++) {
| |
| var portal = portals_1[_i];
| |
| _loop_1(portal);
| |
| }
| |
| }
| |
| function HTMLElementFliter(el) {
| |
| var hel = [];
| |
| for (var _i = 0, el_1 = el; _i < el_1.length; _i++) {
| |
| var e = el_1[_i];
| |
| 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 _i = 0, cls_1 = cls; _i < cls_1.length; _i++) {
| |
| var c = cls_1[_i];
| |
| if (this.classList.contains(c)) {
| |
| this.classList.remove(c);
| |
| }
| |
| else {
| |
| this.classList.add(c);
| |
| }
| |
| }
| |
| };
| |
| }
| |
| if (document.readyState == 'loading') {
| |
| document.addEventListener('DOMContentLoaded', function () { setTimeout(main, 500); });
| |
| }
| |
| else {
| |
| setTimeout(main, 500);
| |
| }
| |
| }
| |
| exec();
| |
| })();
| |