diff --git a/layout/_plugins/fancybox.ejs b/layout/_plugins/fancybox.ejs index 076be32..f3da9af 100644 --- a/layout/_plugins/fancybox.ejs +++ b/layout/_plugins/fancybox.ejs @@ -24,9 +24,9 @@ autoStart: false, }, caption: (fancybox, slide) => { - return slide.triggerEl.alt || null + return slide.triggerEl.alt || slide.triggerEl.dataset.caption || null } }); }) } - \ No newline at end of file + diff --git a/scripts/tags/lib/image.js b/scripts/tags/lib/image.js index 7cbe449..ee981e4 100644 --- a/scripts/tags/lib/image.js +++ b/scripts/tags/lib/image.js @@ -2,7 +2,7 @@ * image.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) * - * {% image src [alt] [width:400px] [bg:#eee] [download:true/false/url] %} + * {% image src [alt] [width:400px] [bg:#eee] [download:true/false/url] [fancybox:true/false/url] %} */ 'use strict' @@ -18,6 +18,7 @@ module.exports = ctx => function(args) { } // fancybox var fancybox = false + var fancyboxHref = null if (ctx.theme.config.plugins.fancybox && ctx.theme.config.plugins.fancybox.enable) { // 主题配置 if (ctx.theme.config.tag_plugins.image && ctx.theme.config.tag_plugins.image.fancybox) { @@ -27,8 +28,11 @@ module.exports = ctx => function(args) { if (args.fancybox && args.fancybox.length > 0) { if (args.fancybox == 'false') { fancybox = false - } else { + } else if (args.fancybox === 'true') { fancybox = args.fancybox + } else { + fancybox = true + fancyboxHref = args.fancybox } } } @@ -36,16 +40,24 @@ module.exports = ctx => function(args) { function img(src, alt, style) { let img = '' img += ' 0) { img += ' style="' + style + '"' } img += '/>' + + if (fancyboxHref) { + a += ` href="${fancyboxHref}">${img}` + return a + } + return img } @@ -87,4 +99,4 @@ module.exports = ctx => function(args) { el += '' return el -} \ No newline at end of file +} diff --git a/source/css/_plugins/fancybox.styl b/source/css/_plugins/fancybox.styl index 4a45238..9a5d3ff 100644 --- a/source/css/_plugins/fancybox.styl +++ b/source/css/_plugins/fancybox.styl @@ -1,2 +1,2 @@ -img[data-fancybox] +img[data-fancybox], a[data-fancybox] cursor: zoom-in