mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
feat: gallery 標籤外掛增加 json 獲取
feat: 本地搜索,點擊文章內容也會跳轉到相應頁面 feat: 添加 docsearch feat: 標籤頁支持配置 orderby 和 order 參數 feat: card_tags 可配置 orderby 和 order 參數 fix: 修復本地搜索,輸入 ?d 報錯的 bug closed #1192 fix: 修復 waline 在 pjax 模式下 css 沒有加載的 bug fix: 修復 artalk 最新評論無法加載 closed #1191 fix: 修復 card_author 和 card_announcement 設為 false 後,aside 卡片沒有間距的 bug closed #1174 improvement: getCSS 重構
This commit is contained in:
@@ -243,8 +243,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
return str
|
||||
}
|
||||
|
||||
const lazyloadFn = (i, arr) => {
|
||||
const loadItem = i.getAttribute('data-limit')
|
||||
const lazyloadFn = (i, arr, limit) => {
|
||||
const loadItem = limit
|
||||
const arrLength = arr.length
|
||||
if (arrLength > loadItem) i.insertAdjacentHTML('beforeend', htmlStr(arr.splice(0, loadItem)))
|
||||
else {
|
||||
@@ -254,29 +254,43 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
return arrLength > loadItem ? loadItem : arrLength
|
||||
}
|
||||
|
||||
ele.forEach(item => {
|
||||
const arr = JSON.parse(item.querySelector('.gallery-data').textContent)
|
||||
const fetchUrl = async (url) => {
|
||||
const response = await fetch(url)
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
const runJustifiedGallery = (item, arr) => {
|
||||
if (!item.classList.contains('lazyload')) item.innerHTML = htmlStr(arr)
|
||||
else {
|
||||
lazyloadFn(item, arr)
|
||||
const limit = item.getAttribute('data-limit')
|
||||
lazyloadFn(item, arr, limit)
|
||||
const clickBtnFn = () => {
|
||||
const lastItemLength = lazyloadFn(item, arr)
|
||||
const lastItemLength = lazyloadFn(item, arr, limit)
|
||||
fjGallery(item, 'appendImages', item.querySelectorAll(`.fj-gallery-item:nth-last-child(-n+${lastItemLength})`))
|
||||
btf.loadLightbox(item.querySelectorAll('img'))
|
||||
lastItemLength < limit && item.nextElementSibling.removeEventListener('click', clickBtnFn)
|
||||
}
|
||||
item.nextElementSibling.addEventListener('click', clickBtnFn)
|
||||
}
|
||||
})
|
||||
btf.initJustifiedGallery(item)
|
||||
btf.loadLightbox(item.querySelectorAll('img'))
|
||||
}
|
||||
|
||||
const addJustifiedGallery = () => {
|
||||
ele.forEach(item => {
|
||||
item.classList.contains('url')
|
||||
? fetchUrl(item.textContent).then(res => { runJustifiedGallery(item, res) })
|
||||
: runJustifiedGallery(item, JSON.parse(item.textContent))
|
||||
})
|
||||
}
|
||||
|
||||
if (window.fjGallery) {
|
||||
setTimeout(() => { btf.initJustifiedGallery(ele) }, 100)
|
||||
addJustifiedGallery()
|
||||
return
|
||||
}
|
||||
|
||||
getCSS(`${GLOBAL_CONFIG.source.justifiedGallery.css}`)
|
||||
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
||||
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(addJustifiedGallery)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user