woocommerce/assets/js/zoom/jquery.zoom.min.js

6 lines
2.5 KiB
JavaScript
Executable File

/*!
Zoom 1.7.15
license: MIT
http://www.jacklmoore.com/zoom
*/
!function(a){var b={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};a.zoom=function(b,c,d,e){var f,g,h,i,j,k,l,m=a(b),n=m.css("position"),o=a(c);return m.css("position",/(absolute|fixed)/.test(n)?n:"relative"),m.css("overflow","hidden"),d.style.width=d.style.height="",a(d).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:d.width*e,height:d.height*e,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(b),{init:function(){g=m.outerWidth(),f=m.outerHeight(),c===m[0]?(i=g,h=f):(i=o.outerWidth(),h=o.outerHeight()),j=(d.width-g)/i,k=(d.height-f)/h,l=o.offset()},move:function(a){var b=a.pageX-l.left,c=a.pageY-l.top;c=Math.max(Math.min(c,h),0),b=Math.max(Math.min(b,i),0),d.style.left=b*-j+"px",d.style.top=c*-k+"px"}}},a.fn.zoom=function(c){return this.each(function(){var d,e=a.extend({},b,c||{}),f=e.target||this,g=this,h=a(g),i=a(f),j=document.createElement("img"),k=a(j),l="mousemove.zoom",m=!1,n=!1;(e.url||(d=h.find("img"),d[0]&&(e.url=d.data("src")||d.attr("src")),e.url))&&(!function(){var a=i.css("position"),b=i.css("overflow");h.one("zoom.destroy",function(){h.off(".zoom"),i.css("position",a),i.css("overflow",b),k.remove()})}(),j.onload=function(){function b(b){d.init(),d.move(b),k.stop().fadeTo(a.support.opacity?e.duration:0,1,!!a.isFunction(e.onZoomIn)&&e.onZoomIn.call(j))}function c(){k.stop().fadeTo(e.duration,0,!!a.isFunction(e.onZoomOut)&&e.onZoomOut.call(j))}var d=a.zoom(f,g,j,e.magnify);"grab"===e.on?h.on("mousedown.zoom",function(e){1===e.which&&(a(document).one("mouseup.zoom",function(){c(),a(document).off(l,d.move)}),b(e),a(document).on(l,d.move),e.preventDefault())}):"click"===e.on?h.on("click.zoom",function(e){return m?void 0:(m=!0,b(e),a(document).on(l,d.move),a(document).one("click.zoom",function(){c(),m=!1,a(document).off(l,d.move)}),!1)}):"toggle"===e.on?h.on("click.zoom",function(a){m?c():b(a),m=!m}):"mouseover"===e.on&&(d.init(),h.on("mouseenter.zoom",b).on("mouseleave.zoom",c).on(l,d.move)),e.touch&&h.on("touchstart.zoom",function(a){a.preventDefault(),n?(n=!1,c()):(n=!0,b(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(a){a.preventDefault(),d.move(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0])}).on("touchend.zoom",function(a){a.preventDefault(),n&&(n=!1,c())}),a.isFunction(e.callback)&&e.callback.call(j)},j.src=e.url)})},a.fn.zoom.defaults=b}(window.jQuery);