7 lines
2.7 KiB
JavaScript
Executable File
7 lines
2.7 KiB
JavaScript
Executable File
/*!
|
|
Zoom 1.7.21_ox
|
|
license: MIT
|
|
http://www.jacklmoore.com/zoom
|
|
edited by olegnax.com
|
|
*/ define(["jquery",],function(o){"use strict";var t={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};o.isFunc=function(o){return"function"==typeof o},o.zoom=function(t,e,n,i){var u,r,a,c,l,s,m,f=o(t),h=f.css("position"),d=o(e);return t.style.position=/(absolute|fixed)/.test(h)?h:"relative",t.style.overflow="hidden",n.style.width=n.style.height="",o(n).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:n.width*i,height:n.height*i,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(t),{init:function(){r=f.outerWidth(),u=f.outerHeight(),e===t?(c=r,a=u):(c=d.outerWidth(),a=d.outerHeight()),l=(n.width-r)/c,s=(n.height-u)/a,m=d.offset()},move:function(o){var t=o.pageX-m.left,e=o.pageY-m.top;e=Math.max(Math.min(e,a),0),t=Math.max(Math.min(t,c),0),n.style.left=-(t*l)+"px",n.style.top=-(e*s)+"px"}}},o.fn.zoom=function(e){return this.each(function(){var n=o.extend({},t,e||{}),i=n.target&&o(n.target)[0]||this,u=this,r=o(u),a=document.createElement("img"),c=o(a),l="mousemove.zoom",s=!1,m=!1;if(!n.url){var f=u.querySelector("img");if(f&&(n.url=f.getAttribute("data-full")||f.getAttribute("data-original")||f.getAttribute("data-src")||f.currentSrc||f.src),!n.url)return}r.one("zoom.destroy",(function(o,t){r.off(".zoom"),i.style.position=o,i.style.overflow=t,a.onload=null,c.remove()}).bind(this,i.style.position,i.style.overflow)),a.onload=function(){var t=o.zoom(i,u,a,n.magnify);function e(e){t.init(),t.move(e),c.stop().fadeTo(o.support.opacity?n.duration:0,1,!!o.isFunc(n.onZoomIn)&&n.onZoomIn.call(a))}function f(){c.stop().fadeTo(n.duration,0,!!o.isFunc(n.onZoomOut)&&n.onZoomOut.call(a))}"grab"===n.on?r.on("mousedown.zoom",function(n){1===n.which&&(o(document).one("mouseup.zoom",function(){f(),o(document).off(l,t.move)}),e(n),o(document).on(l,t.move),n.preventDefault())}):"click"===n.on?r.on("click.zoom",function(n){if(!s)return s=!0,e(n),o(document).on(l,t.move),o(document).one("click.zoom",function(){f(),s=!1,o(document).off(l,t.move)}),!1}):"toggle"===n.on?r.on("click.zoom",function(o){s?f():e(o),s=!s}):"mouseover"===n.on&&(t.init(),r.on("mouseenter.zoom",e).on("mouseleave.zoom",f).on(l,t.move)),n.touch&&r.on("touchstart.zoom",function(o){o.preventDefault(),m?(m=!1,f()):(m=!0,e(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(o){o.preventDefault(),t.move(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0])}).on("touchend.zoom",function(o){o.preventDefault(),m&&(m=!1,f())}),o.isFunc(n.callback)&&n.callback.call(a)},a.setAttribute("role","presentation"),a.alt="",a.src=n.url})},o.fn.zoom.defaults=t});
|