3 lines
8.3 KiB
JavaScript
3 lines
8.3 KiB
JavaScript
|
|
/*!medium-zoom 1.0.5 | MIT License | https://github.com/francoischalifour/medium-zoom*/(function(e,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(t):(e=e||self,e.mediumZoom=t())})(this,function(){"use strict";var e=Object.assign||function(e){for(var t,s,n=1;n<arguments.length;n++){t=arguments[n];for(s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},n=function(t){return t.tagName==="IMG"},a=function(t){return NodeList.prototype.isPrototypeOf(t)},s=function(t){return t&&t.nodeType===1},o=function(t){var n=t.currentSrc||t.src;return n.substr(-4).toLowerCase()===".svg"},i=function(t){try{return Array.isArray(t)?t.filter(n):a(t)?[].slice.call(t).filter(n):s(t)?[t].filter(n):typeof t=="string"?[].slice.call(document.querySelectorAll(t)).filter(n):[]}catch{throw new TypeError(`The provided selector is invalid.
|
||
|
|
Expects a CSS selector, a Node element, a NodeList or an array.
|
||
|
|
See: https://github.com/francoischalifour/medium-zoom`)}},r=function(){var t=document.createElement("div");return t.classList.add("medium-zoom-overlay"),t},c=function(t){var s=t.getBoundingClientRect(),o=s.top,i=s.left,a=s.width,r=s.height,n=t.cloneNode(),c=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,l=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;return n.removeAttribute("id"),n.style.position="absolute",n.style.top=o+c+"px",n.style.left=i+l+"px",n.style.width=a+"px",n.style.height=r+"px",n.style.transform="",n},t=function(n,s){var i,o=e({bubbles:!1,cancelable:!1,detail:void 0},s);return typeof window.CustomEvent=="function"?new CustomEvent(n,o):(i=document.createEvent("CustomEvent"),i.initCustomEvent(n,o.bubbles,o.cancelable,o.detail),i)},l=function n(a){var u,g,k=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=window.Promise||function(t){function n(){}t(n,n)},F=function(t){var n=t.target;if(n===g){m();return}if(h.indexOf(n)===-1)return;v({target:n})},M=function(){if(f||!l.original)return;var t=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;Math.abs(j-t)>d.scrollOffset&&setTimeout(m,150)},A=function(t){var n=t.key||t.keyCode;(n==="Escape"||n==="Esc"||n===27)&&m()},E=function(){var a,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=o;return o.container&&o.container instanceof Object&&(i.container=e({},d.container,o.container)),o.template&&(a=s(o.template)?o.template:document.querySelector(o.template),i.template=a),d=e({},d,i),h.forEach(function(e){e.dispatchEvent(t("medium-zoom:update",{detail:{zoom:u}}))}),u},x=function(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return n(e({},d,s))},_=function(){for(var n,s=arguments.length,o=Array(s),t=0;t<s;t++)o[t]=arguments[t];return n=o.reduce(function(e,t){return[].concat(e,i(t))},[]),n.filter(function(e){return h.indexOf(e)===-1}).forEach(function(e){h.push(e),e.classList.add("medium-zoom-image")}),p.forEach(function(e){var t=e.type,s=e.listener,o=e.options;n.forEach(function(e){e.addEventListener(t,s,o)})}),u},z=function(){for(var o,a=arguments.length,s=Array(a),n=0;n<a;n++)s[n]=arguments[n];return l.zoomed&&m(),o=s.length>0?s.reduce(function(e,t){return[].concat(e,i(t))},[]):h,o.forEach(function(e){e.classList.remove("medium-zoom-image"),e.dispatchEvent(t("medium-zoom:detach",{detail:{zoom:u}}))}),h=h.filter(function(e){return o.indexOf(e)===-1}),u},T=function(t,n){var s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return h.forEach(function(e){e.addEventListener("medium-zoom:"+t,n,s)}),p.push({type:"medium-zoom:"+t,listener:n,options:s}),u},S=function(t,n){var s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return h.forEach(function(e){e.removeEventListener("medium-zoom:"+t,n,s)}),p=p.filter(function(e){return e.type!=="medium-zoom:"+t||e.listener.toString()!==n.toString()}),u},y=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=r.target,a=function(){if(n={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,left:0,top:0,right:0,bottom:0},i=void 0,a=void 0,d.container)if(d.container instanceof Object)n=e({},n,d.container),i=n.width-n.left-n.right-d.margin*2,a=n.height-n.top-n.bottom-d.margin*2;else{var n,A=s(d.container)?d.container:document.querySelector(d.container),u=A.getBoundingClientRect(),g=u.width,C=u.height,w=u.left,_=u.top;n=e({},n,{width:g,height:C,left:w,top:_})}var i=i||n.width-d.margin*2,a=a||n.height-d.margin*2,r=l.zoomedHd||l.original,b=o(r)?i:r.naturalWidth||i,v=o(r)?a:r.naturalHeight||a,c=r.getBoundingClientRect(),j=c.top,y=c.left,p=c.width,f=c.height,O=Math.min(b,i)/p,x=Math.min(v,a)/f,h=Math.min(O,x),E=(-y+(i-p)/2+d.margin+n.left)/h,k=(-j+(a-f)/2+d.margin+n.top)/h,m="scale("+h+") translate3d("+E+"px, "+k+"px, 0)";l.zoomed.style.transform=m,l.zoomedHd&&(l.zoomedHd.style.transform=m)};return new b(function(e){if(i&&h.indexOf(i)===-1){e(u);return}var n,o,r,p,v=function n(){f=!1,l.zoomed.removeEventListener("transit
|