Update Zoom to 1.7.18

This commit is contained in:
Caleb Burks 2017-01-31 22:47:25 -06:00
parent 5b221b4ed0
commit 4e59f08918
2 changed files with 19 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/*!
Zoom 1.7.15
Zoom 1.7.18
license: MIT
http://www.jacklmoore.com/zoom
*/
@ -30,9 +30,8 @@
$source = $(source);
// The parent element needs positioning so that the zoomed element can be correctly positioned within.
$target.css('position', /(absolute|fixed)/.test(position) ? position : 'relative');
$target.css('overflow', 'hidden');
target.style.position = /(absolute|fixed)/.test(position) ? position : 'relative';
target.style.overflow = 'hidden';
img.style.width = img.style.height = '';
$(img)
@ -55,7 +54,7 @@
targetWidth = $target.outerWidth();
targetHeight = $target.outerHeight();
if (source === $target[0]) {
if (source === target) {
sourceWidth = targetWidth;
sourceHeight = targetHeight;
} else {
@ -86,41 +85,34 @@
var
settings = $.extend({}, defaults, options || {}),
//target will display the zoomed image
target = settings.target || this,
target = settings.target && $(settings.target)[0] || this,
//source will provide zoom location info (thumbnail)
source = this,
$source = $(source),
$target = $(target),
img = document.createElement('img'),
$img = $(img),
mousemove = 'mousemove.zoom',
clicked = false,
touched = false,
$urlElement;
touched = false;
// If a url wasn't specified, look for an image element.
if (!settings.url) {
$urlElement = $source.find('img');
if ($urlElement[0]) {
settings.url = $urlElement.data('src') || $urlElement.attr('src');
var srcElement = source.querySelector('img');
if (srcElement) {
settings.url = srcElement.getAttribute('data-src') || srcElement.currentSrc || srcElement.src;
}
if (!settings.url) {
return;
}
}
(function(){
var position = $target.css('position');
var overflow = $target.css('overflow');
$source.one('zoom.destroy', function(){
$source.off(".zoom");
$target.css('position', position);
$target.css('overflow', overflow);
$img.remove();
});
}());
$source.one('zoom.destroy', function(position, overflow){
$source.off(".zoom");
target.style.position = position;
target.style.overflow = overflow;
img.onload = null;
$img.remove();
}.bind(this, target.style.position, target.style.overflow));
img.onload = function () {
var zoom = $.zoom(target, source, img, settings.magnify);
@ -228,7 +220,7 @@
}
});
}
if ($.isFunction(settings.callback)) {
settings.callback.call(img);
}

View File

@ -1,6 +1,6 @@
/*!
Zoom 1.7.15
Zoom 1.7.18
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);
(function(o){var t={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};o.zoom=function(t,n,e,i){var u,c,a,r,m,l,s,f=o(t),h=f.css("position"),d=o(n);return t.style.position=/(absolute|fixed)/.test(h)?h:"relative",t.style.overflow="hidden",e.style.width=e.style.height="",o(e).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:e.width*i,height:e.height*i,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(t),{init:function(){c=f.outerWidth(),u=f.outerHeight(),n===t?(r=c,a=u):(r=d.outerWidth(),a=d.outerHeight()),m=(e.width-c)/r,l=(e.height-u)/a,s=d.offset()},move:function(o){var t=o.pageX-s.left,n=o.pageY-s.top;n=Math.max(Math.min(n,a),0),t=Math.max(Math.min(t,r),0),e.style.left=t*-m+"px",e.style.top=n*-l+"px"}}},o.fn.zoom=function(n){return this.each(function(){var e=o.extend({},t,n||{}),i=e.target&&o(e.target)[0]||this,u=this,c=o(u),a=document.createElement("img"),r=o(a),m="mousemove.zoom",l=!1,s=!1;if(!e.url){var f=u.querySelector("img");if(f&&(e.url=f.getAttribute("data-src")||f.currentSrc||f.src),!e.url)return}c.one("zoom.destroy",function(o,t){c.off(".zoom"),i.style.position=o,i.style.overflow=t,a.onload=null,r.remove()}.bind(this,i.style.position,i.style.overflow)),a.onload=function(){function t(t){f.init(),f.move(t),r.stop().fadeTo(o.support.opacity?e.duration:0,1,o.isFunction(e.onZoomIn)?e.onZoomIn.call(a):!1)}function n(){r.stop().fadeTo(e.duration,0,o.isFunction(e.onZoomOut)?e.onZoomOut.call(a):!1)}var f=o.zoom(i,u,a,e.magnify);"grab"===e.on?c.on("mousedown.zoom",function(e){1===e.which&&(o(document).one("mouseup.zoom",function(){n(),o(document).off(m,f.move)}),t(e),o(document).on(m,f.move),e.preventDefault())}):"click"===e.on?c.on("click.zoom",function(e){return l?void 0:(l=!0,t(e),o(document).on(m,f.move),o(document).one("click.zoom",function(){n(),l=!1,o(document).off(m,f.move)}),!1)}):"toggle"===e.on?c.on("click.zoom",function(o){l?n():t(o),l=!l}):"mouseover"===e.on&&(f.init(),c.on("mouseenter.zoom",t).on("mouseleave.zoom",n).on(m,f.move)),e.touch&&c.on("touchstart.zoom",function(o){o.preventDefault(),s?(s=!1,n()):(s=!0,t(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(o){o.preventDefault(),f.move(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0])}).on("touchend.zoom",function(o){o.preventDefault(),s&&(s=!1,n())}),o.isFunction(e.callback)&&e.callback.call(a)},a.src=e.url})},o.fn.zoom.defaults=t})(window.jQuery);