From cf6f9faab98f0f03ccd9d9595fd40f77bf6d1bda Mon Sep 17 00:00:00 2001 From: liuzhihang Date: Fri, 28 Oct 2022 22:53:44 +0800 Subject: [PATCH] =?UTF-8?q?js=20=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/main.btf.js | 797 ------------------------------- templates/assets/js/main.js | 277 ++++++----- templates/assets/js/man.heo.js | 327 ------------- templates/assets/js/utils.js | 11 + templates/assets/zhheo/blogex.js | 10 +- 5 files changed, 167 insertions(+), 1255 deletions(-) delete mode 100644 templates/assets/js/main.btf.js delete mode 100644 templates/assets/js/man.heo.js diff --git a/templates/assets/js/main.btf.js b/templates/assets/js/main.btf.js deleted file mode 100644 index ab868b47..00000000 --- a/templates/assets/js/main.btf.js +++ /dev/null @@ -1,797 +0,0 @@ -document.addEventListener('DOMContentLoaded', function () { - let blogNameWidth, menusWidth, searchWidth, $nav - let mobileSidebarOpen = false - - const adjustMenu = (init) => { - if (init) { - blogNameWidth = document.getElementById('site-name').offsetWidth - const $menusEle = document.querySelectorAll('#menus .menus_item') - menusWidth = 0 - $menusEle.length && $menusEle.forEach(i => { - menusWidth += i.offsetWidth - }) - const $searchEle = document.querySelector('#search-button') - searchWidth = $searchEle ? $searchEle.offsetWidth : 0 - $nav = document.getElementById('nav') - } - - let hideMenuIndex = '' - if (window.innerWidth <= 768) hideMenuIndex = true - else hideMenuIndex = blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120 - - if (hideMenuIndex) { - $nav.classList.add('hide-menu') - } else { - $nav.classList.remove('hide-menu') - } - } - - // 初始化header - const initAdjust = () => { - adjustMenu(true) - $nav.classList.add('show') - } - - // sidebar menus - const sidebarFn = { - open: () => { - btf.sidebarPaddingR() - document.body.style.overflow = 'hidden' - btf.animateIn(document.getElementById('menu-mask'), 'to_show 0.5s') - document.getElementById('sidebar-menus').classList.add('open') - mobileSidebarOpen = true - }, - close: () => { - const $body = document.body - $body.style.overflow = '' - $body.style.paddingRight = '' - btf.animateOut(document.getElementById('menu-mask'), 'to_hide 0.5s') - document.getElementById('sidebar-menus').classList.remove('open') - mobileSidebarOpen = false - } - } - - /** - * 首頁top_img底下的箭頭 - */ - const scrollDownInIndex = () => { - const $scrollDownEle = document.getElementById('scroll-down') - $scrollDownEle && $scrollDownEle.addEventListener('click', function () { - btf.scrollToDest(document.getElementById('content-inner').offsetTop, 300) - }) - } - - /** - * 代碼 - * 只適用於Hexo默認的代碼渲染 - */ - const addHighlightTool = function () { - const highLight = GLOBAL_CONFIG.highlight - if (!highLight) return - - const isHighlightCopy = highLight.highlightCopy - const isHighlightLang = highLight.highlightLang - const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink - const highlightHeightLimit = highLight.highlightHeightLimit - const isShowTool = isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined - const $figureHighlight = highLight.plugin === 'highlighjs' ? document.querySelectorAll('figure.highlight') : document.querySelectorAll('pre[class*="language-"]') - - if (!((isShowTool || highlightHeightLimit) && $figureHighlight.length)) return - - const isPrismjs = highLight.plugin === 'prismjs' - - let highlightShrinkEle = '' - let highlightCopyEle = '' - const highlightShrinkClass = isHighlightShrink === true ? 'closed' : '' - - if (isHighlightShrink !== undefined) { - highlightShrinkEle = `` - } - - if (isHighlightCopy) { - highlightCopyEle = '
' - } - - const copy = (text, ctx) => { - if (document.queryCommandSupported && document.queryCommandSupported('copy')) { - document.execCommand('copy') - if (GLOBAL_CONFIG.Snackbar !== undefined) { - btf.snackbarShow(GLOBAL_CONFIG.copy.success) - } else { - const prevEle = ctx.previousElementSibling - prevEle.innerText = GLOBAL_CONFIG.copy.success - prevEle.style.opacity = 1 - setTimeout(() => { - prevEle.style.opacity = 0 - }, 700) - } - } else { - if (GLOBAL_CONFIG.Snackbar !== undefined) { - btf.snackbarShow(GLOBAL_CONFIG.copy.noSupport) - } else { - ctx.previousElementSibling.innerText = GLOBAL_CONFIG.copy.noSupport - } - } - } - - // click events - const highlightCopyFn = (ele) => { - const $buttonParent = ele.parentNode - $buttonParent.classList.add('copy-true') - const selection = window.getSelection() - const range = document.createRange() - if (isPrismjs) range.selectNodeContents($buttonParent.querySelectorAll('pre code')[0]) - else range.selectNodeContents($buttonParent.querySelectorAll('table .code pre')[0]) - selection.removeAllRanges() - selection.addRange(range) - const text = selection.toString() - copy(text, ele.lastChild) - selection.removeAllRanges() - $buttonParent.classList.remove('copy-true') - } - - const highlightShrinkFn = (ele) => { - const $nextEle = [...ele.parentNode.children].slice(1) - ele.firstChild.classList.toggle('closed') - if (btf.isHidden($nextEle[$nextEle.length - 1])) { - $nextEle.forEach(e => { - e.style.display = 'block' - }) - } else { - $nextEle.forEach(e => { - e.style.display = 'none' - }) - } - } - - const highlightToolsFn = function (e) { - const $target = e.target.classList - if ($target.contains('expand')) highlightShrinkFn(this) - else if ($target.contains('copy-button')) highlightCopyFn(this) - } - - const expandCode = function () { - this.classList.toggle('expand-done') - } - - function createEle(lang, item, service) { - const fragment = document.createDocumentFragment() - - if (isShowTool) { - const hlTools = document.createElement('div') - hlTools.className = `highlight-tools ${highlightShrinkClass}` - hlTools.innerHTML = highlightShrinkEle + lang + highlightCopyEle - hlTools.addEventListener('click', highlightToolsFn) - fragment.appendChild(hlTools) - } - - if (highlightHeightLimit && item.offsetHeight > highlightHeightLimit + 30) { - const ele = document.createElement('div') - ele.className = 'code-expand-btn' - ele.innerHTML = '' - ele.addEventListener('click', expandCode) - fragment.appendChild(ele) - } - - if (service === 'hl') { - item.insertBefore(fragment, item.firstChild) - } else { - item.parentNode.insertBefore(fragment, item) - } - } - - if (isHighlightLang) { - if (isPrismjs) { - $figureHighlight.forEach(function (item) { - const langName = item.getAttribute('data-language') ? item.getAttribute('data-language') : 'Code' - const highlightLangEle = `
${langName}
` - btf.wrap(item, 'figure', {class: 'highlight'}) - createEle(highlightLangEle, item) - }) - } else { - $figureHighlight.forEach(function (item) { - let langName = item.getAttribute('class').split(' ')[1] - if (langName === 'plain' || langName === undefined) langName = 'Code' - const highlightLangEle = `
${langName}
` - createEle(highlightLangEle, item, 'hl') - }) - } - } else { - if (isPrismjs) { - $figureHighlight.forEach(function (item) { - btf.wrap(item, 'figure', {class: 'highlight'}) - createEle('', item) - }) - } else { - $figureHighlight.forEach(function (item) { - createEle('', item, 'hl') - }) - } - } - } - - /** - * PhotoFigcaption - */ - function addPhotoFigcaption() { - document.querySelectorAll('#article-container img').forEach(function (item) { - const parentEle = item.parentNode - const altValue = item.title || item.alt - if (altValue && !parentEle.parentNode.classList.contains('justified-gallery')) { - const ele = document.createElement('div') - ele.className = 'img-alt is-center' - ele.textContent = altValue - parentEle.insertBefore(ele, item.nextSibling) - } - }) - } - - /** - * Lightbox - */ - const runLightbox = () => { - btf.loadLightbox(document.querySelectorAll('#article-container img:not(.no-lightbox)')) - } - - /** - * justified-gallery 圖庫排版 - */ - const runJustifiedGallery = function (ele) { - ele.forEach(item => { - const $imgList = item.querySelectorAll('img') - - $imgList.forEach(i => { - const dataLazySrc = i.getAttribute('data-lazy-src') - if (dataLazySrc) i.src = dataLazySrc - btf.wrap(i, 'div', {class: 'fj-gallery-item'}) - }) - }) - - if (window.fjGallery) { - setTimeout(() => { - btf.initJustifiedGallery(ele) - }, 100) - return - } - - const newEle = document.createElement('link') - newEle.rel = 'stylesheet' - newEle.href = GLOBAL_CONFIG.source.justifiedGallery.css - document.body.appendChild(newEle) - getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { - btf.initJustifiedGallery(ele) - }) - } - - /** - * 滾動處理 - */ - const scrollFn = function () { - const $rightside = document.getElementById('rightside') - const innerHeight = window.innerHeight + 56 - - // 當滾動條小于 56 的時候 - if (document.body.scrollHeight <= innerHeight) { - $rightside.style.cssText = 'opacity: 1; transform: translateX(-58px)' - return - } - - // find the scroll direction - function scrollDirection(currentTop) { - const result = currentTop > initTop // true is down & false is up - initTop = currentTop - return result - } - - let initTop = 0 - let isChatShow = true - const $header = document.getElementById('page-header') - const isChatBtnHide = typeof chatBtnHide === 'function' - const isChatBtnShow = typeof chatBtnShow === 'function' - - const scrollTask = btf.throttle(() => { - const currentTop = window.scrollY || document.documentElement.scrollTop - const isDown = scrollDirection(currentTop) - if (currentTop > 56) { - if (isDown) { - if ($header.classList.contains('nav-visible')) $header.classList.remove('nav-visible') - if (isChatBtnShow && isChatShow === true) { - chatBtnHide() - isChatShow = false - } - } else { - if (!$header.classList.contains('nav-visible')) $header.classList.add('nav-visible') - if (isChatBtnHide && isChatShow === false) { - chatBtnShow() - isChatShow = true - } - } - $header.classList.add('nav-fixed') - if (window.getComputedStyle($rightside).getPropertyValue('opacity') === '0') { - $rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)' - } - } else { - if (currentTop === 0) { - $header.classList.remove('nav-fixed', 'nav-visible') - } - $rightside.style.cssText = "opacity: ''; transform: ''" - } - - if (document.body.scrollHeight <= innerHeight) { - $rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)' - } - }, 200) - - window.scrollCollect = scrollTask - - window.addEventListener('scroll', scrollCollect) - } - - /** - * toc,anchor - */ - const scrollFnToDo = function () { - const isToc = GLOBAL_CONFIG_SITE.isToc - const isAnchor = GLOBAL_CONFIG.isAnchor - const $article = document.getElementById('article-container') - - if (!($article && (isToc || isAnchor))) return - - let $tocLink, $cardToc, scrollPercent, autoScrollToc, isExpand - - if (isToc) { - const $cardTocLayout = document.getElementById('card-toc') - $cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0] - $tocLink = $cardToc.querySelectorAll('.toc-link') - const $tocPercentage = $cardTocLayout.querySelector('.toc-percentage') - isExpand = $cardToc.classList.contains('is-expand') - - scrollPercent = currentTop => { - const docHeight = $article.clientHeight - const winHeight = document.documentElement.clientHeight - const headerHeight = $article.offsetTop - const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight) - const scrollPercent = (currentTop - headerHeight) / (contentMath) - const scrollPercentRounded = Math.round(scrollPercent * 100) - const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded - $tocPercentage.textContent = percentage - } - - window.mobileToc = { - open: () => { - $cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px' - }, - - close: () => { - $cardTocLayout.style.animation = 'toc-close .2s' - setTimeout(() => { - $cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''" - }, 100) - } - } - - // toc元素點擊 - $cardToc.addEventListener('click', e => { - e.preventDefault() - const target = e.target.classList - if (target.contains('toc-content')) return - const $target = target.contains('toc-link') - ? e.target - : e.target.parentElement - btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI($target.getAttribute('href')).replace('#', ''))), 300) - if (window.innerWidth < 900) { - window.mobileToc.close() - } - }) - - autoScrollToc = item => { - const activePosition = item.getBoundingClientRect().top - const sidebarScrollTop = $cardToc.scrollTop - if (activePosition > (document.documentElement.clientHeight - 100)) { - $cardToc.scrollTop = sidebarScrollTop + 150 - } - if (activePosition < 100) { - $cardToc.scrollTop = sidebarScrollTop - 150 - } - } - } - - // find head position & add active class - const list = $article.querySelectorAll('h1,h2,h3,h4,h5,h6') - let detectItem = '' - const findHeadPosition = function (top) { - if (top === 0) { - return false - } - - let currentId = '' - let currentIndex = '' - - list.forEach(function (ele, index) { - if (top > btf.getEleTop(ele) - 80) { - const id = ele.id - currentId = id ? '#' + encodeURI(id) : '' - currentIndex = index - } - }) - - if (detectItem === currentIndex) return - - if (isAnchor) btf.updateAnchor(currentId) - - detectItem = currentIndex - - if (isToc) { - $cardToc.querySelectorAll('.active').forEach(i => { - i.classList.remove('active') - }) - - if (currentId === '') { - return - } - - const currentActive = $tocLink[currentIndex] - currentActive.classList.add('active') - - setTimeout(() => { - autoScrollToc(currentActive) - }, 0) - - if (isExpand) return - let parent = currentActive.parentNode - - for (; !parent.matches('.toc'); parent = parent.parentNode) { - if (parent.matches('li')) parent.classList.add('active') - } - } - } - - // main of scroll - window.tocScrollFn = function () { - return btf.throttle(function () { - const currentTop = window.scrollY || document.documentElement.scrollTop - isToc && scrollPercent(currentTop) - findHeadPosition(currentTop) - }, 100)() - } - window.addEventListener('scroll', tocScrollFn) - } - - /** - * Rightside - */ - const rightSideFn = { - switchReadMode: () => { // read-mode - const $body = document.body - $body.classList.add('read-mode') - const newEle = document.createElement('button') - newEle.type = 'button' - newEle.className = 'fas fa-sign-out-alt exit-readmode' - $body.appendChild(newEle) - - function clickFn() { - $body.classList.remove('read-mode') - newEle.remove() - newEle.removeEventListener('click', clickFn) - } - - newEle.addEventListener('click', clickFn) - }, - switchDarkMode: () => { // Switch Between Light And Dark Mode - const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light' - if (nowMode === 'light') { - activateDarkMode() - saveToLocal.set('theme', 'dark', 2) - GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night) - } else { - activateLightMode() - saveToLocal.set('theme', 'light', 2) - GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day) - } - // handle some cases - typeof utterancesTheme === 'function' && utterancesTheme() - typeof changeGiscusTheme === 'function' && changeGiscusTheme() - typeof FB === 'object' && window.loadFBComment && window.loadFBComment() - typeof runMermaid === 'function' && window.runMermaid() - }, - showOrHideBtn: (e) => { // rightside 點擊設置 按鈕 展開 - const rightsideHideClassList = document.getElementById('rightside-config-hide').classList - rightsideHideClassList.toggle('show') - if (e.classList.contains('show')) { - rightsideHideClassList.add('status') - setTimeout(() => { - rightsideHideClassList.remove('status') - }, 300) - } - e.classList.toggle('show') - }, - scrollToTop: () => { // Back to top - btf.scrollToDest(0, 500) - }, - hideAsideBtn: () => { // Hide aside - const $htmlDom = document.documentElement.classList - $htmlDom.contains('hide-aside') - ? saveToLocal.set('aside-status', 'show', 2) - : saveToLocal.set('aside-status', 'hide', 2) - $htmlDom.toggle('hide-aside') - }, - - runMobileToc: () => { - if (window.getComputedStyle(document.getElementById('card-toc')).getPropertyValue('opacity') === '0') window.mobileToc.open() - else window.mobileToc.close() - } - } - - document.getElementById('rightside').addEventListener('click', function (e) { - const $target = e.target.id ? e.target : e.target.parentNode - switch ($target.id) { - case 'go-up': - rightSideFn.scrollToTop() - break - case 'rightside_config': - rightSideFn.showOrHideBtn($target) - break - case 'mobile-toc-button': - rightSideFn.runMobileToc() - break - case 'readmode': - rightSideFn.switchReadMode() - break - case 'darkmode': - rightSideFn.switchDarkMode() - break - case 'hide-aside-btn': - rightSideFn.hideAsideBtn() - break - default: - break - } - }) - - /** - * menu - * 側邊欄sub-menu 展開/收縮 - */ - const clickFnOfSubMenu = () => { - document.querySelectorAll('#sidebar-menus .site-page.group').forEach(function (item) { - item.addEventListener('click', function () { - this.classList.toggle('hide') - }) - }) - } - - /** - * 複製時加上版權信息 - */ - const addCopyright = () => { - const copyright = GLOBAL_CONFIG.copyright - document.body.oncopy = (e) => { - e.preventDefault() - let textFont; - const copyFont = window.getSelection(0).toString() - if (copyFont.length > copyright.limitCount) { - textFont = copyFont + '\n' + '\n' + '\n' + - copyright.languages.author + '\n' + - copyright.languages.link + window.location.href + '\n' + - copyright.languages.source + '\n' + - copyright.languages.info - } else { - textFont = copyFont - } - if (e.clipboardData) { - return e.clipboardData.setData('text', textFont) - } else { - return window.clipboardData.setData('text', textFont) - } - } - } - - /** - * 網頁運行時間 - */ - const addRuntime = () => { - const $runtimeCount = document.getElementById('runtimeshow') - if ($runtimeCount) { - const publishDate = $runtimeCount.getAttribute('data-publishDate') - $runtimeCount.innerText = btf.diffDate(publishDate) + ' ' + GLOBAL_CONFIG.runtime - } - } - - /** - * 最後一次更新時間 - */ - const addLastPushDate = () => { - const $lastPushDateItem = document.getElementById('last-push-date') - if ($lastPushDateItem) { - const lastPushDate = $lastPushDateItem.getAttribute('data-lastPushDate') - $lastPushDateItem.innerText = btf.diffDate(lastPushDate, true) - } - } - - /** - * table overflow - */ - const addTableWrap = () => { - const $table = document.querySelectorAll('#article-container :not(.highlight) > table, #article-container > table') - if ($table.length) { - $table.forEach(item => { - btf.wrap(item, 'div', {class: 'table-wrap'}) - }) - } - } - - /** - * tag-hide - */ - const clickFnOfTagHide = function () { - const $hideInline = document.querySelectorAll('#article-container .hide-button') - if ($hideInline.length) { - $hideInline.forEach(function (item) { - item.addEventListener('click', function (e) { - const $this = this - $this.classList.add('open') - const $fjGallery = $this.nextElementSibling.querySelectorAll('.fj-gallery') - $fjGallery.length && btf.initJustifiedGallery($fjGallery) - }) - }) - } - } - - const tabsFn = { - clickFnOfTabs: function () { - document.querySelectorAll('#article-container .tab > button').forEach(function (item) { - item.addEventListener('click', function (e) { - const $this = this - const $tabItem = $this.parentNode - - if (!$tabItem.classList.contains('active')) { - const $tabContent = $tabItem.parentNode.nextElementSibling - const $siblings = btf.siblings($tabItem, '.active')[0] - $siblings && $siblings.classList.remove('active') - $tabItem.classList.add('active') - const tabId = $this.getAttribute('data-href').replace('#', '') - const childList = [...$tabContent.children] - childList.forEach(item => { - if (item.id === tabId) item.classList.add('active') - else item.classList.remove('active') - }) - const $isTabJustifiedGallery = $tabContent.querySelectorAll(`#${tabId} .fj-gallery`) - if ($isTabJustifiedGallery.length > 0) { - btf.initJustifiedGallery($isTabJustifiedGallery) - } - } - }) - }) - }, - backToTop: () => { - document.querySelectorAll('#article-container .tabs .tab-to-top').forEach(function (item) { - item.addEventListener('click', function () { - btf.scrollToDest(btf.getEleTop(btf.getParents(this, '.tabs')), 300) - }) - }) - } - } - - const toggleCardCategory = function () { - const $cardCategory = document.querySelectorAll('#aside-cat-list .card-category-list-item.parent i') - if ($cardCategory.length) { - $cardCategory.forEach(function (item) { - item.addEventListener('click', function (e) { - e.preventDefault() - const $this = this - $this.classList.toggle('expand') - const $parentEle = $this.parentNode.nextElementSibling - if (btf.isHidden($parentEle)) { - $parentEle.style.display = 'block' - } else { - $parentEle.style.display = 'none' - } - }) - }) - } - } - - const switchComments = function () { - let switchDone = false - const $switchBtn = document.querySelector('#comment-switch > .switch-btn') - $switchBtn && $switchBtn.addEventListener('click', function () { - this.classList.toggle('move') - document.querySelectorAll('#post-comment > .comment-wrap > div').forEach(function (item) { - if (btf.isHidden(item)) { - item.style.cssText = 'display: block;animation: tabshow .5s' - } else { - item.style.cssText = "display: none;animation: ''" - } - }) - - if (!switchDone && typeof loadOtherComment === 'function') { - switchDone = true - loadOtherComment() - } - }) - } - - const addPostOutdateNotice = function () { - const data = GLOBAL_CONFIG.noticeOutdate - const diffDay = btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate) - if (diffDay >= data.limitDay) { - const ele = document.createElement('div') - ele.className = 'post-outdate-notice' - ele.textContent = data.messagePrev + ' ' + diffDay + ' ' + data.messageNext - const $targetEle = document.getElementById('article-container') - if (data.position === 'top') { - $targetEle.insertBefore(ele, $targetEle.firstChild) - } else { - $targetEle.appendChild(ele) - } - } - } - - const lazyloadImg = () => { - window.lazyLoadInstance = new LazyLoad({ - elements_selector: 'img', - threshold: 0, - data_src: 'lazy-src' - }) - } - - const relativeDate = function (selector) { - selector.forEach(item => { - const $this = item - const timeVal = $this.getAttribute('datetime') - $this.innerText = btf.diffDate(timeVal, true) - $this.style.display = 'inline' - }) - } - - const unRefreshFn = function () { - window.addEventListener('resize', () => { - adjustMenu(false) - btf.isHidden(document.getElementById('toggle-menu')) && mobileSidebarOpen && sidebarFn.close() - }) - - document.getElementById('menu-mask').addEventListener('click', e => { - sidebarFn.close() - }) - - clickFnOfSubMenu() - GLOBAL_CONFIG.islazyload && lazyloadImg() - GLOBAL_CONFIG.copyright !== undefined && addCopyright() - } - - window.refreshFn = function () { - initAdjust() - - if (GLOBAL_CONFIG_SITE.isPost) { - GLOBAL_CONFIG.noticeOutdate !== undefined && addPostOutdateNotice() - GLOBAL_CONFIG.relativeDate.post && relativeDate(document.querySelectorAll('#post-meta time')) - } else { - GLOBAL_CONFIG.relativeDate.homepage && relativeDate(document.querySelectorAll('#recent-posts time')) - GLOBAL_CONFIG.runtime && addRuntime() - addLastPushDate() - toggleCardCategory() - } - - scrollFnToDo() - GLOBAL_CONFIG_SITE.isHome && scrollDownInIndex() - addHighlightTool() - GLOBAL_CONFIG.isPhotoFigcaption && addPhotoFigcaption() - scrollFn() - - const $jgEle = document.querySelectorAll('#article-container .fj-gallery') - $jgEle.length && runJustifiedGallery($jgEle) - - runLightbox() - addTableWrap() - clickFnOfTagHide() - tabsFn.clickFnOfTabs() - tabsFn.backToTop() - switchComments() - document.getElementById('toggle-menu').addEventListener('click', () => { - sidebarFn.open() - }) - } - - refreshFn() - unRefreshFn() -}) diff --git a/templates/assets/js/main.js b/templates/assets/js/main.js index 5bbe257d..9e3f7c8a 100644 --- a/templates/assets/js/main.js +++ b/templates/assets/js/main.js @@ -31,105 +31,118 @@ document.addEventListener("DOMContentLoaded", function () { // 滚动处理 function scrollFn() { - let a; - let c; - let r; - let s; - let l; - let d; - const $rightside = document.getElementById("rightside"); + const innerHeight = window.innerHeight + 56; - document.body.scrollHeight <= innerHeight - ? ($rightside.style.cssText = "opacity: 1; transform: translateX(-38px)") - : ((c = !(a = 0)), - (r = document.getElementById("page-header")), - document.getElementById("guli_top"), - (s = document.getElementById("cookies-window")), - (l = "function" == typeof chatBtnHide), - (d = "function" == typeof chatBtnShow), - window.addEventListener( - "scroll", - btf.throttle(function (t) { - var e, - n, - o = window.scrollY || document.documentElement.scrollTop, - i = ((n = a < (e = o)), (a = e), n); - 56 < o - ? (i - ? (r.classList.contains("nav-visible") && - r.classList.remove("nav-visible"), - d && !0 === c && (chatBtnHide(), (c = !1))) - : (r.classList.contains("nav-visible") || - r.classList.add("nav-visible"), - l && !1 === c && (chatBtnShow(), (c = !0))), - r.classList.add("nav-fixed"), - s.classList.add("cw-hide"), - "0" === - window.getComputedStyle($rightside).getPropertyValue("opacity") && - ($rightside.style.cssText = - "opacity: 1; transform: translateX(-38px)")) - : (0 === o && r.classList.remove("nav-fixed", "nav-visible"), - ($rightside.style.cssText = "opacity: ''; transform: ''")), - document.body.scrollHeight <= innerHeight && - ($rightside.style.cssText = "opacity: 1; transform: translateX(-38px)"); - }, 200) - )); + if (document.body.scrollHeight <= innerHeight) { + return + } + + // 滚动方向 + function scrollDirection(currentTop) { + const result = currentTop > initTop // true is down & false is up + initTop = currentTop + return result + } + + let initTop = 0; + let $header = document.getElementById("page-header"); + let $cookies = document.getElementById("cookies-window"); + + window.scrollCollect = btf.throttle(function () { + + let currentTop = window.scrollY || document.documentElement.scrollTop; + let isDown = scrollDirection(currentTop); + + if (56 < currentTop) { + // 向下滚动 + if (isDown) { + // 隐藏 nav + if ($header.classList.contains("nav-visible")) { + $header.classList.remove("nav-visible"); + } + } else { + if (!$header.classList.contains("nav-visible")) { + $header.classList.add("nav-visible") + } + } + $header.classList.add("nav-fixed") + $cookies.classList.add("cw-hide") + } else { + if (0 === currentTop) { + $header.classList.remove("nav-fixed", "nav-visible") + } + } + }, 200) + + window.addEventListener('scroll', scrollCollect) } - function scrollFnToDo() { - const $cardTocLayout = document.getElementById("card-toc"); - const $cardToc = $cardTocLayout.getElementsByClassName("toc-content")[0]; - const $tocLink = $cardToc.querySelectorAll(".toc-link"); - const $article = document.getElementById("article-container"); - window.tocScrollFn = function () { - return btf.throttle(function () { - const currentTop = window.scrollY || document.documentElement.scrollTop; - scrollPercent(currentTop) - findHeadPosition(currentTop); - }, 100)(); - } - window.addEventListener("scroll", tocScrollFn); + // 滚动处理 + const scrollFnToDo = function () { + let $cardTocLayout = document.getElementById("card-toc"); + let $cardToc = $cardTocLayout.getElementsByClassName("toc-content")[0]; + let $tocLink = $cardToc.querySelectorAll(".toc-link"); + let $article = document.getElementById("article-container"); - function scrollPercent(currentTop) { + + const scrollPercent = function (currentTop) { const docHeight = $article.clientHeight; const winHeight = document.documentElement.clientHeight; const headerHeight = $article.offsetTop; - const scrollPercent = (currentTop - headerHeight) / (winHeight < docHeight ? docHeight - winHeight : document.documentElement.scrollHeight - winHeight); + const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight) + const scrollPercent = (currentTop - headerHeight) / (contentMath); const scrollPercentRounded = Math.round(100 * scrollPercent); const percentage = 100 < scrollPercentRounded ? 100 : scrollPercentRounded <= 0 ? 0 : scrollPercentRounded; $cardToc.setAttribute("progress-percentage", percentage); } - function close() { - $cardTocLayout.style.animation = "toc-close .2s"; - setTimeout(function () { - $cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''"; - }, 100); - } - - function open() { - $cardTocLayout.style.cssText = "animation: toc-open .3s; opacity: 1; right: 45px"; - } - - // document.getElementById("mobile-toc-button") .addEventListener("click", function () { - ("0" === window.getComputedStyle($cardTocLayout).getPropertyValue("opacity") ? open() : close())(); + if ("0" === window.getComputedStyle($cardTocLayout).getPropertyValue("opacity")) { + window.mobileToc.open(); + } else { + window.mobileToc.close(); + } }); + + window.mobileToc = { + open: () => { + $cardTocLayout.style.cssText = "animation: toc-open .3s; opacity: 1; right: 45px"; + }, + + close: () => { + $cardTocLayout.style.animation = "toc-close .2s" + setTimeout(function () { + $cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''"; + }, 100); + } + } + // toc 元素点击 $cardToc.addEventListener("click", e => { e.preventDefault(); - const $target = e.target.classList.contains("toc-link") ? e.target : e.target.parentElement; - btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI($target.getAttribute("href")).replace("#", ""))), 300); - window.innerWidth < 900 && close(); + const target = e.target.classList.contains("toc-link") ? e.target : e.target.parentElement; + + btf.scrollToDest( + btf.getEleTop( + document.getElementById( + decodeURI(target.getAttribute("href")).replace("#", "") + ) + ), + 300 + ); + if (window.innerWidth < 900) { + window.mobileToc.close(); + } }); // find head position & add active class const list = $article.querySelectorAll("h1,h2,h3,h4,h5,h6"); let detectItem = ""; const findHeadPosition = function (top) { + if (0 === $tocLink.length || 0 === top) { - return false; + return false } let currentId = ""; @@ -138,75 +151,95 @@ document.addEventListener("DOMContentLoaded", function () { list.forEach(function (ele, index) { if (top > btf.getEleTop(ele) - 80) { currentId = "#" + encodeURI(ele.getAttribute("id")); - currentIndex = index; + currentIndex = index } - }); + }) if (detectItem === currentIndex) { - return; - } - - $cardToc.querySelectorAll(".active").forEach(function (i) { - i.classList.remove("active"); - }); - - if ("" === currentId) { return } - detectItem = currentIndex; + detectItem = currentIndex - const currentActive = $tocLink[currentIndex]; - currentActive.classList.add("active"); + $cardToc.querySelectorAll(".active").forEach(i => { + i.classList.remove("active") + }) - setTimeout(function () { - autoScrollToc(currentActive); - }, 0); + if (currentId === "") { + return + } + + const currentActive = $tocLink[currentIndex] + currentActive.classList.add("active") + + setTimeout(() => { + autoScrollToc(currentActive) + }, 0) + + if (isExpand) return + let parent = currentActive.parentNode for (; !parent.matches(".toc"); parent = parent.parentNode) { if (parent.matches("li")) parent.classList.add("active") } - }; - - - function autoScrollToc(item) { - const activePosition = item.getBoundingClientRect().top - const sidebarScrollTop = $cardToc.scrollTop - if (activePosition > (document.documentElement.clientHeight - 100)) { - $cardToc.scrollTop = sidebarScrollTop + 150 - } - if (activePosition < 100) { - $cardToc.scrollTop = sidebarScrollTop - 150 - } } + window.tocScrollFn = function () { + return btf.throttle(function () { + let currentTop = window.scrollY || document.documentElement.scrollTop; + scrollPercent(currentTop) + findHeadPosition(currentTop); + }, 100)(); + }; + window.addEventListener("scroll", tocScrollFn); + }; + + const tabsFn = { + clickFnOfTabs() { + document + .querySelectorAll("#article-container .tab > button") + .forEach(function (item) { + item.addEventListener("click", function (t) { + const $tabItem = this.parentNode; + if (!$tabItem.classList.contains("active")) { + const $tabContent = $tabItem.parentNode.nextElementSibling + const $siblings = btf.siblings($tabItem, ".active")[0] + $siblings && $siblings.classList.remove("active") + $tabItem.classList.add("active") + const tabId = this.getAttribute("data-href").replace("#", "") + const childList = [...$tabContent.children] + childList.forEach(function (item) { + item.id === tabId ? item.classList.add("active") : item.classList.remove("active"); + }) + } + }) + }); + }, + backToTop() { + document.querySelectorAll("#article-container .tabs .tab-to-top") + .forEach(function (t) { + t.addEventListener("click", function () { + btf.scrollToDest(btf.getEleTop(btf.getParents(this, ".tabs")), 300); + }); + }); + } } - window.refreshFn = function () { + initAdjust(); + scrollFnToDo(); scrollFn(); - }; - refreshFn(); + tabsFn.clickFnOfTabs(); + tabsFn.backToTop(); + } - - window.addEventListener("resize", adjustMenu); - window.addEventListener("orientationchange", function () { - setTimeout(adjustMenu, 100) - }); - - document.querySelectorAll("#sidebar-menus .expand").forEach(function (t) { - t.addEventListener("click", function () { - this.classList.toggle("hide"); - var t = this.parentNode.nextElementSibling; - btf.isHidden(t) ? t.style.display = "block" : t.style.display = "none" - }) - }); + refreshFn() window.addEventListener("touchmove", function (t) { document.querySelectorAll("#nav .menus_item_child").forEach(function (t) { - btf.isHidden(t) || (t.style.display = "none") - }) - }); -}); \ No newline at end of file + btf.isHidden(t) || (t.style.display = "none"); + }); + }) +}); diff --git a/templates/assets/js/man.heo.js b/templates/assets/js/man.heo.js deleted file mode 100644 index 9df470ff..00000000 --- a/templates/assets/js/man.heo.js +++ /dev/null @@ -1,327 +0,0 @@ -"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") - } - - function E() { - var t, e, n, c, r, o, s, l, d, u, i, f, m, a = GLOBAL_CONFIG.highlight; - - function h(t, e, n) { - var o, i, a = document.createDocumentFragment(); - r && ((o = document.createElement("div")).className = "highlight-tools ".concat(u), o.innerHTML = l + t + d, o.addEventListener("click", f), a.appendChild(o)), c && e.offsetHeight > c + 30 && ((i = document.createElement("div")).className = "code-expand-btn", i.innerHTML = '', i.addEventListener("click", m), a.appendChild(i)), "hl" === n ? e.insertBefore(a, e.firstChild) : e.parentNode.insertBefore(a, e) - } - - a && (t = a.highlightCopy, e = a.highlightLang, n = GLOBAL_CONFIG_SITE.isHighlightShrink, c = a.highlightHeightLimit, r = t || e || void 0 !== n, o = "highlighjs" === a.plugin ? document.querySelectorAll("figure.highlight") : document.querySelectorAll('pre[class*="language-"]'), (r || c) && o.length && (s = "prismjs" === a.plugin, u = !(d = l = "") === n ? "closed" : "", void 0 !== n && (l = '')), t && (d = '
'), i = function (t) { - var e = t.parentNode; - e.classList.add("copy-true"); - var n = window.getSelection(), o = document.createRange(); - s ? o.selectNodeContents(e.querySelectorAll("pre code")[0]) : o.selectNodeContents(e.querySelectorAll("table .code pre")[0]), n.removeAllRanges(), n.addRange(o); - var i, a; - n.toString(); - i = t.lastChild, document.queryCommandSupported && document.queryCommandSupported("copy") ? (document.execCommand("copy"), void 0 !== GLOBAL_CONFIG.Snackbar ? btf.snackbarShow(GLOBAL_CONFIG.copy.success) : ((a = i.previousElementSibling).innerText = GLOBAL_CONFIG.copy.success, a.style.opacity = 1, setTimeout(function () { - a.style.opacity = 0 - }, 700))) : void 0 !== GLOBAL_CONFIG.Snackbar ? btf.snackbarShow(GLOBAL_CONFIG.copy.noSupport) : i.previousElementSibling.innerText = GLOBAL_CONFIG.copy.noSupport, n.removeAllRanges(), e.classList.remove("copy-true") - }, f = function (t) { - var e, n, o = t.target.classList; - o.contains("expand") ? (n = _toConsumableArray((e = this).parentNode.children).slice(1), e.firstChild.classList.toggle("closed"), btf.isHidden(n[n.length - 1]) ? n.forEach(function (t) { - t.style.display = "block" - }) : n.forEach(function (t) { - t.style.display = "none" - })) : o.contains("copy-button") && i(this) - }, m = function () { - this.classList.toggle("expand-done") - }, e ? s ? o.forEach(function (t) { - var e = t.getAttribute("data-language") ? t.getAttribute("data-language") : "Code", - n = '
'.concat(e, "
"); - btf.wrap(t, "figure", "", "highlight"), h(n, t) - }) : o.forEach(function (t) { - var e = t.getAttribute("class").split(" ")[1]; - "plain" !== e && void 0 !== e || (e = "Code"), h('
'.concat(e, "
"), t, "hl") - }) : s ? o.forEach(function (t) { - btf.wrap(t, "figure", "", "highlight"), h("", t) - }) : o.forEach(function (t) { - h("", t, "hl") - }))) - } - - 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 - }) - } - - 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 A() { - var a, c, r, s, l, d, u = document.getElementById("rightside"), f = window.innerHeight + 56; - document.body.scrollHeight <= f ? u.style.cssText = "opacity: 1; transform: translateX(-38px)" : (c = !(a = 0), r = document.getElementById("page-header"), document.getElementById("guli_top"), s = document.getElementById("cookies-window"), l = "function" == typeof chatBtnHide, d = "function" == typeof chatBtnShow, window.addEventListener("scroll", btf.throttle(function (t) { - var e, n, o = window.scrollY || document.documentElement.scrollTop, i = (n = a < (e = o), a = e, n); - 56 < o ? (i ? (r.classList.contains("nav-visible") && r.classList.remove("nav-visible"), d && !0 === c && (chatBtnHide(), c = !1)) : (r.classList.contains("nav-visible") || r.classList.add("nav-visible"), l && !1 === c && (chatBtnShow(), c = !0)), r.classList.add("nav-fixed"), s.classList.add("cw-hide"), "0" === window.getComputedStyle(u).getPropertyValue("opacity") && (u.style.cssText = "opacity: 1; transform: translateX(-38px)")) : (0 === o && r.classList.remove("nav-fixed", "nav-visible"), u.style.cssText = "opacity: ''; transform: ''"), document.body.scrollHeight <= f && (u.style.cssText = "opacity: 1; transform: translateX(-38px)") - }, 200))) - } - - function S() { - var t = document.getElementById("card-toc"), r = t.getElementsByClassName("toc-content")[0], - s = r.querySelectorAll(".toc-link"), c = document.getElementById("article-container"); - window.tocScrollFn = function () { - return btf.throttle(function () { - var t = window.scrollY || document.documentElement.scrollTop; - e(t), i(t) - }, 100)() - }, window.addEventListener("scroll", tocScrollFn); - var e = function (t) { - var e = c.clientHeight, n = document.documentElement.clientHeight, - o = (t - c.offsetTop) / (n < e ? e - n : document.documentElement.scrollHeight - n), - i = Math.round(100 * o), a = 100 < i ? 100 : i <= 0 ? 0 : i; - r.setAttribute("progress-percentage", a) - }, l = GLOBAL_CONFIG.isanchor, n = function () { - t.style.cssText = "animation: toc-open .3s; opacity: 1; right: 45px" - }, o = function () { - t.style.animation = "toc-close .2s", setTimeout(function () { - t.style.cssText = "opacity:''; animation: ''; right: ''" - }, 100) - }; - document.getElementById("mobile-toc-button").addEventListener("click", function () { - ("0" === window.getComputedStyle(t).getPropertyValue("opacity") ? n : o)() - }), r.addEventListener("click", function (t) { - t.preventDefault(); - 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() - }); - var d = c.querySelectorAll("h1,h2,h3,h4,h5,h6"), u = "", i = function (n) { - if (0 === s.length || 0 === n) return !1; - var t, e, o = "", i = ""; - if (d.forEach(function (t, e) { - n > btf.getEleTop(t) - 80 && (o = "#" + encodeURI(t.getAttribute("id")), i = e) - }), u !== i) { - if (l && (t = o, window.history.replaceState && t !== window.location.hash && (t = t || location.pathname, e = GLOBAL_CONFIG_SITE.title, window.history.replaceState({ - url: location.href, - title: e - }, e, t))), "" === o) return r.querySelectorAll(".active").forEach(function (t) { - t.classList.remove("active") - }), void (u = i); - u = i, r.querySelectorAll(".active").forEach(function (t) { - t.classList.remove("active") - }); - var a = s[i]; - a.classList.add("active"), setTimeout(function () { - var t, e; - t = a.getBoundingClientRect().top, e = r.scrollTop, t > document.documentElement.clientHeight - 100 && (r.scrollTop = e + 150), t < 100 && (r.scrollTop = e - 150) - }, 0); - for (var c = a.parentNode; !c.matches(".toc"); c = c.parentNode) c.matches("li") && c.classList.add("active") - } - } - } - - var d = !1, e = function () { - var e = document.body; - e.classList.add("read-mode"); - var n = document.createElement("button"); - n.type = "button", n.className = "fas fa-sign-out-alt exit-readmode", e.appendChild(n), n.addEventListener("click", function t() { - e.classList.remove("read-mode"), n.remove(), n.removeEventListener("click", t) - }) - }, n = function () { - "light" == ("dark" === document.documentElement.getAttribute("data-theme") ? "dark" : "light") ? (activateDarkMode(), saveToLocal.set("theme", "dark", 2), void 0 !== GLOBAL_CONFIG.Snackbar && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night, !1, 2e3)) : (activateLightMode(), saveToLocal.set("theme", "light", 2), void 0 !== GLOBAL_CONFIG.Snackbar && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day, !1, 2e3)), "function" == typeof utterancesTheme && utterancesTheme(), "object" === ("undefined" == typeof FB ? "undefined" : _typeof(FB)) && window.loadFBComment(), window.DISQUS && document.getElementById("disqus_thread").children.length && setTimeout(function () { - return window.disqusReset() - }, 200) - }, u = function () { - document.getElementById("rightside-config-hide").classList.toggle("show") - }, f = function () { - btf.scrollToDest(0, 500) - }, m = function () { - var t = document.documentElement.classList; - t.contains("hide-aside") ? saveToLocal.set("aside-status", "show", 2) : saveToLocal.set("aside-status", "hide", 2), t.toggle("hide-aside") - }, h = function (t) { - var e = parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--global-font-size")), - n = ""; - if (t) { - if (20 <= e) return; - n = e + 1, document.documentElement.style.setProperty("--global-font-size", n + "px"), document.getElementById("nav").classList.contains("hide-menu") || L(!0) - } else { - if (e <= 10) return; - n = e - 1, document.documentElement.style.setProperty("--global-font-size", n + "px"), document.getElementById("nav").classList.contains("hide-menu") && L(!0) - } - saveToLocal.set("global-font-size", n, 2) - }; - document.getElementById("rightside").addEventListener("click", function (t) { - switch (t.target.id || t.target.parentNode.id) { - case"go-up": - f(); - break; - case"rightside_config": - u(); - break; - case"readmode": - e(); - break; - case"darkmode": - n(); - break; - case"hide-aside-btn": - m(); - break; - case"font-plus": - h(!0); - break; - case"font-minus": - h() - } - }); - - function I(t) { - t.forEach(function (t) { - var e = t, n = e.getAttribute("datetime"); - e.innerText = btf.diffDate(n, !0), e.style.display = "inline" - }) - } - - var g, O = function () { - document.querySelectorAll("#article-container .tab > button").forEach(function (t) { - t.addEventListener("click", function (t) { - var e, n, o, i, a = this.parentNode; - a.classList.contains("active") || (e = a.parentNode.nextElementSibling, (n = btf.siblings(a, ".active")[0]) && n.classList.remove("active"), a.classList.add("active"), o = this.getAttribute("data-href").replace("#", ""), _toConsumableArray(e.children).forEach(function (t) { - t.id === o ? t.classList.add("active") : t.classList.remove("active") - }), 0 < (i = e.querySelectorAll("#".concat(o, " .justified-gallery"))).length && btf.initJustifiedGallery(i)) - }) - }) - }, G = function () { - document.querySelectorAll("#article-container .tabs .tab-to-top").forEach(function (t) { - t.addEventListener("click", function () { - btf.scrollToDest(btf.getEleTop(btf.getParents(this, ".tabs")), 300) - }) - }) - }; - window.refreshFn = function () { - var t, e, n, o, i, a, c, r, s, l, d, u, f, m, h, g, y, p, b; - - function v() { - 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) { - t.addEventListener("click", function (t) { - t.preventDefault(); - this.classList.toggle("expand"); - var e = this.parentNode.nextElementSibling; - btf.isHidden(e) ? e.style.display = "block" : e.style.display = "none" - }) - })), l = document.getElementById("toggle-menu"), d = document.getElementById("sidebar-menus"), u = document.getElementById("menu-mask"), f = document.body, l.addEventListener("click", function () { - btf.sidebarPaddingR(), f.style.overflow = "hidden", btf.fadeIn(u, .5), d.classList.add("open") - }), u.addEventListener("click", function (t) { - d.classList.contains("open") && v() - }), window.addEventListener("resize", function (t) { - btf.isHidden(l) && d.classList.contains("open") && v() - }), !GLOBAL_CONFIG_SITE.isHome || (m = document.getElementById("scroll-down")) && m.addEventListener("click", function () { - btf.scrollToDest(document.getElementById("content-inner").offsetTop, 300) - }), E(), GLOBAL_CONFIG.isPhotoFigcaption && document.querySelectorAll("#article-container img").forEach(function (t) { - var e, n = t.parentNode; - n.parentNode.classList.contains("justified-gallery") || ((e = document.createElement("div")).className = "img-alt is-center", e.textContent = t.getAttribute("alt"), n.insertBefore(e, t.nextSibling)) - }), w(), "mediumZoom" === GLOBAL_CONFIG.lightbox && (h = mediumZoom(document.querySelectorAll("#article-container :not(a)>img"))).on("open", function (t) { - var e = "dark" === document.documentElement.getAttribute("data-theme") ? "#121212" : "#fff"; - h.update({background: e}) - }), A(), (g = document.querySelectorAll("#article-container :not(.highlight) > table, #article-container > table")).length && g.forEach(function (t) { - btf.wrap(t, "div", "", "table-wrap") - }), (y = document.querySelectorAll("#article-container .hide-button")).length && y.forEach(function (t) { - t.addEventListener("click", function (t) { - var e = this.nextElementSibling; - this.classList.toggle("open"), this.classList.contains("open") && 0 < e.querySelectorAll(".justified-gallery").length && btf.initJustifiedGallery(e.querySelectorAll(".justified-gallery")) - }) - }), O(), G(), p = !1, (b = document.querySelector("#comment-switch > .switch-btn")) && b.addEventListener("click", function () { - this.classList.toggle("move"), document.querySelectorAll("#post-comment > .comment-wrap > div").forEach(function (t) { - btf.isHidden(t) ? t.style.cssText = "display: block;animation: tabshow .5s" : t.style.cssText = "display: none;animation: ''" - }), p || "function" != typeof loadOtherComment || (p = !0, loadOtherComment()) - }) - }, refreshFn(), window.addEventListener("resize", L), window.addEventListener("orientationchange", function () { - setTimeout(L(!0), 100) - }), document.querySelectorAll("#sidebar-menus .expand").forEach(function (t) { - t.addEventListener("click", function () { - this.classList.toggle("hide"); - var t = this.parentNode.nextElementSibling; - btf.isHidden(t) ? t.style.display = "block" : t.style.display = "none" - }) - }), window.addEventListener("touchmove", function (t) { - document.querySelectorAll("#nav .menus_item_child").forEach(function (t) { - btf.isHidden(t) || (t.style.display = "none") - }) - }), GLOBAL_CONFIG.islazyload && (window.lazyLoadInstance = new LazyLoad({ - elements_selector: "img", - threshold: 0, - data_src: "lazy-src" - })), void 0 !== GLOBAL_CONFIG.copyright && (g = GLOBAL_CONFIG.copyright, document.body.oncopy = function (t) { - t.preventDefault(); - var e = window.getSelection(0).toString(), - n = e.length > g.limitCount ? e + "\n\n\n" + g.languages.author + "\n" + g.languages.link + window.location.href + "\n" + g.languages.source + "\n" + g.languages.info : e; - return t.clipboardData ? t.clipboardData.setData("text", n) : window.clipboardData.setData("text", n) - }) -}); \ No newline at end of file diff --git a/templates/assets/js/utils.js b/templates/assets/js/utils.js index 12478cf2..45d213fb 100644 --- a/templates/assets/js/utils.js +++ b/templates/assets/js/utils.js @@ -184,4 +184,15 @@ const btf = { return actualTop }, + + updateAnchor: (anchor) => { + if (anchor !== window.location.hash) { + if (!anchor) anchor = location.pathname + const title = GLOBAL_CONFIG_SITE.title + window.history.replaceState({ + url: location.href, + title: title + }, title, anchor) + } + } }; \ No newline at end of file diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js index cac2147f..f079ab97 100644 --- a/templates/assets/zhheo/blogex.js +++ b/templates/assets/zhheo/blogex.js @@ -263,7 +263,7 @@ $(window).on("keyup", function (e) { }); document.addEventListener("pjax:send", function () { - //heo.showLoading() + heo.showLoading() }); document.addEventListener("load", function () { @@ -283,11 +283,3 @@ window.onscroll = function () { }; - -function imgError(url) { - $("img").on("error", function () { - $(this).attr("src", url); - }); -} - -