From f7bd196c56f6cf310360bfa0fce3dc7b8d98bfd2 Mon Sep 17 00:00:00 2001 From: liuzhihang Date: Thu, 27 Oct 2022 00:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=8F=20js=20=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/main.js | 100 ++++++++---------------------------- 1 file changed, 20 insertions(+), 80 deletions(-) diff --git a/templates/assets/js/main.js b/templates/assets/js/main.js index a0fb061b..451ae62e 100644 --- a/templates/assets/js/main.js +++ b/templates/assets/js/main.js @@ -1,86 +1,26 @@ "use strict"; -function _typeof(t) { - return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) { - return typeof t - } : function (t) { - return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t - })(t) -} - -function _toConsumableArray(t) { - return _arrayWithoutHoles(t) || _iterableToArray(t) || _unsupportedIterableToArray(t) || _nonIterableSpread() -} - -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.") -} - -function _unsupportedIterableToArray(t, e) { - if (t) { - if ("string" == typeof t) return _arrayLikeToArray(t, e); - var n = Object.prototype.toString.call(t).slice(8, -1); - return "Object" === n && t.constructor && (n = t.constructor.name), "Map" === n || "Set" === n ? Array.from(t) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? _arrayLikeToArray(t, e) : void 0 - } -} - -function _iterableToArray(t) { - if ("undefined" != typeof Symbol && null != t[Symbol.iterator] || null != t["@@iterator"]) return Array.from(t) -} - -function _arrayWithoutHoles(t) { - if (Array.isArray(t)) return _arrayLikeToArray(t) -} - -function _arrayLikeToArray(t, e) { - (null == e || e > t.length) && (e = t.length); - for (var n = 0, o = new Array(e); n < e; n++) o[n] = t[n]; - return o -} - 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") - } - 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 e(t) { - t.each(function (t, e) { - var n = $(e), o = n.attr("data-lazy-src") || n.attr("src"), i = o + "_1600w", a = n.attr("alt") || ""; - -1 !== o.indexOf("!blogimg") ? n.wrap('')) : n.wrap('')) - }); - $().fancybox({ - selector: "[data-fancybox]", - loop: !0, - transitionEffect: "slide", - protect: !0, - buttons: ["slideShow", "fullScreen", "thumbs", "close"], - hash: !1 - }) + let $siteName = document.getElementById("site-name"); + let blogNameWidth = $siteName && $siteName.offsetWidth; + let $menusEle = document.querySelector("#menus .menus_items"); + let menusWidth = $menusEle && $menusEle.offsetWidth; + let $search = document.querySelector("#search-button"); + let searchWidth = $search && $search.offsetWidth; + + // 菜单栏调整 + function adjustMenu(init) { + + 0 < arguments.length && void 0 !== init && init && (blogNameWidth = $siteName && $siteName.offsetWidth, menusWidth = $menusEle && $menusEle.offsetWidth, searchWidth = $search && $search.offsetWidth); + const $nav = document.getElementById("nav"); + + if (window.innerWidth < 768 || blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120) { + $nav.classList.add("hide-menu") + } else { + $nav.classList.remove("hide-menu") } - - void 0 === $.fancybox ? ($("head").append('')), $.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("
") - }), d ? btf.initJustifiedGallery(t) : ($("head").append('')), $.getScript("".concat(GLOBAL_CONFIG.source.justifiedGallery.js), function () { - btf.initJustifiedGallery(t) - }), d = !0)), o && l(n) - }) } function S() { @@ -171,7 +111,7 @@ document.addEventListener("DOMContentLoaded", function () { f.style.overflow = "", f.style.paddingRight = "", btf.fadeOut(u, .5), d.classList.remove("open") } - 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) { + 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) { t.addEventListener("click", function (t) { t.preventDefault(); this.classList.toggle("expand"); @@ -215,9 +155,9 @@ document.addEventListener("DOMContentLoaded", function () { refreshFn(); - window.addEventListener("resize", L); + window.addEventListener("resize", adjustMenu); window.addEventListener("orientationchange", function () { - setTimeout(L(!0), 100) + setTimeout(adjustMenu(!0), 100) }); document.querySelectorAll("#sidebar-menus .expand").forEach(function (t) {