js 整理
This commit is contained in:
parent
061c74031a
commit
bd6a4c84cb
|
@ -39,69 +39,49 @@ function _arrayLikeToArray(t, e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
function L(t) {
|
||||||
|
0 < arguments.length && void 0 !== t && t && (i = o && o.offsetWidth, c = a && a.offsetWidth, s = r && r.offsetWidth);
|
||||||
|
var e = document.getElementById("nav"), n = window.innerWidth < 768 || i + c + s > e.offsetWidth - 120;
|
||||||
|
n ? e.classList.add("hide-menu") : e.classList.remove("hide-menu")
|
||||||
|
}
|
||||||
|
|
||||||
let blogNameWidth, menusWidth, searchWidth, $nav;
|
var o = document.getElementById("site-name"), i = o && o.offsetWidth,
|
||||||
|
a = document.querySelector("#menus .menus_items"), c = a && a.offsetWidth,
|
||||||
|
r = document.querySelector("#search-button"), s = r && r.offsetWidth;
|
||||||
|
|
||||||
// 调整菜单
|
function l(t) {
|
||||||
function adjustMenu(init) {
|
function e(t) {
|
||||||
|
t.each(function (t, e) {
|
||||||
if (init) {
|
var n = $(e), o = n.attr("data-lazy-src") || n.attr("src"), i = o + "_1600w", a = n.attr("alt") || "";
|
||||||
blogNameWidth = document.getElementById("site-name").offsetWidth;
|
-1 !== o.indexOf("!blogimg") ? n.wrap('<a href="'.concat(o, '" data-fancybox="images" data-caption="').concat(a, '" class="fancybox" data-srcset="').concat(i, ' 1600w"></a>')) : n.wrap('<a href="'.concat(o, '" data-fancybox="images" data-caption="').concat(a, '" class="fancybox" data-srcset="').concat(o, ' 1600w"></a>'))
|
||||||
const $menusEle = document.querySelectorAll("#menus .menus_item");
|
|
||||||
menusWidth = 0;
|
|
||||||
$menusEle.length && $menusEle.forEach((i) => {
|
|
||||||
menusWidth += i.offsetWidth;
|
|
||||||
});
|
});
|
||||||
const $searchEle = document.querySelector("#search-button");
|
$().fancybox({
|
||||||
searchWidth = $searchEle ? $searchEle.offsetWidth : 0;
|
selector: "[data-fancybox]",
|
||||||
$nav = document.getElementById("nav");
|
loop: !0,
|
||||||
}
|
transitionEffect: "slide",
|
||||||
let hideMenuIndex;
|
protect: !0,
|
||||||
if (window.innerWidth <= 768) {
|
buttons: ["slideShow", "fullScreen", "thumbs", "close"],
|
||||||
hideMenuIndex = true;
|
hash: !1
|
||||||
} else {
|
})
|
||||||
hideMenuIndex = blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hideMenuIndex) {
|
void 0 === $.fancybox ? ($("head").append('<link rel="stylesheet" type="text/css" href="'.concat(GLOBAL_CONFIG.source.fancybox.css, '">')), $.getScript("".concat(GLOBAL_CONFIG.source.fancybox.js), function () {
|
||||||
$nav.classList.add("hide-menu");
|
e($(t))
|
||||||
} else {
|
})) : e($(t))
|
||||||
$nav.classList.remove("hide-menu");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function l(t) {
|
function w() {
|
||||||
// function e(t) {
|
var n = "fancybox" === GLOBAL_CONFIG.lightbox ? document.querySelectorAll("#article-container :not(a):not(.gallery-group) > img, #article-container > img,.bber-content-img > img") : [],
|
||||||
// t.each(function (t, e) {
|
o = 0 < n.length, i = document.querySelectorAll("#article-container .justified-gallery"), a = 0 < i.length;
|
||||||
// var n = $(e), o = n.attr("data-lazy-src") || n.attr("src"), i = o + "_1600w", a = n.attr("alt") || "";
|
(a || o) && btf.isJqueryLoad(function () {
|
||||||
// -1 != o.indexOf("!blogimg") ? n.wrap('<a href="'.concat(o, '" data-fancybox="images" data-caption="').concat(a, '" class="fancybox" data-srcset="').concat(i, ' 1600w"></a>')) : n.wrap('<a href="'.concat(o, '" data-fancybox="images" data-caption="').concat(a, '" class="fancybox" data-srcset="').concat(o, ' 1600w"></a>'))
|
var t, e;
|
||||||
// }), $().fancybox({
|
a && (t = $(i), (e = t.find("img")).unwrap(), e.length && e.each(function (t, e) {
|
||||||
// selector: "[data-fancybox]",
|
$(e).attr("data-lazy-src") && $(e).attr("src", $(e).attr("data-lazy-src")), $(e).wrap("<div></div>")
|
||||||
// loop: !0,
|
}), d ? btf.initJustifiedGallery(t) : ($("head").append('<link rel="stylesheet" type="text/css" href="'.concat(GLOBAL_CONFIG.source.justifiedGallery.css, '">')), $.getScript("".concat(GLOBAL_CONFIG.source.justifiedGallery.js), function () {
|
||||||
// transitionEffect: "slide",
|
btf.initJustifiedGallery(t)
|
||||||
// protect: !0,
|
}), d = !0)), o && l(n)
|
||||||
// buttons: ["slideShow", "fullScreen", "thumbs", "close"],
|
})
|
||||||
// hash: !1
|
}
|
||||||
// })
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void 0 === $.fancybox ? ($("head").append('<link rel="stylesheet" type="text/css" href="'.concat(GLOBAL_CONFIG.source.fancybox.css, '">')), $.getScript("".concat(GLOBAL_CONFIG.source.fancybox.js), function () {
|
|
||||||
// e($(t))
|
|
||||||
// })) : e($(t))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// function w() {
|
|
||||||
// var n = "fancybox" === GLOBAL_CONFIG.lightbox ? document.querySelectorAll("#article-container :not(a):not(.gallery-group) > img, #article-container > img,.bber-content-img > img") : [],
|
|
||||||
// o = 0 < n.length, i = document.querySelectorAll("#article-container .justified-gallery"), a = 0 < i.length;
|
|
||||||
// (a || o) && btf.isJqueryLoad(function () {
|
|
||||||
// var t, e;
|
|
||||||
// a && (t = $(i), (e = t.find("img")).unwrap(), e.length && e.each(function (t, e) {
|
|
||||||
// $(e).attr("data-lazy-src") && $(e).attr("src", $(e).attr("data-lazy-src")), $(e).wrap("<div></div>")
|
|
||||||
// }), d ? btf.initJustifiedGallery(t) : ($("head").append('<link rel="stylesheet" type="text/css" href="'.concat(GLOBAL_CONFIG.source.justifiedGallery.css, '">')), $.getScript("".concat(GLOBAL_CONFIG.source.justifiedGallery.js), function () {
|
|
||||||
// btf.initJustifiedGallery(t)
|
|
||||||
// }), d = !0)), o && l(n)
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
function S() {
|
function S() {
|
||||||
var t = document.getElementById("card-toc"), r = t.getElementsByClassName("toc-content")[0],
|
var t = document.getElementById("card-toc"), r = t.getElementsByClassName("toc-content")[0],
|
||||||
|
@ -111,7 +91,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
var t = window.scrollY || document.documentElement.scrollTop;
|
var t = window.scrollY || document.documentElement.scrollTop;
|
||||||
e(t), i(t)
|
e(t), i(t)
|
||||||
}, 100)()
|
}, 100)()
|
||||||
}, window.addEventListener("scroll", tocScrollFn);
|
};
|
||||||
|
window.addEventListener("scroll", tocScrollFn);
|
||||||
var e = function (t) {
|
var e = function (t) {
|
||||||
var e = c.clientHeight, n = document.documentElement.clientHeight,
|
var e = c.clientHeight, n = document.documentElement.clientHeight,
|
||||||
o = (t - c.offsetTop) / (n < e ? e - n : document.documentElement.scrollHeight - n),
|
o = (t - c.offsetTop) / (n < e ? e - n : document.documentElement.scrollHeight - n),
|
||||||
|
@ -124,7 +105,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
};
|
};
|
||||||
document.getElementById("mobile-toc-button").addEventListener("click", function () {
|
document.getElementById("mobile-toc-button").addEventListener("click", function () {
|
||||||
("0" === window.getComputedStyle(t).getPropertyValue("opacity") ? n : o)()
|
("0" === window.getComputedStyle(t).getPropertyValue("opacity") ? n : o)()
|
||||||
}), r.addEventListener("click", function (t) {
|
});
|
||||||
|
r.addEventListener("click", function (t) {
|
||||||
t.preventDefault();
|
t.preventDefault();
|
||||||
var e = t.target.classList.contains("toc-link") ? t.target : t.target.parentElement;
|
var e = t.target.classList.contains("toc-link") ? t.target : t.target.parentElement;
|
||||||
btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI(e.getAttribute("href")).replace("#", ""))), 300), window.innerWidth < 900 && o()
|
btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI(e.getAttribute("href")).replace("#", ""))), 300), window.innerWidth < 900 && o()
|
||||||
|
@ -189,7 +171,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
f.style.overflow = "", f.style.paddingRight = "", btf.fadeOut(u, .5), d.classList.remove("open")
|
f.style.overflow = "", f.style.paddingRight = "", btf.fadeOut(u, .5), d.classList.remove("open")
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustMenu(), document.getElementById("nav").classList.add("show"), GLOBAL_CONFIG_SITE.isPost ? (GLOBAL_CONFIG_SITE.isToc && S(), void 0 !== GLOBAL_CONFIG.noticeOutdate && (r = GLOBAL_CONFIG.noticeOutdate, (s = btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate)) >= r.limitDay && ((a = document.createElement("div")).className = "post-outdate-notice", a.textContent = r.messagePrev + " " + s + " " + r.messageNext, c = document.getElementById("article-container"), "top" === r.position ? c.insertBefore(a, c.firstChild) : c.appendChild(a))), GLOBAL_CONFIG.relativeDate.post && I(document.querySelectorAll("#post-meta time"))) : (GLOBAL_CONFIG.relativeDate.homepage && I(document.querySelectorAll("#recent-posts time")), !GLOBAL_CONFIG.runtime || (i = document.getElementById("runtimeshow")) && (o = i.getAttribute("data-publishDate"), i.innerText = btf.diffDate(o) + " " + GLOBAL_CONFIG.runtime), (n = document.getElementById("last-push-date")) && (e = n.getAttribute("data-lastPushDate"), n.innerText = btf.diffDate(e, !0)), (t = document.querySelectorAll("#aside-cat-list .card-category-list-item.parent i")).length && t.forEach(function (t) {
|
L(), document.getElementById("nav").classList.add("show"), GLOBAL_CONFIG_SITE.isPost ? (GLOBAL_CONFIG_SITE.isToc && S(), void 0 !== GLOBAL_CONFIG.noticeOutdate && (r = GLOBAL_CONFIG.noticeOutdate, (s = btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate)) >= r.limitDay && ((a = document.createElement("div")).className = "post-outdate-notice", a.textContent = r.messagePrev + " " + s + " " + r.messageNext, c = document.getElementById("article-container"), "top" === r.position ? c.insertBefore(a, c.firstChild) : c.appendChild(a))), GLOBAL_CONFIG.relativeDate.post && I(document.querySelectorAll("#post-meta time"))) : (GLOBAL_CONFIG.relativeDate.homepage && I(document.querySelectorAll("#recent-posts time")), !GLOBAL_CONFIG.runtime || (i = document.getElementById("runtimeshow")) && (o = i.getAttribute("data-publishDate"), i.innerText = btf.diffDate(o) + " " + GLOBAL_CONFIG.runtime), (n = document.getElementById("last-push-date")) && (e = n.getAttribute("data-lastPushDate"), n.innerText = btf.diffDate(e, !0)), (t = document.querySelectorAll("#aside-cat-list .card-category-list-item.parent i")).length && t.forEach(function (t) {
|
||||||
t.addEventListener("click", function (t) {
|
t.addEventListener("click", function (t) {
|
||||||
t.preventDefault();
|
t.preventDefault();
|
||||||
this.classList.toggle("expand");
|
this.classList.toggle("expand");
|
||||||
|
@ -233,9 +215,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
refreshFn();
|
refreshFn();
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener("resize", adjustMenu);
|
window.addEventListener("resize", L);
|
||||||
window.addEventListener("orientationchange", function () {
|
window.addEventListener("orientationchange", function () {
|
||||||
setTimeout(adjustMenu(!0), 100)
|
setTimeout(L(!0), 100)
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll("#sidebar-menus .expand").forEach(function (t) {
|
document.querySelectorAll("#sidebar-menus .expand").forEach(function (t) {
|
||||||
|
|
Loading…
Reference in New Issue