bibliotheks-und-archivinfor.../docsify/zoom-image.min.js

2 lines
9.0 KiB
JavaScript

!function(){function t(e){return"IMG"===e.tagName}function w(e){return e&&1===e.nodeType}function L(e){return".svg"===(e.currentSrc||e.src).substr(-4).toLowerCase()}function p(e){try{return Array.isArray(e)?e.filter(t):function(e){return NodeList.prototype.isPrototypeOf(e)}(e)?[].slice.call(e).filter(t):w(e)?[e].filter(t):"string"==typeof e?[].slice.call(document.querySelectorAll(e)).filter(t):[]}catch(e){throw new TypeError("The provided selector is invalid.\nExpects a CSS selector, a Node element, a NodeList or an array.\nSee: https://github.com/francoischalifour/medium-zoom")}}function g(e,t){var o=H({bubbles:!1,cancelable:!1,detail:void 0},t);if("function"==typeof window.CustomEvent)return new CustomEvent(e,o);var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,o.bubbles,o.cancelable,o.detail),n}function v(e,t){function o(){for(var e=arguments,t=arguments.length,o=Array(t),n=0;n<t;n++)o[n]=e[n];var i=o.reduce(function(e,t){return[].concat(e,p(t))},[]);return i.filter(function(e){return-1===c.indexOf(e)}).forEach(function(e){c.push(e),e.classList.add("medium-zoom-image")}),d.forEach(function(e){var t=e.type,o=e.listener,n=e.options;i.forEach(function(e){e.addEventListener(t,o,n)})}),f}function n(e){function r(){var e={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,left:0,top:0,right:0,bottom:0},t=void 0,o=void 0;if(b.container)if(b.container instanceof Object)t=(e=H({},e,b.container)).width-e.left-e.right-2*b.margin,o=e.height-e.top-e.bottom-2*b.margin;else{var n=(w(b.container)?b.container:document.querySelector(b.container)).getBoundingClientRect(),i=n.width,r=n.height,d=n.left,a=n.top;e=H({},e,{width:i,height:r,left:d,top:a})}t=t||e.width-2*b.margin,o=o||e.height-2*b.margin;var m=E.zoomedHd||E.original,c=L(m)?t:m.naturalWidth||t,l=L(m)?o:m.naturalHeight||o,u=m.getBoundingClientRect(),s=u.top,f=u.left,p=u.width,g=u.height,v=Math.min(c,t)/p,h=Math.min(l,o)/g,z=Math.min(v,h),y="scale("+z+") translate3d("+((t-p)/2-f+b.margin+e.left)/z+"px, "+((o-g)/2-s+b.margin+e.top)/z+"px, 0)";E.zoomed.style.transform=y,E.zoomedHd&&(E.zoomedHd.style.transform=y)}var d=(0<arguments.length&&void 0!==e?e:{}).target;return new a(function(t){if(d&&-1===c.indexOf(d))t(f);else{if(E.zoomed)t(f);else{if(d)E.original=d;else{if(!(0<c.length))return void t(f);var e=c;E.original=e[0]}if(E.original.dispatchEvent(g("medium-zoom:open",{detail:{zoom:f}})),u=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,l=!0,E.zoomed=function(e){var t=e.getBoundingClientRect(),o=t.top,n=t.left,i=t.width,r=t.height,d=e.cloneNode(),a=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,m=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;return d.removeAttribute("id"),d.style.position="absolute",d.style.top=o+a+"px",d.style.left=n+m+"px",d.style.width=i+"px",d.style.height=r+"px",d.style.transform="",d}(E.original),document.body.appendChild(s),b.template){var o=w(b.template)?b.template:document.querySelector(b.template);E.template=document.createElement("div"),E.template.appendChild(o.content.cloneNode(!0)),document.body.appendChild(E.template)}if(document.body.appendChild(E.zoomed),window.requestAnimationFrame(function(){document.body.classList.add("medium-zoom--opened")}),E.original.classList.add("medium-zoom-image--hidden"),E.zoomed.classList.add("medium-zoom-image--opened"),E.zoomed.addEventListener("click",m),E.zoomed.addEventListener("transitionend",function e(){l=!1,E.zoomed.removeEventListener("transitionend",e),E.original.dispatchEvent(g("medium-zoom:opened",{detail:{zoom:f}})),t(f)}),E.original.getAttribute("data-zoom-src")){E.zoomedHd=E.zoomed.cloneNode(),E.zoomedHd.removeAttribute("srcset"),E.zoomedHd.removeAttribute("sizes"),E.zoomedHd.src=E.zoomed.getAttribute("data-zoom-src"),E.zoomedHd.onerror=function(){clearInterval(n),console.warn("Unable to reach the zoom image target "+E.zoomedHd.src),E.zoomedHd=null,r()};var n=setInterval(function(){E.zoomedHd.complete&&(clearInterval(n),E.zoomedHd.classList.add("medium-zoom-image--opened"),E.zoomedHd.addEventListener("click",m),document.body.appendChild(E.zoomedHd),r())},10)}else if(E.original.hasAttribute("srcset")){E.zoomedHd=E.zoomed.cloneNode(),E.zoomedHd.removeAttribute("sizes");var i=E.zoomedHd.addEventListener("load",function(){E.zoomedHd.removeEventListener("load",i),E.zoomedHd.classList.add("medium-zoom-image--opened"),E.zoomedHd.addEventListener("click",m),document.body.appendChild(E.zoomedHd),r()})}else r()}}})}var i=1<arguments.length&&void 0!==t?t:{},a=window.Promise||function(e){function t(){}e(t,t)},m=function(){return new a(function(t){if(!l&&E.original){l=!0,document.body.classList.remove("medium-zoom--opened"),E.zoomed.style.transform="",E.zoomedHd&&(E.zoomedHd.style.transform=""),E.template&&(E.template.style.transition="opacity 150ms",E.template.style.opacity=0),E.original.dispatchEvent(g("medium-zoom:close",{detail:{zoom:f}})),E.zoomed.addEventListener("transitionend",function e(){E.original.classList.remove("medium-zoom-image--hidden"),document.body.removeChild(E.zoomed),E.zoomedHd&&document.body.removeChild(E.zoomedHd),document.body.removeChild(s),E.zoomed.classList.remove("medium-zoom-image--opened"),E.template&&document.body.removeChild(E.template),l=!1,E.zoomed.removeEventListener("transitionend",e),E.original.dispatchEvent(g("medium-zoom:closed",{detail:{zoom:f}})),E.original=null,E.zoomed=null,E.zoomedHd=null,E.template=null,t(f)})}else t(f)})},r=function(e){var t=(0<arguments.length&&void 0!==e?e:{}).target;return E.original?m():n({target:t})},c=[],d=[],l=!1,u=0,b=i,E={original:null,zoomed:null,zoomedHd:null,template:null};"[object Object]"===Object.prototype.toString.call(e)?b=e:!e&&"string"!=typeof e||o(e);var s=function(e){var t=document.createElement("div");return t.classList.add("medium-zoom-overlay"),t.style.background=e,t}((b=H({margin:0,background:"#fff",scrollOffset:40,container:null,template:null},b)).background);document.addEventListener("click",function(e){var t=e.target;t!==s?-1!==c.indexOf(t)&&r({target:t}):m()}),document.addEventListener("keyup",function(e){var t=e.key||e.keyCode;"Escape"!==t&&"Esc"!==t&&27!==t||m()}),document.addEventListener("scroll",function(){if(!l&&E.original){var e=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;Math.abs(u-e)>b.scrollOffset&&setTimeout(m,150)}}),window.addEventListener("resize",m);var f={open:n,close:m,toggle:r,update:function(e){var t=0<arguments.length&&void 0!==e?e:{},o=t;if(t.background&&(s.style.background=t.background),t.container&&t.container instanceof Object&&(o.container=H({},b.container,t.container)),t.template){var n=w(t.template)?t.template:document.querySelector(t.template);o.template=n}return b=H({},b,o),c.forEach(function(e){e.dispatchEvent(g("medium-zoom:update",{detail:{zoom:f}}))}),f},clone:function(e){return v(H({},b,0<arguments.length&&void 0!==e?e:{}))},attach:o,detach:function(){for(var e=arguments,t=arguments.length,o=Array(t),n=0;n<t;n++)o[n]=e[n];E.zoomed&&m();var i=0<o.length?o.reduce(function(e,t){return[].concat(e,p(t))},[]):c;return i.forEach(function(e){e.classList.remove("medium-zoom-image"),e.dispatchEvent(g("medium-zoom:detach",{detail:{zoom:f}}))}),c=c.filter(function(e){return-1===i.indexOf(e)}),f},on:function(t,o,e){var n=2<arguments.length&&void 0!==e?e:{};return c.forEach(function(e){e.addEventListener("medium-zoom:"+t,o,n)}),d.push({type:"medium-zoom:"+t,listener:o,options:n}),f},off:function(t,o,e){var n=2<arguments.length&&void 0!==e?e:{};return c.forEach(function(e){e.removeEventListener("medium-zoom:"+t,o,n)}),d=d.filter(function(e){return!(e.type==="medium-zoom:"+t&&e.listener.toString()===o.toString())}),f},getOptions:function(){return b},getImages:function(){return c},getZoomedImage:function(){return E.original}};return f}var H=Object.assign||function(e){for(var t=arguments,o=1;o<arguments.length;o++){var n=t[o];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e};!function(e,t){void 0===t&&(t={});var o=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===o&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}(".medium-zoom-overlay{position:fixed;top:0;right:0;bottom:0;left:0;opacity:0;transition:opacity .3s;will-change:opacity}.medium-zoom--opened .medium-zoom-overlay{cursor:pointer;cursor:zoom-out;opacity:1}.medium-zoom-image{cursor:pointer;cursor:zoom-in;transition:transform .3s cubic-bezier(.2,0,.2,1)!important}.medium-zoom-image--hidden{visibility:hidden}.medium-zoom-image--opened{position:relative;cursor:pointer;cursor:zoom-out;will-change:transform}");var n=Element.prototype.matches||Element.prototype.webkitMatchesSelector||Element.prototype.msMatchesSelector;$docsify.plugins=[].concat(function(e){var o;e.doneEach(function(e){var t=Array.apply(null,document.querySelectorAll(".markdown-section img:not(.emoji):not([data-no-zoom])"));t=t.filter(function(e){return!1===n.call(e,"a img")}),o&&o.detach(),o=v(t)})},$docsify.plugins)}();