diff --git a/jquery.zoom.js b/jquery.zoom.js index 9757bfa..f165e83 100644 --- a/jquery.zoom.js +++ b/jquery.zoom.js @@ -1,5 +1,5 @@ /*! - Zoom 1.7.18 + Zoom 1.7.22 license: MIT http://www.jacklmoore.com/zoom */ @@ -124,12 +124,12 @@ // Skip the fade-in for IE8 and lower since it chokes on fading-in // and changing position based on mousemovement at the same time. $img.stop() - .fadeTo($.support.opacity ? settings.duration : 0, 1, $.isFunction(settings.onZoomIn) ? settings.onZoomIn.call(img) : false); + .fadeTo($.support.opacity ? settings.duration : 0, 1, typeof settings.onZoomIn === "function" ? settings.onZoomIn.call(img) : false); } function stop() { $img.stop() - .fadeTo(settings.duration, 0, $.isFunction(settings.onZoomOut) ? settings.onZoomOut.call(img) : false); + .fadeTo(settings.duration, 0, typeof settings.onZoomOut === "function" ? settings.onZoomOut.call(img) : false); } // Mouse events @@ -220,12 +220,14 @@ } }); } - - if ($.isFunction(settings.callback)) { + + if (typeof settings.callback === "function") { settings.callback.call(img); } }; + img.setAttribute('role', 'presentation'); + img.alt = ''; img.src = settings.url; }); }; diff --git a/jquery.zoom.min.js b/jquery.zoom.min.js index 0bbb206..ce06f6b 100644 --- a/jquery.zoom.min.js +++ b/jquery.zoom.min.js @@ -1,6 +1,6 @@ /*! - Zoom 1.7.18 + Zoom 1.7.22 license: MIT http://www.jacklmoore.com/zoom */ -(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); \ No newline at end of file +(d=>{var n={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};d.zoom=function(o,t,e,n){var i,u,c,a,r,m,l,f=d(o),s=f.css("position"),h=d(t);return o.style.position=/(absolute|fixed)/.test(s)?s:"relative",o.style.overflow="hidden",e.style.width=e.style.height="",d(e).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:e.width*n,height:e.height*n,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(o),{init:function(){u=f.outerWidth(),i=f.outerHeight(),c=t===o?(a=u,i):(a=h.outerWidth(),h.outerHeight()),r=(e.width-u)/a,m=(e.height-i)/c,l=h.offset()},move:function(o){var t=o.pageX-l.left,o=o.pageY-l.top,o=Math.max(Math.min(o,c),0),t=Math.max(Math.min(t,a),0);e.style.left=t*-r+"px",e.style.top=o*-m+"px"}}},d.fn.zoom=function(e){return this.each(function(){var i=d.extend({},n,e||{}),u=i.target&&d(i.target)[0]||this,o=this,c=d(o),a=document.createElement("img"),r=d(a),m="mousemove.zoom",l=!1,f=!1;if(!i.url){var t=o.querySelector("img");if(t&&(i.url=t.getAttribute("data-src")||t.currentSrc||t.src),!i.url)return}c.one("zoom.destroy",function(o,t){c.off(".zoom"),u.style.position=o,u.style.overflow=t,a.onload=null,r.remove()}.bind(this,u.style.position,u.style.overflow)),a.onload=function(){var t=d.zoom(u,o,a,i.magnify);function e(o){t.init(),t.move(o),r.stop().fadeTo(d.support.opacity?i.duration:0,1,"function"==typeof i.onZoomIn&&i.onZoomIn.call(a))}function n(){r.stop().fadeTo(i.duration,0,"function"==typeof i.onZoomOut&&i.onZoomOut.call(a))}"grab"===i.on?c.on("mousedown.zoom",function(o){1===o.which&&(d(document).one("mouseup.zoom",function(){n(),d(document).off(m,t.move)}),e(o),d(document).on(m,t.move),o.preventDefault())}):"click"===i.on?c.on("click.zoom",function(o){if(!l)return l=!0,e(o),d(document).on(m,t.move),d(document).one("click.zoom",function(){n(),l=!1,d(document).off(m,t.move)}),!1}):"toggle"===i.on?c.on("click.zoom",function(o){l?n():e(o),l=!l}):"mouseover"===i.on&&(t.init(),c.on("mouseenter.zoom",e).on("mouseleave.zoom",n).on(m,t.move)),i.touch&&c.on("touchstart.zoom",function(o){o.preventDefault(),f?(f=!1,n()):(f=!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(),f&&(f=!1,n())}),"function"==typeof i.callback&&i.callback.call(a)},a.setAttribute("role","presentation"),a.alt="",a.src=i.url})},d.fn.zoom.defaults=n})(window.jQuery); diff --git a/package.json b/package.json index e205e77..057dc81 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery-zoom", "description": "Enlarge images on click or mouseover.", - "version": "1.7.18", + "version": "1.7.22", "keywords": [ "zoom", "images", diff --git a/readme.md b/readme.md index 74a066b..89ec15e 100644 --- a/readme.md +++ b/readme.md @@ -2,10 +2,22 @@ A small jQuery plugin for zooming images on mouseover or mousedown. See the [project page](http://jacklmoore.com/zoom/) for documentation and a demonstration. Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php). -To compile the .min.js file, run: `uglifyjs --comments '/license:/' < jquery.zoom.js > jquery.zoom.min.js` +To compile the .min.js file, run: `uglifyjs -c -m --comments '/license:/' < jquery.zoom.js > jquery.zoom.min.js` ## Changelog: +##### v1.7.22 - 2025/9/7 +* Removed $.isFunction for jQuery 4 compatibility. Merged #161 + +##### v1.7.21 - 2018/4/26 +* Added empty alt attribute. Resolves #134 + +##### v1.7.20 - 2017/4/25 +* Replaced alt and aria-hidden with role attribute. Resolves #121 + +##### v1.7.19 - 2017/4/20 +* Added alt and aria-hidden attributes to the zoom layer img element. Merged #121 + ##### v1.7.18 - 2016/9/9 * Fixed regression from 1.7.16 that occurred when the target option was passed a selector. Fixes #113