Merge pull request #246 from chengzhongxue/main

评论图片预览
This commit is contained in:
困困鱼 2023-07-08 14:15:44 +08:00 committed by GitHub
commit 6734edfc52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 207 additions and 137 deletions

View File

@ -245,27 +245,27 @@ document.addEventListener('DOMContentLoaded', function () {
* 需要 jQuery
*/
// let detectJgJsLoad = false
// const runJustifiedGallery = function (ele) {
// const $justifiedGallery = $(ele)
// const $imgList = $justifiedGallery.find('img')
// $imgList.unwrap()
// if ($imgList.length) {
// $imgList.each(function (i, o) {
// if ($(o).attr('data-lazy-src')) $(o).attr('src', $(o).attr('data-lazy-src'))
// $(o).wrap('<div></div>')
// })
// }
//
// if (detectJgJsLoad) btf.initJustifiedGallery($justifiedGallery)
// else {
// $('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.justifiedGallery.css}">`)
// $.getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`, function () {
// btf.initJustifiedGallery($justifiedGallery)
// })
// detectJgJsLoad = true
// }
// }
let detectJgJsLoad = false
const runJustifiedGallery = function (ele) {
const $justifiedGallery = $(ele)
const $imgList = $justifiedGallery.find('img')
$imgList.unwrap()
if ($imgList.length) {
$imgList.each(function (i, o) {
if ($(o).attr('data-lazy-src')) $(o).attr('src', $(o).attr('data-lazy-src'))
$(o).wrap('<div></div>')
})
}
if (detectJgJsLoad) btf.initJustifiedGallery($justifiedGallery)
else {
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.justifiedGallery.css}">`)
$.getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`, function () {
btf.initJustifiedGallery($justifiedGallery)
})
detectJgJsLoad = true
}
}
/**
* fancybox和 mediumZoom
@ -317,7 +317,7 @@ document.addEventListener('DOMContentLoaded', function () {
const jqLoadAndRun = () => {
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
? document.querySelectorAll('#article-container :not(a):not(.gallery-group) > img, #article-container > img,.bber-content-img > img')
? document.querySelectorAll('#article-container :not(a):not(.gallery-group):not(.site-card-avatar) > img, #article-container > img,.bber-content-img > img')
: []
const fbLengthNoZero = $fancyboxEle.length > 0
const $jgEle = document.querySelectorAll('#article-container .justified-gallery')

View File

@ -36,43 +36,102 @@ var btf = {
return result;
},
// loadLightbox: ele => {
// const service = GLOBAL_CONFIG.lightbox;
// if (service === "mediumZoom") {
// const zoom = mediumZoom(ele);
// zoom.on("open", e => {
// const photoBg = document.documentElement.getAttribute("data-theme") === "dark" ? "#121212" : "#fff";
// zoom.update({
// background: photoBg,
// });
// });
// }
// if (service === "fancybox") {
// ele.forEach(i => {
// if (i.parentNode.tagName !== "A") {
// const dataSrc = i.dataset.lazySrc || i.src;
// const dataCaption = i.title || i.alt || "";
// btf.wrap(i, "a", {
// href: dataSrc,
// "data-fancybox": "gallery",
// "data-caption": dataCaption,
// "data-thumb": dataSrc,
// });
// }
// });
// if (!window.fancyboxRun) {
// Fancybox.bind("[data-fancybox]", {
// Hash: false,
// Thumbs: {
// autoStart: false,
// },
// });
// window.fancyboxRun = true;
// }
// }
// },
loadLightbox: ele => {
const service = GLOBAL_CONFIG.lightbox;
if (service === "mediumZoom") {
const zoom = mediumZoom(ele);
zoom.on("open", e => {
const photoBg = document.documentElement.getAttribute("data-theme") === "dark" ? "#121212" : "#fff";
zoom.update({
background: photoBg,
});
});
const jqLoadAndRun = () => {
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
? ele
: []
const fbLengthNoZero = $fancyboxEle.length > 0
if (fbLengthNoZero) {
btf.isJqueryLoad(() => {
fbLengthNoZero && addFancybox($fancyboxEle)
})
}
}
if (service === "fancybox") {
ele.forEach(i => {
if (i.parentNode.tagName !== "A") {
const dataSrc = i.dataset.lazySrc || i.src;
const dataCaption = i.title || i.alt || "";
btf.wrap(i, "a", {
href: dataSrc,
"data-fancybox": "gallery",
"data-caption": dataCaption,
"data-thumb": dataSrc,
});
}
});
if (!window.fancyboxRun) {
Fancybox.bind("[data-fancybox]", {
Hash: false,
Thumbs: {
autoStart: false,
},
});
window.fancyboxRun = true;
/**
* fancybox
*/
const addFancybox = function (ele) {
const runFancybox = (ele) => {
ele.each(function (i, o) {
const $this = $(o)
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
const lazyloadSrc1600 = lazyloadSrc + '_1600w'
const dataCaption = $this.attr('alt') || ''
if (lazyloadSrc.indexOf('!blogimg') != -1) {
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="images" data-caption="${dataCaption}" class="fancybox" data-srcset="${lazyloadSrc1600} 1600w"></a>`)
} else {
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="images" data-caption="${dataCaption}" class="fancybox" data-srcset="${lazyloadSrc} 1600w"></a>`)
}
})
$().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 {
runFancybox($(ele))
}
}
jqLoadAndRun()
},
debounce: function (func, wait, immediate) {
let timeout

View File

@ -174,6 +174,17 @@
allPlaylist: [[${theme.config.other.nav_music.all_playlist}]],
navMusicEnable:[[${theme.config.other.nav_musicEnable}]],
isMusic: [[${ htmlType == 'music'}]],
source: {
jQuery: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js',
justifiedGallery: {
js: 'https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js',
css: 'https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/justifiedGallery/3.8.1/css/justifiedGallery.min.css'
},
fancybox: {
js: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/fancybox/3.5.7/jquery.fancybox.min.js',
css: 'https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/fancybox/3.5.7/jquery.fancybox.min.css'
}
},
date_suffix: {
just: '刚刚',
min: '分钟前',

View File

@ -17,7 +17,7 @@
envId: [[${theme.config.comments.twikoos.envId}]],
region: '',
onCommentLoaded: function () {
//- btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.vemoji)'))
btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.vemoji)'))
$("input").focus(function () {
heo_intype = true;
});