force-test2/static/js/zomm_img.js

1 line
9.0 KiB
JavaScript
Raw Permalink Normal View History

2022-04-22 11:07:34 +08:00
!function(){function o(e){return"IMG"===e.tagName}function E(e){return e&&1===e.nodeType}function c(e){return".svg"===(e.currentSrc||e.src).substr(-4).toLowerCase()}function m(e){try{return Array.isArray(e)?e.filter(o):(t=e,NodeList.prototype.isPrototypeOf(t)?[].slice.call(e).filter(o):E(e)?[e].filter(o):"string"==typeof e?[].slice.call(document.querySelectorAll(e)).filter(o):[])}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")}var t}function w(e,t){var o=l({bubbles:!1,cancelable:!1,detail:void 0},t);return"function"==typeof window.CustomEvent?new CustomEvent(e,o):((t=document.createEvent("CustomEvent")).initCustomEvent(e,o.bubbles,o.cancelable,o.detail),t)}function a(e,t){function o(e){function u(){var e={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight,left:0,top:0,right:0,bottom:0},t=void 0,o=void 0;v.container&&(v.container instanceof Object?(t=(e=l({},e,v.container)).width-e.left-e.right-2*v.margin,o=e.height-e.top-e.bottom-2*v.margin):(d=(i=(E(v.container)?v.container:document.querySelector(v.container)).getBoundingClientRect()).width,a=i.height,r=i.left,m=i.top,e=l({},e,{width:d,height:a,left:r,top:m}))),t=t||e.width-2*v.margin,o=o||e.height-2*v.margin;var n=z.zoomedHd||z.original,i=!c(n)&&n.naturalWidth||t,d=!c(n)&&n.naturalHeight||o,r=(a=n.getBoundingClientRect()).top,m=a.left,n=a.width,a=a.height,i=Math.min(i,t)/n,d=Math.min(d,o)/a,d="scale("+(d=Math.min(i,d))+") translate3d("+((t-n)/2-m+v.margin+e.left)/d+"px, "+((o-a)/2-r+v.margin+e.top)/d+"px, 0)";z.zoomed.style.transform=d,z.zoomedHd&&(z.zoomedHd.style.transform=d)}var s=(0<arguments.length&&void 0!==e?e:{}).target;return new i(function(e){if(s&&-1===f.indexOf(s))e(b);else{function t(){g=!1,z.zoomed.removeEventListener("transitionend",t),z.original.dispatchEvent(w("medium-zoom:opened",{detail:{zoom:b}})),e(b)}var o,n,i,d,r,m,a,c,l;if(z.zoomed)e(b);else{if(s)z.original=s;else{if(!(0<f.length))return void e(b);z.original=f[0]}z.original.dispatchEvent(w("medium-zoom:open",{detail:{zoom:b}})),h=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,g=!0,z.zoomed=(o=z.original,n=o.getBoundingClientRect(),i=n.top,d=n.left,r=n.width,m=n.height,a=o.cloneNode(),n=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0,o=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0,a.removeAttribute("id"),a.style.position="absolute",a.style.top=i+n+"px",a.style.left=d+o+"px",a.style.width=r+"px",a.style.height=m+"px",a.style.transform="",a),document.body.appendChild(y),v.template&&(a=E(v.template)?v.template:document.querySelector(v.template),z.template=document.createElement("div"),z.template.appendChild(a.content.cloneNode(!0)),document.body.appendChild(z.template)),document.body.appendChild(z.zoomed),window.requestAnimationFrame(function(){document.body.classList.add("medium-zoom--opened")}),z.original.classList.add("medium-zoom-image--hidden"),z.zoomed.classList.add("medium-zoom-image--opened"),z.zoomed.addEventListener("click",p),z.zoomed.addEventListener("transitionend",t),z.original.getAttribute("data-zoom-src")?(z.zoomedHd=z.zoomed.cloneNode(),z.zoomedHd.removeAttribute("srcset"),z.zoomedHd.removeAttribute("sizes"),z.zoomedHd.src=z.zoomed.getAttribute("data-zoom-src"),z.zoomedHd.onerror=function(){clearInterval(c),console.warn("Unable to reach the zoom image target "+z.zoomedHd.src),z.zoomedHd=null,u()},c=setInterval(function(){z.zoomedHd.complete&&(clearInterval(c),z.zoomedHd.classList.add("medium-zoom-image--opened"),z.zoomedHd.addEventListener("click",p),document.body.appendChild(z.zoomedHd),u())},10)):z.original.hasAttribute("srcset")?(z.zoomedHd=z.zoomed.cloneNode(),z.zoomedHd.removeAttribute("sizes"),z.zoomedHd.removeAttribute("loading"),l=z.zoomedHd.addEventListener("load",function(){z.zoomedHd.removeEventListener("load",l),z.zoomedHd.classList.add("medium-zoom-image--opened"),z.zoomedHd.addEventListen