forked from francoischalifour/medium-zoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedium-zoom.min.js
11 lines (11 loc) · 5.14 KB
/
medium-zoom.min.js
1
2
3
4
5
6
7
8
9
10
11
/*!
*
* medium-zoom v0.2.5
* Medium-like zoom on your pictures in pure JavaScript
* Copyright (c) 2016 mrdream
* https://github.com/francoischalifour/medium-zoom
* MIT license
*
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("medium-zoom",[],t):"object"==typeof exports?exports["medium-zoom"]=t():e["medium-zoom"]=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){(function(e){"use strict";function t(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Array.prototype.includes||(Array.prototype.includes=function(e){if(null==this)throw new TypeError("Array.prototype.includes called on null or undefined");var t=Object(this),n=parseInt(t.length,10)||0;if(0===n)return!1;var o,r=parseInt(arguments[1],10)||0;r>=0?o=r:(o=n+r,o<0&&(o=0));for(var i;o<n;){if(i=t[o],e===i||e!==e&&i!==i)return!0;o++}return!1});var r=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.margin,a=void 0===i?0:i,c=r.background,d=void 0===c?"#fff":c,u=r.scrollOffset,l=void 0===u?48:u,s=r.metaClick,f=void 0===s||s,m=["IMG","PICTURE","SVG"],p=27,y=81,h=[p,y],v=function(e){return m.includes(e.tagName)},g=function(e){return e.naturalWidth!==e.width},b=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":o(e))&&e.length&&"number"==typeof e.length&&e.length>0},w=function(){try{return Array.isArray(e)?e.filter(v):b(e)?[].concat(t(e)).filter(v):"string"==typeof e?[].concat(t(document.querySelectorAll(e))).filter(v):[].concat(t(document.querySelectorAll(m.map(function(e){return e.toLowerCase()}).join(",")))).filter(g)}catch(n){throw console.log(n),new SyntaxError("[medium-zoom] Unknown selector when applying the zoom.Expects a CSS selector, an array-like or an array.Check https://github.com/francoischalifour/medium-zoom for more.")}},E=function(){var e=document.createElement("div");return e.classList.add("medium-zoom-overlay"),e.style.backgroundColor=T.background,e},k=function(){if(q){var e=new Event("show");q.dispatchEvent(e),H=document.body.scrollTop,G=!0,document.body.appendChild(W),requestAnimationFrame(function(){document.body.classList.add("medium-zoom--open")}),q.classList.add("medium-zoom-image--open"),q.addEventListener("transitionend",S),M()}},L=function(){if(q){var e=new Event("hide");q.dispatchEvent(e),setTimeout(function(){G=!0,document.body.classList.remove("medium-zoom--open"),q.style.transform="none",q.addEventListener("transitionend",j)},150)}},x=function(e){q?L():(q=e?e.target:P[0],k())},z=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return T=n({},T,e),T.background&&(W.style.backgroundColor=T.background),T},A=function(e,t){P.forEach(function(n){n.addEventListener(e,t)})},C=function(e){return(e.metaKey||e.ctrlKey)&&T.metaClick?window.open(e.target.getAttribute("data-original")||e.target.parentNode.href||e.target.src,"_blank"):(e.preventDefault(),void x(e))},S=function K(){G=!1,q.removeEventListener("transitionend",K);var e=new Event("shown");q.dispatchEvent(e)},j=function N(){if(q){document.body.removeChild(W),q.classList.remove("medium-zoom-image--open"),G=!1,q.removeEventListener("transitionend",N);var e=new Event("hidden");q.dispatchEvent(e),q=null}},O=function(){!G&&q&&Math.abs(H-document.body.scrollTop)>T.scrollOffset&&L()},I=function(e){h.includes(e.keyCode||e.which)&&L()},M=function(){if(q){var e=document.body.clientWidth||window.innerWidth,t=document.documentElement.clientHeight||window.innerHeight,n=e-2*T.margin,o=t-2*T.margin,r=q,i=r.width,a=r.height,c=r.naturalWidth,d=void 0===c?+(1/0):c,u=r.naturalHeight,l=void 0===u?+(1/0):u,s=q.getBoundingClientRect(),f=s.top,m=s.left,p=Math.abs(e/2-(m+i/2))<=10,y=Math.min(d,n)/i,h=Math.min(l,o)/a,v=Math.min(y,h)||1,g=p?0:(-m+(n-i)/2)/v,b=(-f+(o-a)/2+T.margin)/v;q.style.transform="scale("+v+") translate3d("+g+"px, "+b+"px, 0)"}},T={margin:parseInt(a)||0,background:d,scrollOffset:parseInt(l)||48,metaClick:f};e instanceof Object&&(T=n({},T,e));var P=w(e),W=E(),q=null,H=0,G=!1;return P.forEach(function(e){e.classList.add("medium-zoom-image"),e.addEventListener("click",C)}),W.addEventListener("click",L),document.addEventListener("scroll",O),document.addEventListener("keyup",I),window.addEventListener("resize",L),{show:x,hide:L,toggle:x,update:z,addEventListeners:A,images:P,options:T}};"undefined"!=typeof window?window.mediumZoom=r:e&&e.exports&&(e.exports=r)}).call(t,n(1)(e))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children=[],e.webpackPolyfill=1),e}}])});
//# sourceMappingURL=medium-zoom.min.js.map