|
|
|
@ -1,4 +1,13 @@
|
|
|
|
|
var headingList = [];
|
|
|
|
|
var scrollBehaviorAvaliable = (function() {
|
|
|
|
|
var v = navigator.userAgent.match(/Chrome\/(?<version>\S+)/);
|
|
|
|
|
if (v && v.groups.version) { // 检测chrome版本
|
|
|
|
|
var chromeVersion = parseInt(v.groups.version);
|
|
|
|
|
return chromeVersion >= 61;
|
|
|
|
|
} else { // 非chrome
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
function getScrollOffset() {
|
|
|
|
|
if (mw.config.get('skin') === 'timeless' && $(window).width() > 850) {
|
|
|
|
@ -22,12 +31,19 @@ function scrollToAnchor(link) {
|
|
|
|
|
function doScroll() {
|
|
|
|
|
var position = target.offset().top - getScrollOffset();
|
|
|
|
|
|
|
|
|
|
$('html, body').animate({
|
|
|
|
|
scrollTop: position,
|
|
|
|
|
}, 500);
|
|
|
|
|
if (scrollBehaviorAvaliable) {
|
|
|
|
|
window.scrollTo({
|
|
|
|
|
top: position,
|
|
|
|
|
behavior: 'smooth'
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$('html, body').animate({
|
|
|
|
|
scrollTop: position,
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mw.config.get('skin') === 'minerva') { // 手机端主体,需要检测折叠状态
|
|
|
|
|
if (mw.config.get('skin') === 'minerva') { // 手机端主题,需要检测折叠状态
|
|
|
|
|
var collapseBlock = target.parents('.collapsible-block');
|
|
|
|
|
if (collapseBlock.length > 0 && !collapseBlock.hasClass('open-block')) {
|
|
|
|
|
var h1Elem = collapseBlock.prev('.collapsible-heading');
|
|
|
|
@ -64,7 +80,6 @@ function getScrollbarWidth() {
|
|
|
|
|
|
|
|
|
|
function updateActive() {
|
|
|
|
|
var scrollTop = $(window).scrollTop() + getAnchorOffset();
|
|
|
|
|
console.log('scroll top', scrollTop);
|
|
|
|
|
$('#isekai-offcanvas-toc ul .list-item').removeClass('active');
|
|
|
|
|
|
|
|
|
|
if (headingList.length > 0) {
|
|
|
|
@ -81,7 +96,7 @@ function updateActive() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!activedId) {
|
|
|
|
|
activedId = [headingList.length - 1].attr('id');
|
|
|
|
|
activedId = headingList[headingList.length - 1].attr('id');
|
|
|
|
|
}
|
|
|
|
|
$('#isekai-offcanvas-toc ul .list-item[data-id="' + activedId + '"]').addClass('active');
|
|
|
|
|
}
|
|
|
|
@ -92,6 +107,9 @@ function openOffcanvas() {
|
|
|
|
|
$('body').addClass(['toc-offcanvas-show', 'toc-offcanvas-open'])
|
|
|
|
|
.css('margin-right', scrollbarWidth);
|
|
|
|
|
$('#iseai-offcanvas-btn').css('margin-right', scrollbarWidth);
|
|
|
|
|
if (mw.config.get('skin') === 'timeless') {
|
|
|
|
|
$('#mw-header-container').css('padding-right', scrollbarWidth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 滚动到当前项目
|
|
|
|
|
let activedItem = $('#isekai-offcanvas-toc ul .list-item.active');
|
|
|
|
@ -106,18 +124,32 @@ function closeOffcanvas() {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$('body').removeClass('toc-offcanvas-show').css('margin-right', 0);
|
|
|
|
|
$('#iseai-offcanvas-btn').css('margin-right', 0);
|
|
|
|
|
if (mw.config.get('skin') === 'timeless') {
|
|
|
|
|
$('#mw-header-container').css('padding-right', 0);
|
|
|
|
|
}
|
|
|
|
|
}, 260);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成目录
|
|
|
|
|
$(function() {
|
|
|
|
|
// 创建目录dom
|
|
|
|
|
$('body').append(`
|
|
|
|
|
<div id="isekai-offcanvas-toc" class="toc-offcanvas">
|
|
|
|
|
<ul></ul>
|
|
|
|
|
</div>
|
|
|
|
|
<button role="button" id="iseai-offcanvas-btn" class="toc-offcanvas-btn" aria-label="Open float table of contents menu"></button>
|
|
|
|
|
<div id="isekai-offcanvas-cover" class="toc-offcanvas-cover"></div>
|
|
|
|
|
`);
|
|
|
|
|
var menuIcon = new OO.ui.IconWidget({ icon: 'menu' });
|
|
|
|
|
$('#iseai-offcanvas-btn').append(menuIcon.$element);
|
|
|
|
|
|
|
|
|
|
// 生成目录
|
|
|
|
|
var parserOutput = $('.mw-parser-output');
|
|
|
|
|
var headings = parserOutput.find('h1,h2,h3,h4,h5,h6');
|
|
|
|
|
|
|
|
|
|
var headNum = new Array(6).fill(0);
|
|
|
|
|
var menuList = [{
|
|
|
|
|
number: false,
|
|
|
|
|
text: '简介',
|
|
|
|
|
text: mw.msg('isekai-offcanvastoc-description-item'),
|
|
|
|
|
id: 'bodyContent'
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|