3,389
个编辑
MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
Salt lovely(留言 | 贡献) (左侧栏折叠) |
Salt lovely(留言 | 贡献) 小 (ES2015 == ES5 // false ; mw.ES2015 === mwES5 //) |
||
| 第10行: | 第10行: | ||
// 主过程 | // 主过程 | ||
function main() { | function main() { | ||
var panel = document.getElementById('mw-panel'); | |||
if (!panel /*|| !(panel instanceof HTMLElement)*/) { | if (!panel /*|| !(panel instanceof HTMLElement)*/) { | ||
return; | return; | ||
} | } | ||
var portals = HTMLElementFliter(Array.from(panel.getElementsByClassName('portal'))); | |||
// let screenHeight = document.documentElement.clientHeight, panelHeight = panel.offsetHeight | // 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) | if (!h3 || !(h3 instanceof HTMLElement) | ||
|| !body || !(body instanceof HTMLElement)) | || !body || !(body instanceof HTMLElement)) | ||
continue; // 没有的话就算了 | return "continue"; // 没有的话就算了 | ||
if (h3.textContent == '导航') | if (h3.textContent == '导航') | ||
continue; // 这个'导航'的h3是没不显示的 | return "continue"; // 这个'导航'的h3是没不显示的 | ||
var openHeight = body.offsetHeight; //, closeHeight = h3.offsetTop + h3.offsetHeight | |||
portal.style.setProperty('--salt-open-height', openHeight + 'px'); | portal.style.setProperty('--salt-open-height', openHeight + 'px'); | ||
// portal.style.setProperty('--salt-close-height', closeHeight + 'px') | // portal.style.setProperty('--salt-close-height', closeHeight + 'px') | ||
portal.classList.add(defaultClass); | portal.classList.add(defaultClass); | ||
h3.addEventListener('click', () | h3.addEventListener('click', function () { | ||
portal.toggleClass('salt-open'); | portal.toggleClass('salt-open'); | ||
portal.toggleClass('salt-close'); | 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) { | function HTMLElementFliter(el) { | ||
var hel = []; | |||
for ( | for (var _i = 0, el_1 = el; _i < el_1.length; _i++) { | ||
var e = el_1[_i]; | |||
if (e instanceof HTMLElement) | if (e instanceof HTMLElement) | ||
hel.push(e); | hel.push(e); | ||
} | |||
return hel; | return hel; | ||
} | } | ||
| 第50行: | 第56行: | ||
HTMLElement.prototype.toggleClass = function (classes) { | HTMLElement.prototype.toggleClass = function (classes) { | ||
var cls = String(classes).replace(/[\s\,\;]+/gm, ',').split(','); | var cls = String(classes).replace(/[\s\,\;]+/gm, ',').split(','); | ||
for (var | for (var _i = 0, cls_1 = cls; _i < cls_1.length; _i++) { | ||
var c = cls_1[_i]; | |||
if (this.classList.contains(c)) { | if (this.classList.contains(c)) { | ||
this.classList.remove(c); | this.classList.remove(c); | ||
| 第61行: | 第68行: | ||
} | } | ||
if (document.readyState == 'loading') { | if (document.readyState == 'loading') { | ||
document.addEventListener('DOMContentLoaded', () | document.addEventListener('DOMContentLoaded', function () { setTimeout(main, 500); }); | ||
} | } | ||
else { | else { | ||