From df86dd509a02704d18bc6eace1f9bfe4527c1b89 Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sat, 20 Jul 2019 19:29:13 +0800 Subject: [PATCH 1/8] Add medium-zoom support --- _config.yml | 10 ++++++++++ layout/_scripts/vendors.swig | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/_config.yml b/_config.yml index 57cbdc4bdb..84df1a921e 100644 --- a/_config.yml +++ b/_config.yml @@ -517,6 +517,10 @@ math: # To install 3.x: https://github.com/theme-next/theme-next-fancybox3 fancybox: false +# A JavaScript library for zooming images like Medium. +# Dependencies: https://github.com/theme-next/theme-next-mediumzoom +mediumzoom: false + # Polyfill to remove click delays on browsers with touch UIs. # Dependencies: https://github.com/theme-next/theme-next-fastclick fastclick: false @@ -1005,6 +1009,12 @@ vendors: fancybox: fancybox_css: + # Internal version: 0.4.0 + # See: https://github.com/francoischalifour/medium-zoom + # Example: + # mediumzoom: //cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js + mediumzoom: + # Internal version: 1.0.6 # See: https://github.com/ftlabs/fastclick # Example: diff --git a/layout/_scripts/vendors.swig b/layout/_scripts/vendors.swig index 42ae238061..cb2958636b 100644 --- a/layout/_scripts/vendors.swig +++ b/layout/_scripts/vendors.swig @@ -27,6 +27,10 @@ {% set js_vendors.fancybox = 'fancybox/source/jquery.fancybox.pack.js' %} {% endif %} +{% if theme.mediumzoom %} + {% set js_vendors.mediumzoom = 'mediumzoom/source/jquery.mediumzoom.pack.js' %} +{% endif %} + {% if theme.canvas_nest.enable %} {% if theme.canvas_nest.onmobile %} {% set canvas_nest_uri = url_for(theme.vendors._internal + '/canvas-nest/canvas-nest.min.js') %} From 6f7f9319a0587ca2f4b586f45f904e8cbf4d23fd Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sat, 20 Jul 2019 20:00:13 +0800 Subject: [PATCH 2/8] Update --- _config.yml | 2 +- layout/_partials/head/head.swig | 1 + layout/_scripts/vendors.swig | 2 +- source/js/next-boot.js | 1 + source/js/utils.js | 11 +++++++---- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/_config.yml b/_config.yml index 84df1a921e..1e64e3535c 100644 --- a/_config.yml +++ b/_config.yml @@ -1009,7 +1009,7 @@ vendors: fancybox: fancybox_css: - # Internal version: 0.4.0 + # Internal version: 1.0.4 # See: https://github.com/francoischalifour/medium-zoom # Example: # mediumzoom: //cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js diff --git a/layout/_partials/head/head.swig b/layout/_partials/head/head.swig index fa6ed20f00..ff0527eb25 100644 --- a/layout/_partials/head/head.swig +++ b/layout/_partials/head/head.swig @@ -98,6 +98,7 @@ back2top: {{ theme.back2top | json_encode }}, copycode: {{ theme.codeblock.copy_button | json_encode }}, fancybox: {{ theme.fancybox }}, + mediumzoom: {{ theme.mediumzoom }}, fastclick: {{ theme.fastclick }}, lazyload: {{ theme.lazyload }}, tabs: {{ theme.tabs.enable }}, diff --git a/layout/_scripts/vendors.swig b/layout/_scripts/vendors.swig index cb2958636b..e2fe9a7aff 100644 --- a/layout/_scripts/vendors.swig +++ b/layout/_scripts/vendors.swig @@ -28,7 +28,7 @@ {% endif %} {% if theme.mediumzoom %} - {% set js_vendors.mediumzoom = 'mediumzoom/source/jquery.mediumzoom.pack.js' %} + {% set js_vendors.mediumzoom = 'mediumzoom/medium-zoom.min.js' %} {% endif %} {% if theme.canvas_nest.enable %} diff --git a/source/js/next-boot.js b/source/js/next-boot.js index 28ecca10e2..681161f798 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -27,6 +27,7 @@ $(document).ready(function() { }); CONFIG.fancybox && NexT.utils.wrapImageWithFancyBox(); + CONFIG.mediumzoom && NexT.utils.registerMediumZoom(); CONFIG.copycode.enable && NexT.utils.registerCopyCode(); CONFIG.tabs && NexT.utils.registerTabsTag(); diff --git a/source/js/utils.js b/source/js/utils.js index 1628145ce3..202e0aed6c 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -3,11 +3,10 @@ NexT.utils = { /** - * Wrap images with fancybox support. + * Wrap images with fancybox. */ wrapImageWithFancyBox: function() { - $('.content img') - .not('#qr img') + $('.post-body img') .each(function() { var $image = $(this); var imageTitle = $image.attr('title') || $image.attr('alt'); @@ -45,8 +44,12 @@ NexT.utils = { }); }, + registerMediumZoom: function() { + mediumZoom('.post-body img'); + }, + lazyLoadPostsImages: function() { - lozad('.content img').observe(); + lozad('.post-body img').observe(); }, /** From 8fd616c402f9acfac4ad7971e574fcb4a50d3da0 Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sat, 20 Jul 2019 20:22:36 +0800 Subject: [PATCH 3/8] Fix QA --- layout/_layout.swig | 13 +------------ layout/_third-party/index.swig | 12 ++++++++++++ source/js/next-boot.js | 4 ++-- source/js/utils.js | 13 +++---------- 4 files changed, 18 insertions(+), 24 deletions(-) create mode 100644 layout/_third-party/index.swig diff --git a/layout/_layout.swig b/layout/_layout.swig index 8001d05240..dbad216616 100644 --- a/layout/_layout.swig +++ b/layout/_layout.swig @@ -103,18 +103,7 @@ {% include '_scripts/scroll-cookie.swig' %} {% include '_scripts/exturl.swig' %} {% include '_scripts/three.swig' %} - {% include '_third-party/math/index.swig' %} - {% include '_third-party/pangu.swig' %} - {% include '_third-party/quicklink.swig' %} - {% include '_third-party/bookmark.swig' %} - {% include '_third-party/schedule.swig' %} - {% include '_third-party/comments/index.swig' %} - {% include '_third-party/search/index.swig' %} - {% include '_third-party/chat/index.swig' %} - {% include '_third-party/tags/index.swig' %} - {% include '_third-party/baidu-push.swig' %} - {% include '_third-party/needsharebutton.swig' %} - {% include '_third-party/rating.swig' %} + {% include '_third-party/index.swig' %} {% for inject_item in theme.injects.bodyEnd %} {{ partial(inject_item.layout, inject_item.locals, inject_item.options) }} diff --git a/layout/_third-party/index.swig b/layout/_third-party/index.swig new file mode 100644 index 0000000000..8ab51bf034 --- /dev/null +++ b/layout/_third-party/index.swig @@ -0,0 +1,12 @@ +{% include '_third-party/math/index.swig' %} +{% include '_third-party/pangu.swig' %} +{% include '_third-party/quicklink.swig' %} +{% include '_third-party/bookmark.swig' %} +{% include '_third-party/schedule.swig' %} +{% include '_third-party/comments/index.swig' %} +{% include '_third-party/search/index.swig' %} +{% include '_third-party/chat/index.swig' %} +{% include '_third-party/tags/index.swig' %} +{% include '_third-party/baidu-push.swig' %} +{% include '_third-party/needsharebutton.swig' %} +{% include '_third-party/rating.swig' %} diff --git a/source/js/next-boot.js b/source/js/next-boot.js index 681161f798..1c2ce2cc5d 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -7,7 +7,7 @@ $(document).ready(function() { * Need to add config option in Front-End at 'layout/_partials/head.swig' file. */ CONFIG.fastclick && NexT.utils.isMobile() && window.FastClick.attach(document.body); - CONFIG.lazyload && NexT.utils.lazyLoadPostsImages(); + CONFIG.lazyload && window.lozad('.content img').observe(); NexT.utils.registerESCKeyEvent(); @@ -27,7 +27,7 @@ $(document).ready(function() { }); CONFIG.fancybox && NexT.utils.wrapImageWithFancyBox(); - CONFIG.mediumzoom && NexT.utils.registerMediumZoom(); + CONFIG.mediumzoom && window.mediumZoom('.post-body img'); CONFIG.copycode.enable && NexT.utils.registerCopyCode(); CONFIG.tabs && NexT.utils.registerTabsTag(); diff --git a/source/js/utils.js b/source/js/utils.js index 202e0aed6c..7d0d207c79 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -3,10 +3,11 @@ NexT.utils = { /** - * Wrap images with fancybox. + * Wrap images with fancybox support. */ wrapImageWithFancyBox: function() { - $('.post-body img') + $('.content img') + .not('#qr img') .each(function() { var $image = $(this); var imageTitle = $image.attr('title') || $image.attr('alt'); @@ -44,14 +45,6 @@ NexT.utils = { }); }, - registerMediumZoom: function() { - mediumZoom('.post-body img'); - }, - - lazyLoadPostsImages: function() { - lozad('.post-body img').observe(); - }, - /** * One-click copy code support. */ From 4e3ecd582d8ca0e86d7f63c6735e061b1fad96ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=C9=AA=E1=B4=8D=C9=AA?= <1119186082@qq.com> Date: Sat, 20 Jul 2019 20:25:30 +0800 Subject: [PATCH 4/8] Update index.swig --- layout/_third-party/index.swig | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/layout/_third-party/index.swig b/layout/_third-party/index.swig index 751c2b9d37..1711a79b62 100644 --- a/layout/_third-party/index.swig +++ b/layout/_third-party/index.swig @@ -1,13 +1,13 @@ -{% include '_third-party/math/index.swig' %} -{% include '_third-party/pangu.swig' %} -{% include '_third-party/quicklink.swig' %} -{% include '_third-party/bookmark.swig' %} -{% include '_third-party/schedule.swig' %} -{% include '_third-party/comments/index.swig' %} -{% include '_third-party/analytics/analytics-with-jquery.swig' %} -{% include '_third-party/search/index.swig' %} -{% include '_third-party/chat/index.swig' %} -{% include '_third-party/tags/index.swig' %} -{% include '_third-party/baidu-push.swig' %} -{% include '_third-party/needsharebutton.swig' %} -{% include '_third-party/rating.swig' %} +{% include 'math/index.swig' %} +{% include 'pangu.swig' %} +{% include 'quicklink.swig' %} +{% include 'bookmark.swig' %} +{% include 'schedule.swig' %} +{% include 'comments/index.swig' %} +{% include 'analytics/analytics-with-jquery.swig' %} +{% include 'search/index.swig' %} +{% include 'chat/index.swig' %} +{% include 'tags/index.swig' %} +{% include 'baidu-push.swig' %} +{% include 'needsharebutton.swig' %} +{% include 'rating.swig' %} From 56a1ef737de269a9d8cdcc455da5000718cedb71 Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sat, 20 Jul 2019 20:48:39 +0800 Subject: [PATCH 5/8] Update --- source/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/js/utils.js b/source/js/utils.js index 7d0d207c79..c4e2aeae3d 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -3,7 +3,7 @@ NexT.utils = { /** - * Wrap images with fancybox support. + * Wrap images with fancybox. */ wrapImageWithFancyBox: function() { $('.content img') From bf2dc4bfe158b8169d1f48743b8da91339dc230a Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sat, 20 Jul 2019 20:51:25 +0800 Subject: [PATCH 6/8] Update --- source/js/next-boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/js/next-boot.js b/source/js/next-boot.js index 1c2ce2cc5d..ca83cc85ea 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -7,7 +7,7 @@ $(document).ready(function() { * Need to add config option in Front-End at 'layout/_partials/head.swig' file. */ CONFIG.fastclick && NexT.utils.isMobile() && window.FastClick.attach(document.body); - CONFIG.lazyload && window.lozad('.content img').observe(); + CONFIG.lazyload && window.lozad('.post-body img').observe(); NexT.utils.registerESCKeyEvent(); From 17954b19bc72b2500b918668ab84df80e1b717da Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sun, 21 Jul 2019 12:18:00 +0800 Subject: [PATCH 7/8] Update --- _config.yml | 1 + layout/_layout.swig | 15 ++++++++++++++- layout/_third-party/index.swig | 13 ------------- 3 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 layout/_third-party/index.swig diff --git a/_config.yml b/_config.yml index 1e64e3535c..bf703f71fb 100644 --- a/_config.yml +++ b/_config.yml @@ -518,6 +518,7 @@ math: fancybox: false # A JavaScript library for zooming images like Medium. +# Do not enable both `fancybox` and `mediumzoom`. # Dependencies: https://github.com/theme-next/theme-next-mediumzoom mediumzoom: false diff --git a/layout/_layout.swig b/layout/_layout.swig index dbad216616..7e744eb4ef 100644 --- a/layout/_layout.swig +++ b/layout/_layout.swig @@ -103,7 +103,20 @@ {% include '_scripts/scroll-cookie.swig' %} {% include '_scripts/exturl.swig' %} {% include '_scripts/three.swig' %} - {% include '_third-party/index.swig' %} + {% include 'math/index.swig' %} + {% include 'pangu.swig' %} + {% include 'quicklink.swig' %} + {% include 'bookmark.swig' %} + {% include 'schedule.swig' %} + {% include 'comments/index.swig' %} + {% include 'analytics/analytics-with-jquery.swig' %} + {% include 'search/index.swig' %} + {% include 'chat/index.swig' %} + {% include 'tags/index.swig' %} + {% include 'baidu-push.swig' %} + {% include 'needsharebutton.swig' %} + {% include 'rating.swig' %} + {% for inject_item in theme.injects.bodyEnd %} {{ partial(inject_item.layout, inject_item.locals, inject_item.options) }} diff --git a/layout/_third-party/index.swig b/layout/_third-party/index.swig deleted file mode 100644 index 1711a79b62..0000000000 --- a/layout/_third-party/index.swig +++ /dev/null @@ -1,13 +0,0 @@ -{% include 'math/index.swig' %} -{% include 'pangu.swig' %} -{% include 'quicklink.swig' %} -{% include 'bookmark.swig' %} -{% include 'schedule.swig' %} -{% include 'comments/index.swig' %} -{% include 'analytics/analytics-with-jquery.swig' %} -{% include 'search/index.swig' %} -{% include 'chat/index.swig' %} -{% include 'tags/index.swig' %} -{% include 'baidu-push.swig' %} -{% include 'needsharebutton.swig' %} -{% include 'rating.swig' %} From 2040298b88b972dddd9e547435f7ad997955f973 Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Sun, 21 Jul 2019 12:19:39 +0800 Subject: [PATCH 8/8] Update --- layout/_layout.swig | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/layout/_layout.swig b/layout/_layout.swig index 7e744eb4ef..0c89ae8d81 100644 --- a/layout/_layout.swig +++ b/layout/_layout.swig @@ -103,20 +103,19 @@ {% include '_scripts/scroll-cookie.swig' %} {% include '_scripts/exturl.swig' %} {% include '_scripts/three.swig' %} - {% include 'math/index.swig' %} - {% include 'pangu.swig' %} - {% include 'quicklink.swig' %} - {% include 'bookmark.swig' %} - {% include 'schedule.swig' %} - {% include 'comments/index.swig' %} - {% include 'analytics/analytics-with-jquery.swig' %} - {% include 'search/index.swig' %} - {% include 'chat/index.swig' %} - {% include 'tags/index.swig' %} - {% include 'baidu-push.swig' %} - {% include 'needsharebutton.swig' %} - {% include 'rating.swig' %} - + {% include '_third-party/math/index.swig' %} + {% include '_third-party/pangu.swig' %} + {% include '_third-party/quicklink.swig' %} + {% include '_third-party/bookmark.swig' %} + {% include '_third-party/schedule.swig' %} + {% include '_third-party/comments/index.swig' %} + {% include '_third-party/analytics/analytics-with-jquery.swig' %} + {% include '_third-party/search/index.swig' %} + {% include '_third-party/chat/index.swig' %} + {% include '_third-party/tags/index.swig' %} + {% include '_third-party/baidu-push.swig' %} + {% include '_third-party/needsharebutton.swig' %} + {% include '_third-party/rating.swig' %} {% for inject_item in theme.injects.bodyEnd %} {{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}