fix: 修復開啟gitalk評論數後與toc衝突的bug close #462

fix: 修復jquery在一些介面仍然載入問題
fix: 修復medium zoom 報錯的 bug
This commit is contained in:
Jerry
2020-12-27 15:51:00 +08:00
parent eb823b0a2d
commit 4a69c623fc
3 changed files with 33 additions and 33 deletions

View File

@@ -77,7 +77,7 @@
else if whichCount === 'Gitalk'
+countBlock
a(href=url_for(page.path) + '#post-comment')
span.gitalk-#card-toc
span.gitalk-comment-count
else if whichCount === 'Twikoo'
+countBlock
a(href=url_for(page.path) + '#post-comment')

View File

@@ -1,6 +1,6 @@
{
"name": "hexo-theme-butterfly",
"version": "3.4.1",
"version": "3.4.2",
"description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json",
"scripts": {

View File

@@ -247,40 +247,38 @@ document.addEventListener('DOMContentLoaded', function () {
* fancybox和 mediumZoom
*/
const addFancybox = function (ele) {
if (ele.length) {
const runFancybox = (ele) => {
ele.each(function (i, o) {
const $this = $(o)
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
const dataCaption = $this.attr('alt') || ''
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`)
})
const runFancybox = (ele) => {
ele.each(function (i, o) {
const $this = $(o)
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
const dataCaption = $this.attr('alt') || ''
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`)
})
$().fancybox({
selector: '[data-fancybox]',
loop: true,
transitionEffect: 'slide',
protect: true,
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
hash: false
})
}
$().fancybox({
selector: '[data-fancybox]',
loop: true,
transitionEffect: 'slide',
protect: true,
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
hash: false
})
}
if (typeof $.fancybox === 'undefined') {
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
runFancybox($(ele))
})
} else {
if (typeof $.fancybox === 'undefined') {
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
runFancybox($(ele))
}
})
} else {
runFancybox($(ele))
}
}
const addMediumZoom = () => {
const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a)>img'))
zoom.on('open', e => {
const photoBg = $(document.documentElement).attr('data-theme') === 'dark' ? '#121212' : '#fff'
const photoBg = document.documentElement.getAttribute('data-theme') === 'dark' ? '#121212' : '#fff'
zoom.update({
background: photoBg
})
@@ -288,15 +286,17 @@ document.addEventListener('DOMContentLoaded', function () {
}
const jqLoadAndRun = () => {
const isFancybox = GLOBAL_CONFIG.lightbox === 'fancybox'
const $fancyboxEle = isFancybox ? document.querySelectorAll('#article-container :not(a):not(.gallery-group) > img, #article-container > img') : null
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
? document.querySelectorAll('#article-container :not(a):not(.gallery-group) > img, #article-container > img')
: []
const fbLengthNoZero = $fancyboxEle.length > 0
const $jgEle = document.querySelectorAll('#article-container .justified-gallery')
const jgEleLength = $jgEle.length
const jgLengthNoZero = $jgEle.length > 0
if (jgEleLength || $fancyboxEle !== null) {
if (jgLengthNoZero || fbLengthNoZero) {
btf.isJqueryLoad(() => {
jgEleLength && runJustifiedGallery($jgEle)
isFancybox && addFancybox($fancyboxEle)
jgLengthNoZero && runJustifiedGallery($jgEle)
fbLengthNoZero && addFancybox($fancyboxEle)
})
}
}