!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Zooming=e()}(this,function(){"use strict";function t(t){return function(e){return(void 0===e?"undefined":T(e))===t}}function e(t){return function(e){return e.tagName===t}}function n(t,e){for(var n=[];t&&t!==document;t=t.parentNode)e?e(t)&&n.push(t):n.push(t);return n}function i(){return e("IMG")===!1}function o(t,e){if(t){var n=new Image;n.onload=function(){e&&e(n)},n.src=t}}function s(t,e){var n=null;t.hasAttribute("data-original")?n=t.getAttribute("data-original"):P(t.parentNode)&&(n=t.parentNode.getAttribute("href")),e(n)}function r(t){var e=I.transitionProp,n=I.transformProp,i=void 0;t.transition&&(i=t.transition,delete t.transition,t[e]=i),t.transform&&(i=t.transform,delete t.transform,t[n]=i)}function a(t){var e={},n=["webkitTransition","transition","mozTransition"],i=["webkitTransform","transform","mozTransform"],o={transition:"transitionend",mozTransition:"transitionend",webkitTransition:"webkitTransitionEnd"};return n.some(function(n){if(void 0!==t.style[n])return e.transitionProp=n,e.transEndEvent=o[n],!0}),i.some(function(n){if(void 0!==t.style[n])return e.transformProp=n,e.transformCssProp=n.replace(/(.*)Transform/,"-$1-transform"),!0}),e}function l(t){return function(e){return e/t}}function u(t,e,n,i){i?t.addEventListener(e,n[e],{passive:!1}):t.removeEventListener(e,n[e],{passive:!1})}function c(){var t=Math.min(z.clientWidth,window.innerWidth),e=Math.min(z.clientHeight,window.innerHeight);return{x:N(t),y:N(e)}}function h(t,e,n){["mousedown","mousemove","mouseup","touchstart","touchmove","touchend"].forEach(function(i){u(t,i,e,n)})}function f(t,e,n){r(e);var i=t.style,o={};for(var s in e)n&&(o[s]=i[s]||""),i[s]=e[s];return o}function d(t,e){Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach(function(n){t[n]=t[n].bind(e)})}function v(t){return"hidden"===getComputedStyle(t).overflow}function p(t){if(G.map.has(t))return G.map.get(t);var e=n(t.parentNode,v);return G.map.set(t,e),e}function y(t){p(t).forEach(function(t){G.style.has(t)?f(t,{overflow:"visible"}):G.style.set(t,f(t,{overflow:"visible"},!0))})}function m(t){G.map.has(t)&&G.map.get(t).forEach(function(t){f(t,G.style.get(t))})}function g(t){return 0!==t.button}function b(t){return"Escape"===(t.key||t.code)||27===t.keyCode}function k(t){return t.targetTouches.length>0}function w(t,e,n){for(var i=t.length,o=t[0],s=i>1,r=e,a=t.length,l=0,u=0,c={x:o.clientX,y:o.clientY},h={x:o.clientX,y:o.clientY};a--;){var f=t[a],d=[f.clientX,f.clientY],v=d[0],p=d[1];l+=v,u+=p,s&&(vh.x&&(h.x=v),ph.y&&(h.y=p))}if(s){var y=h.x-c.x,m=h.y-c.y;r=y>m?y/window.innerWidth*2:m/window.innerHeight*2}n(l/i,u/i,r)}function x(t){var e=c(),n={x:t.left+N(t.width),y:t.top+N(t.height)};return{x:e.x-n.x,y:e.y-n.y}}function E(t,e,n){if(n)return{x:n.width/t.width,y:n.height/t.height};var i=N(t.width),o=N(t.height),s=c(),r={x:s.x-i,y:s.y-o},a=r.x/i,l=r.y/o,u=e+Math.min(a,l);return{x:u,y:u}}var T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},S=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},C=function(){function t(t,e){for(var n=0;n=this.options.scrollThreshold&&(this.lastScrollPosition=null,this.close())}},{key:"keydown",value:function(t){var e=this;b(t)&&(this.released?this.close():this.release(function(){return e.close()}))}},{key:"mousedown",value:function(t){var e=this;g(t)||(t.preventDefault(),this.pressTimer=setTimeout(function(){e.grab(t.clientX,t.clientY)},200))}},{key:"mousemove",value:function(t){this.released||this.move(t.clientX,t.clientY)}},{key:"mouseup",value:function(t){g(t)||(clearTimeout(this.pressTimer),this.released?this.close():this.release())}},{key:"touchstart",value:function(t){var e=this;t.preventDefault(),this.pressTimer=setTimeout(function(){w(t.touches,e.options.scaleExtra,function(t,n,i){e.grab(t,n,i)})},200)}},{key:"touchmove",value:function(t){var e=this;this.released||w(t.touches,this.options.scaleExtra,function(t,n,i){e.move(t,n,i)})}},{key:"touchend",value:function(t){k(t)||(clearTimeout(this.pressTimer),this.released?this.close():this.release())}}]),t}(),R=function(){function t(e,n){S(this,t),this.el=e,this.instance=n,this.parent=document.body}return C(t,[{key:"init",value:function(t){var e=this;f(this.el,{zIndex:998,backgroundColor:t.bgColor,position:"fixed",top:0,left:0,right:0,bottom:0,opacity:0,transition:"opacity\n "+t.transitionDuration+"s\n "+t.transitionTimingFunction}),this.el.addEventListener("click",function(){return e.instance.close()})}},{key:"updateStyle",value:function(t){f(this.el,{backgroundColor:t.bgColor,transition:"opacity\n "+t.transitionDuration+"s\n "+t.transitionTimingFunction})}},{key:"insert",value:function(){this.parent.appendChild(this.el)}},{key:"remove",value:function(){this.parent.removeChild(this.el)}},{key:"show",value:function(){var t=this;setTimeout(function(){return t.el.style.opacity=t.instance.options.bgOpacity},30)}},{key:"hide",value:function(){this.el.style.opacity=0}}]),t}(),W=function(){function t(e,n){S(this,t),this.el=e,this.instance=n,this.translate=null,this.scale=null,this.srcThumbnail=this.el.getAttribute("src"),this.style={open:null,close:null}}return C(t,[{key:"zoomIn",value:function(){var t=this.instance.options,e=this.el.getBoundingClientRect();G.disable(this.el),this.translate=x(e),this.scale=E(e,t.scaleBase,t.customSize),this.el.offsetWidth,this.style.open={position:"relative",zIndex:999,cursor:t.enableGrab?D.grab:D.zoomOut,transition:M+"\n "+t.transitionDuration+"s\n "+t.transitionTimingFunction,transform:"translate("+this.translate.x+"px, "+this.translate.y+"px)\n scale("+this.scale.x+","+this.scale.y+")",width:e.width+"px",height:e.height+"px"},this.style.close=f(this.el,this.style.open,!0)}},{key:"zoomOut",value:function(){G.enable(this.el),this.el.offsetWidth,f(this.el,{transform:"none"})}},{key:"grab",value:function(t,e,n){var i=c(),o=i.x-t,s=i.y-e;f(this.el,{cursor:D.move,transform:"translate(\n "+(this.translate.x+o)+"px, "+(this.translate.y+s)+"px)\n scale("+(this.scale.x+n)+","+(this.scale.y+n)+")"})}},{key:"move",value:function(t,e,n){var i=c(),o=i.x-t,s=i.y-e;f(this.el,{transition:M,transform:"translate(\n "+(this.translate.x+o)+"px, "+(this.translate.y+s)+"px)\n scale("+(this.scale.x+n)+","+(this.scale.y+n)+")"})}},{key:"restoreCloseStyle",value:function(){f(this.el,this.style.close)}},{key:"restoreOpenStyle",value:function(){f(this.el,this.style.open)}},{key:"upgradeSource",value:function(t){var e=this;if(t){var n=this.el.parentNode,i=this.el.cloneNode(!1);i.setAttribute("src",t),i.style.position="fixed",i.style.visibility="hidden",n.appendChild(i),setTimeout(function(){e.el.setAttribute("src",t),n.removeChild(i)},100)}}},{key:"downgradeSource",value:function(t){t&&this.el.setAttribute("src",this.srcThumbnail)}}]),t}(),Y={defaultZoomable:'img[data-action="zoom"]',enableGrab:!0,preloadImage:!0,transitionDuration:.4,transitionTimingFunction:"cubic-bezier(0.4, 0, 0, 1)",bgColor:"rgb(255, 255, 255)",bgOpacity:1,scaleBase:1,scaleExtra:.5,scrollThreshold:40,customSize:null,onOpen:null,onClose:null,onRelease:null,onBeforeOpen:null,onBeforeClose:null,onBeforeGrab:null,onBeforeMove:null,onBeforeRelease:null},X=function(){function t(e){S(this,t),this.target=null,this.overlay=new R(document.createElement("div"),this),this.eventHandler=new j(this),this.body=document.body,this.shown=!1,this.lock=!1,this.released=!0,this.lastScrollPosition=null,this.pressTimer=null,this.options=O({},Y),this.config(e),this.listen(this.options.defaultZoomable),this.overlay.init(this.options)}return C(t,[{key:"listen",value:function(t){if(B(t)){for(var e=document.querySelectorAll(t),n=e.length;n--;)this.listen(e[n]);return this}if(!i(t))return t.style.cursor=D.zoomIn,t.addEventListener("click",this.eventHandler.click,{passive:!1}),this.options.preloadImage&&s(t,o),this}},{key:"config",value:function(t){return t?(O(this.options,t),this.overlay.updateStyle(this.options),this):this.options}},{key:"open",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.options.onOpen;if(!this.shown&&!this.lock){var r=B(t)?document.querySelector(t):t;if(!i(r)){this.options.onBeforeOpen&&this.options.onBeforeOpen(r),this.options.preloadImage||s(r,o),this.target=new W(r,this),this.shown=!0,this.lock=!0,this.target.zoomIn(),this.overlay.insert(),this.overlay.show(),document.addEventListener("scroll",this.eventHandler.scroll),document.addEventListener("keydown",this.eventHandler.keydown);var a=function t(){r.removeEventListener(A,t),e.lock=!1,s(r,function(t){return e.target.upgradeSource(t)}),e.options.enableGrab&&h(document,e.eventHandler,!0),n&&n(r)};return r.addEventListener(A,a),this}}}},{key:"close",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.options.onClose;if(this.shown&&!this.lock){var n=this.target.el;this.options.onBeforeClose&&this.options.onBeforeClose(n),this.lock=!0,this.body.style.cursor=D.default,this.overlay.hide(),this.target.zoomOut(),document.removeEventListener("scroll",this.eventHandler.scroll),document.removeEventListener("keydown",this.eventHandler.keydown);var i=function i(){n.removeEventListener(A,i),t.shown=!1,t.lock=!1,s(n,function(e){return t.target.downgradeSource(e)}),t.options.enableGrab&&h(document,t.eventHandler,!1),t.target.restoreCloseStyle(),t.overlay.remove(),e&&e(n)};return n.addEventListener(A,i),this}}},{key:"grab",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.scaleExtra,i=arguments[3];if(this.shown&&!this.lock){var o=this.target.el;this.options.onBeforeGrab&&this.options.onBeforeGrab(o),this.released=!1,this.target.grab(t,e,n);var s=function t(){o.removeEventListener(A,t),i&&i(o)};o.addEventListener(A,s)}}},{key:"move",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.scaleExtra,i=arguments[3];if(this.shown&&!this.lock){var o=this.target.el;this.options.onBeforeMove&&this.options.onBeforeMove(o),this.released=!1,this.target.move(t,e,n),this.body.style.cursor=D.move;var s=function t(){o.removeEventListener(A,t),i&&i(o)};o.addEventListener(A,s)}}},{key:"release",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.options.onRelease;if(this.shown&&!this.lock){var n=this.target.el;this.options.onBeforeRelease&&this.options.onBeforeRelease(n),this.lock=!0,this.target.restoreOpenStyle(),this.body.style.cursor=D.default;var i=function i(){n.removeEventListener(A,i),t.lock=!1,t.released=!0,e&&e(n)};return n.addEventListener(A,i),this}}}]),t}();return document.addEventListener("DOMContentLoaded",function(){new X}),X}); //# sourceMappingURL=zooming.min.js.map