From 63876c601ddadfeaa4b9fa6d767f3129d8614793 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 23 Oct 2018 00:28:03 -0700 Subject: [PATCH] Fix: zoom-image target elements (#640) - Ignore images outside of main content area (e.g. logo, sidenav icons, etc.) - Ignore linked images (previous behavior broke linked images) Fixes #520 --- src/plugins/zoom-image.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/zoom-image.js b/src/plugins/zoom-image.js index ec9e9f5a..faf92e1d 100644 --- a/src/plugins/zoom-image.js +++ b/src/plugins/zoom-image.js @@ -1,14 +1,20 @@ import mediumZoom from 'medium-zoom' +const matchesSelector = Element.prototype.matches || Element.prototype.webkitMatchesSelector || Element.prototype.msMatchesSelector + function install(hook) { let zoom hook.doneEach(_ => { + let elms = Array.apply(null, document.querySelectorAll('.markdown-section img:not(.emoji):not([data-no-zoom])')) + + elms = elms.filter(elm => matchesSelector.call(elm, 'a img') === false) + if (zoom) { zoom.detach() } - zoom = mediumZoom('img:not(.emoji):not([data-no-zoom])') + zoom = mediumZoom(elms) }) }