Skip to content

Commit

Permalink
[opt] fancybox 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xaoxuu committed Jan 21, 2024
1 parent f51bf78 commit c640310
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 64 deletions.
8 changes: 4 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ plugins:
lazyload:
enable: true # [hexo clean && hexo s] is required after changing this value.
js: https://gcore.jsdelivr.net/npm/vanilla-lazyload@17.8.3/dist/lazyload.min.js
transition: blur # blur, fade
transition: fade # blur, fade

# https://scrollrevealjs.org/api/reveal.html
scrollreveal:
Expand All @@ -395,12 +395,12 @@ plugins:
# available for {% image xxx %}
fancybox:
enable: true
js: https://gcore.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.umd.js
css: https://gcore.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.css
js: https://cdn.bootcdn.net/ajax/libs/fancyapps-ui/5.0.22/fancybox/fancybox.umd.min.js
css: https://cdn.bootcdn.net/ajax/libs/fancyapps-ui/5.0.22/fancybox/fancybox.min.css
# 可以处理评论区的图片(不支持 iframe 类评论系统)例如:
# 使用twikoo评论可以写: .tk-content img:not([class*="emo"])
# 使用waline评论可以写: #waline_container .vcontent img
selector: .fancybox img # 多个选择器用英文逗号隔开
selector: # 多个选择器用英文逗号隔开

# swiper
swiper:
Expand Down
7 changes: 5 additions & 2 deletions scripts/tags/lib/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

'use strict'

var index = 0

function img(src, alt) {
let img = ''
img += `<img src="${src}"`
img += `<img data-fancybox="gallery-${index}" src="${src}"`
if (alt?.length > 0) {
img += ` alt="${alt}"`
}
Expand All @@ -44,7 +46,8 @@ module.exports = ctx => function(args, content) {
if (args.layout == 'flow') {
layoutType = 'flow'
}
el += `<div class="tag-plugin gallery fancybox ${layoutType}-box" ${ctx.args.joinTags(args, ['size', 'ratio']).join(' ')}>`
index += 1
el += `<div class="tag-plugin gallery ${layoutType}-box" ${ctx.args.joinTags(args, ['size', 'ratio']).join(' ')}>`
const img_mds = content.split('\n').filter(item => item.trim().length > 0)
for (let md of img_mds) {
const matches = md.match(/\!\[(.*?)\]\((.*?)\)/i)
Expand Down
8 changes: 4 additions & 4 deletions scripts/tags/lib/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module.exports = ctx => function(args) {
}
// 覆盖配置
if (args.fancybox && args.fancybox.length > 0) {
if (args.fancybox == 'true') {
fancybox = true
} else if (args.fancybox == 'false') {
if (args.fancybox == 'false') {
fancybox = false
} else {
fancybox = args.fancybox
}
}
}
Expand All @@ -40,7 +40,7 @@ module.exports = ctx => function(args) {
img += ' alt="' + alt + '"'
}
if (fancybox) {
img += ' fancybox="true"'
img += ` data-fancybox="${fancybox}"`
}
if (style.length > 0) {
img += ' style="' + style + '"'
Expand Down
6 changes: 1 addition & 5 deletions source/css/_plugins/fancybox.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
img[fancybox='true']
img[data-fancybox]
cursor: zoom-in

.fancybox
img
cursor: zoom-in
39 changes: 12 additions & 27 deletions source/css/_plugins/lazyload.styl
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
trans-cover($p, $t = 0.28s)
trans2pro: transform 0.5s $p $t
trans-site($p)
trans2: box-shadow transform $p
trans-user($p)
trans3: box-shadow transform $p

if hexo-config('plugins.lazyload.transition') == 'blur'
img.lazy
trans-cover filter
img.lazy
&:not(.loaded)
opacity: 0
&.loaded,&.error
opacity: 1
if hexo-config('plugins.lazyload.transition') == 'blur'
trans1 all 0.75s
&:not(.loaded)
filter blur(8px)
-webkit-filter blur(8px)
filter blur(50px)
-webkit-filter blur(50px)
&.loaded,&.error
filter none
-webkit-filter none
.site-card .card-link>img
trans-site filter
.user-card .card-link>img
trans-user filter
else
img.lazy
trans-cover opacity 0.5s
&:not(.loaded)
opacity: 0
&.loaded,&.error
opacity: 1
.site-card .card-link>img
trans-site opacity
.user-card .card-link>img
trans-user opacity
else
trans1 all 0.38s

23 changes: 4 additions & 19 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,9 @@ if (stellar.plugins.preload) {
}
}

function loadFancybox() {
stellar.loadCSS(stellar.plugins.fancybox.css);
stellar.loadScript(stellar.plugins.fancybox.js, { defer: true }).then(function () {
Fancybox.bind(selector, {
groupAll: true,
hideScrollbar: false,
Thumbs: {
autoStart: false,
},
caption: function (fancybox, carousel, slide) {
return slide.$trigger.alt || null
}
});
})
}
// fancybox
if (stellar.plugins.fancybox) {
let selector = 'img[fancybox]:not(.error)';
let selector = '[data-fancybox]:not(.error)';
if (stellar.plugins.fancybox.selector) {
selector += `, ${stellar.plugins.fancybox.selector}`
}
Expand All @@ -332,16 +317,16 @@ if (stellar.plugins.fancybox) {
}
}
if (needFancybox) {
console.log('need fancy', selector, document.querySelectorAll(selector) );
stellar.loadCSS(stellar.plugins.fancybox.css);
stellar.loadScript(stellar.plugins.fancybox.js, { defer: true }).then(function () {
Fancybox.bind(selector, {
groupAll: true,
hideScrollbar: false,
Thumbs: {
autoStart: false,
},
caption: function (fancybox, carousel, slide) {
return slide.$trigger.alt || null
caption: (fancybox, slide) => {
return slide.triggerEl.alt || null
}
});
})
Expand Down
5 changes: 2 additions & 3 deletions source/js/plugins/memos.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ const MemosJS = {
cell += '<div class="tag-plugin image">';
for (let img of imgs) {
if (img.externalLink?.length > 0) {
cell += `<div class="image-bg"><img src="${img.externalLink}" fancybox="true"></div>`;
cell += `<div class="image-bg"><img src="${img.externalLink}" data-fancybox="memos"></div>`;
} else {
cell += `<div class="image-bg"><img src="https://${cfg.host}/o/r/${img.id}" fancybox="true"></div>`;
cell += `<div class="image-bg"><img src="https://${cfg.host}/o/r/${img.id}" data-fancybox="memos"></div>`;
}

}
cell += '</div>';
}
Expand Down

0 comments on commit c640310

Please sign in to comment.