vufindtutorialde/docsify/zoom-image.min.js

2 lines
7.7 KiB
JavaScript

!function(){var T=Object.assign||function(e){for(var t,o=1;o<arguments.length;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},x=["IMG"],S=[27,81],N=function(e){return-1<x.indexOf(e.tagName)},j=function(e){return e.naturalWidth!==e.width},M=function(e){return e&&1===e.nodeType},e=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},o=t.margin,n=void 0===o?0:o,i=t.background,r=void 0===i?"#fff":i,d=t.scrollOffset,a=void 0===d?48:d,l=t.metaClick,c=t.container,m=t.template,s=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{bubbles:!1,cancelable:!1,detail:void 0};if("function"==typeof window.CustomEvent)return new CustomEvent(e,t);var o=document.createEvent("CustomEvent");return o.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),o},u=function(){if(H.original){if(H.original.dispatchEvent(s("show")),O=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,A=!0,H.zoomed=(o=H.original,n=o.getBoundingClientRect(),i=n.top,r=n.left,d=n.width,a=n.height,l=o.cloneNode(),c=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,m=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0,l.removeAttribute("id"),l.style.position="absolute",l.style.top=i+c+"px",l.style.left=r+m+"px",l.style.width=d+"px",l.style.height=a+"px",l.style.transform="",l),document.body.appendChild(k),E.template){var e=M(E.template)?E.template:document.querySelector(E.template);H.template=document.createElement("div"),H.template.appendChild(e.content.cloneNode(!0)),document.body.appendChild(H.template)}if(document.body.appendChild(H.zoomed),requestAnimationFrame(function(){document.body.classList.add("medium-zoom--open")}),H.original.style.visibility="hidden",H.zoomed.classList.add("medium-zoom-image--open"),H.zoomed.addEventListener("click",p),H.zoomed.addEventListener("transitionend",v),H.original.getAttribute("data-zoom-target")){H.zoomedHd=H.zoomed.cloneNode(),H.zoomedHd.src=H.zoomed.getAttribute("data-zoom-target"),H.zoomedHd.onerror=function(){clearInterval(t),console.error("Unable to reach the zoom image target "+H.zoomedHd.src),H.zoomedHd=null,b()};var t=setInterval(function(){H.zoomedHd.naturalWidth&&(clearInterval(t),H.zoomedHd.classList.add("medium-zoom-image--open"),H.zoomedHd.addEventListener("click",p),document.body.appendChild(H.zoomedHd),b())},10)}else b()}var o,n,i,r,d,a,l,c,m},p=function e(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,o=function(){A||!H.original||(H.original.dispatchEvent(s("hide")),A=!0,document.body.classList.remove("medium-zoom--open"),H.zoomed.style.transform="",H.zoomedHd&&(H.zoomedHd.style.transform="",H.zoomedHd.removeEventListener("click",e)),H.template&&(H.template.style.transition="opacity 150ms",H.template.style.opacity=0),H.zoomed.removeEventListener("click",e),H.zoomed.addEventListener("transitionend",h))};0<t?setTimeout(o,t):o()},f=function(e){e&&e.target?(H.original=e.target,u()):H.original?p():(H.original=C[0],u())},g=function(e){return(e.metaKey||e.ctrlKey)&&E.metaClick?window.open(e.target.getAttribute("data-original")||e.target.parentNode.href||e.target.src,"_blank"):(e.preventDefault(),void f(e))},v=function e(){A=!1,H.zoomed.removeEventListener("transitionend",e),H.original.dispatchEvent(s("shown"))},h=function e(){H.original&&(H.original.style.visibility="",document.body.removeChild(H.zoomed),H.zoomedHd&&document.body.removeChild(H.zoomedHd),document.body.removeChild(k),H.zoomed.classList.remove("medium-zoom-image--open"),H.template&&document.body.removeChild(H.template),A=!1,H.zoomed.removeEventListener("transitionend",e),H.original.dispatchEvent(s("hidden")),H.original=null,H.zoomed=null,H.zoomedHd=null,H.template=null)},y=function(){if(!A&&H.original){var e=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;Math.abs(O-e)>E.scrollOffset&&p(150)}},z=function(e){-1<S.indexOf(e.keyCode||e.which)&&p()},b=function(){var e=Math.min;if(H.original){var t,o,n={width:window.innerWidth,height:window.innerHeight,left:0,top:0,right:0,bottom:0};if(E.container)if(E.container instanceof Object)T(n,E.container),t=n.width-n.left-n.right-2*E.margin,o=n.height-n.top-n.bottom-2*E.margin;else{var i=(M(E.container)?E.container:document.querySelector(E.container)).getBoundingClientRect(),r=i.width,d=i.height,a=i.left,l=i.top;T(n,{width:r,height:d,left:a,top:l})}t=t||n.width-2*E.margin,o=o||n.height-2*E.margin;var c=H.zoomedHd||H.original,m=c.naturalWidth,s=void 0===m?t:m,u=c.naturalHeight,p=void 0===u?o:u,f=c.getBoundingClientRect(),g=f.top,v=f.left,h=f.width,y=f.height,z=e(e(s,t)/h,e(p,o)/y)||1,b="scale("+z+") translate3d("+((t-h)/2-v+E.margin+n.left)/z+"px, "+((o-y)/2-g+E.margin+n.top)/z+"px, 0)";H.zoomed.style.transform=b,H.zoomedHd&&(H.zoomedHd.style.transform=b)}},E={margin:n,background:r,scrollOffset:a,metaClick:void 0===l||l,container:c,template:m};e instanceof Object&&T(E,e);var w,L,C=function(e){try{return Array.isArray(e)?e.filter(N):(t=e,NodeList.prototype.isPrototypeOf(t)||HTMLCollection.prototype.isPrototypeOf(t)?Array.apply(null,e).filter(N):M(e)?[e].filter(N):"string"==typeof e?Array.apply(null,document.querySelectorAll(e)).filter(N):Array.apply(null,document.querySelectorAll(x.map(function(e){return e.toLowerCase()}).join(","))).filter(j))}catch(e){throw new TypeError("The provided selector is invalid.\nExpects a CSS selector, a Node element, a NodeList, an HTMLCollection or an array.\nSee: https://github.com/francoischalifour/medium-zoom")}var t}(e),k=(w=E.background,(L=document.createElement("div")).classList.add("medium-zoom-overlay"),L.style.backgroundColor=w,L),H={original:null,zoomed:null,zoomedHd:null,template:null},O=0,A=!1;return C.forEach(function(e){e.classList.add("medium-zoom-image"),e.addEventListener("click",g)}),k.addEventListener("click",p),document.addEventListener("scroll",y),document.addEventListener("keyup",z),window.addEventListener("resize",p),{show:f,hide:p,toggle:f,update:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return e.background&&(k.style.backgroundColor=e.background),e.container&&e.container instanceof Object&&(e.container=T({},E.container,e.container)),T(E,e)},addEventListeners:function(t,o){C.forEach(function(e){e.addEventListener(t,o)})},detach:function(){H.zoomed&&p();var t=s("detach");C.forEach(function(e){e.classList.remove("medium-zoom-image"),e.removeEventListener("click",g),e.dispatchEvent(t)}),C.splice(0,C.length),k.removeEventListener("click",p),document.removeEventListener("scroll",y),document.removeEventListener("keyup",z),window.removeEventListener("resize",p)},images:C,options:E}},t=Object.freeze({default: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--open .medium-zoom-overlay{cursor:pointer;cursor:zoom-out;opacity:1}.medium-zoom-image{cursor:pointer;cursor:zoom-in;transition:transform .3s}.medium-zoom-image--open{position:relative;cursor:pointer;cursor:zoom-out;will-change:transform}");var n=t&&e||t,i=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===i.call(e,"a img")}),o&&o.detach(),o=n(t)})},$docsify.plugins)}();