forked from caleboleary/jQuery-Extended-Mag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextm.min.js
8 lines (8 loc) · 3.08 KB
/
extm.min.js
1
2
3
4
5
6
7
8
/*
jQuery Extended Mag(nify)
Author: Caleb O'Leary
Site: http://caleboleary.com
Current Version: https://github.com/caleboleary/jQuery-Extended-Mag
MIT License
*/
!function(t){"use strict";t.fn.extend({extm:function(e){function i(e,i){var s,o=i.width(),n=i.height(),a=i.offset();e.zoomElement?s=e.zoomElement:(s=t("<div style='overflow:hidden;pointer-events:none;height:"+n+"px;width:"+o+"px;' class='extm'></div>"),"right"===e.position?(s.appendTo(t("body")),s.css("position","absolute"),s.css("top",a.top),s.css("left",a.left+o+e.rightPad)):"overlay"===e.position?(s.appendTo(t("body")),s.css("position","absolute"),s.css("top",a.top),s.css("left",a.left)):s.insertAfter(i));var r,l;if(e.squareOverlay&&(r=t("<div class='overlayElement' style='pointer-events:none;height:"+n+"px;width:"+o+"px;position:absolute;top:"+a.top+"px;left:"+a.left+"px;'></div>"),t("body").append(r),l=t("<div style='background-color:rgba(0,0,0,0.2);position:absolute;' class='innerOverlay'></div>"),r.append(l)),e.lazy||(s.css("visibility","hidden"),e.squareOverlay&&l.css("visibility","hidden")),e.zoomSize)var h=t('<img style="position:relative;max-width:none;width:'+e.zoomSize+'px;">');else if(1!==e.zoomLevel)var h=t('<img style="position:relative;max-width:none;width:'+100*e.zoomLevel+'%;">');else var h=t('<img style="position:relative;max-width:none;">');e.imageSrc?h.attr("src",e.imageSrc):h.attr("src",i.attr("src")),h.appendTo(s),function(t,e,i,s,o,n,a,r,l){i.load(function(){t.on("mouseenter",function(){a=t.offset(),"right"===l.position?(e.css("top",a.top),e.css("left",a.left+n+l.rightPad)):"overlay"===l.position&&(e.css("top",a.top),e.css("left",a.left)),l.squareOverlay&&(s.css("top",a.top),s.css("left",a.left)),e.css("visibility","visible"),l.squareOverlay&&r.css("visibility","visible")}),t.on("mouseleave",function(){e.css("visibility","hidden"),l.squareOverlay&&r.css("visibility","hidden")});var h=i.width(),c=i.height(),p=h/n,d=c/o,v=0-(h-e.width()),m=0-(c-e.height());if(l.squareOverlay){var f=n/h*n,u=o/c*o;r.css("height",u),r.css("width",f)}t.on("mousemove",function(e){a=t.offset();var s=o/2-(e.pageY-a.top)*d;s=Math.max(s,m),s=Math.min(s,0);var h=n/2-(e.pageX-a.left)*p;if(h=Math.max(h,v),h=Math.min(h,0),i.css("top",s),i.css("left",h),l.squareOverlay){var c=e.pageY-a.top-r.height()/2;c=Math.max(c,0),c=Math.min(c,o-r.height());var f=e.pageX-a.left-r.width()/2;f=Math.max(f,0),f=Math.min(f,n-r.width()),r.css("top",c),r.css("left",f)}})})}(i,s,h,r,n,o,a,l,e),i.on("extmdestroy",function(){s.remove(),e.squareOverlay&&r.remove()}),i.on("updateImage",function(t,e){h.attr("src",e)})}var s={zoomElement:!1,imageSrc:t(this).attr("src"),squareOverlay:!1,position:!1,rightPad:0,lazy:!1,zoomLevel:1,zoomSize:!1},o=t.extend({},s,e||{});o.lazy?t(this).width()>10&&t(this).height()>10?t(this).one("mouseenter",function(){i(o,t(this))}):t(this).one("load",function(){t(this).one("mouseenter",function(){i(o,t(this))})}):t(this).width()>10&&t(this).height()>10?i(o,t(this)):t(this).one("load",function(){i(o,t(this))})},extmDestroy:function(){t(this).trigger("extmdestroy")},extmImageUpdate:function(e){t(this).trigger("updateImage",e)}})}(jQuery);