/*! fg-enlarge - v0.3.0 - 2017-08-29 * Copyright (c) 2017 Scott Jehl, Filament Group, Inc.; Licensed */ !function(a){var b=function(){var b=a.jQuery,c="enlarge";b.fn[c]=function(d){var e=arguments,f=b(this).data("options")||{button:!0,hoverZoomWithoutClick:!0,delay:300,flyout:{width:200,height:200},placement:"inline",magnification:3};"string"!=typeof d&&(f=b.extend(f,d),b(this).data("options",f));var g,h=this.each(function(){function h(){"inline"===f.placement?(D=C,N=M,w.data("zoomParent",N),L=K):(D=V.find("img")[0],N=L=V,w.data("zoomParent",N))}function i(){V.css({width:f.flyout.width+"px",height:f.flyout.height+"px",top:"",left:"","margin-left":"","margin-top":""});var a=f.placement.match(/left|right/);a&&V.css(a[0],-f.flyout.width+"px");var b=f.placement.match(/loupe/);b&&V.css({"margin-left":-f.flyout.width/2+"px","margin-top":-f.flyout.height/2+"px"}),V[0].className=V[0].className.replace(/enlarge_flyout\-[^$\s]+/," "),V.addClass("enlarge_flyout-"+f.placement)}function j(){f.disabled?w.addClass("enlarge_disabled"):w.removeClass("enlarge_disabled")}function k(){K.append('')}function l(){O=!w.data("zoomed"),w.data("zoomed",O)}function m(a){if(a=a||function(){},O){if(f.disabled)return a(),!1;var c=new Image;c.className="enlarge_img-loading",c.onload=function(){D.sizes=c.sizes,A&&F||(D.src=H),b(c).remove(),a()},c.sizes=p()+"px",A&&F?F&&(c.srcset=F):c.src=H,b(c).insertBefore(D)}else D.sizes=G,A||(D.src=E),a()}function n(){var a=L.width(),b=L.height(),c=D.offsetWidth,d=D.offsetHeight;L[0].scrollLeft=c/2-a/2,L[0].scrollTop=d/2-b/2}function o(){if(w.data("lockedZoom"))M.add(N).removeClass(P),w.data("lockedZoom",lockedZoom=!1),L.removeAttr("tabindex");else{if(f.disabled)return!1;M.add(N).addClass(P),w.data("lockedZoom",lockedZoom=!0),L.attr("tabindex","0"),L[0].focus()}}function p(){return M[0].offsetWidth*f.magnification}function q(){if(w.data("zoomed")){if(f.disabled)return!1;"inline"===f.placement&&K.add(M).css({width:M[0].offsetWidth+"px",height:parseFloat(getComputedStyle(M[0]).height)+"px"}),N.addClass(I),b(D).css("width",p()+"px"),b(x).trigger(c+".after-zoom-in")}else N.removeClass(I),"inline"===f.placement&&K.add(M).css({width:"",height:""}),b(D).css("width",""),b(x).trigger(c+".after-zoom-out")}function r(){function a(){f.placement=d,h(),b(x).unbind(c+".after-zoom-out",a)}var d=f.placement;"inline"!==d&&(b(x).bind(c+".after-zoom-out",a),f.placement="inline",h())}function s(){return f.disabled&&!w.data("zoomed")?!1:(l(),void m(function(){o(),q(),n()}))}function t(a){"touchstart"===a.type&&(T=!0),T&&"mouseenter"===a.type||"mouseenter"===a.type&&!T&&!U||w.data("lockedZoom")||S||(S=!0,K.addClass(J),R=setTimeout(function(){K.removeClass(J),l(),m(function(){q(),Q=!0,v(a)})},f.delay))}function u(a){K.removeClass(J),clearTimeout(R),Q=!1,f.hoverZoomWithoutClick!==!1||T||(U=!1),T&&"mouseleave"===a.type&&(T=!1)}function v(a){if(Q){if(T&&"mousemove"===a.type)return;var b=a.touches?a.touches[0]:a;a.preventDefault();var c=b.clientX-K[0].getBoundingClientRect().left,d=b.clientY-K[0].getBoundingClientRect().top;if(f.placement.match(/loupe/)){var e=(a.touches?-f.flyout.width/1.3:-f.flyout.width/2)+"px",g=(a.touches?-f.flyout.height/1.3:-f.flyout.height/2)+"px";requestAnimationFrame(function(){V.css({top:d+"px",left:c+"px","margin-left":e,"margin-top":g})})}var h=K[0].offsetWidth,i=K[0].offsetHeight,j=D.offsetWidth,k=D.offsetHeight,l=L[0].offsetWidth,m=L[0].offsetHeight;L[0].scrollLeft=c/h*(j-l),L[0].scrollTop=d/i*(k-m)}}var w=b(this),x=this,y=a.document.createElement("img"),z="srcset"in y,A=z&&"sizes"in y,B=b(this).find("a");if(!B.length)throw new Error(c+": requires an anchor element with `href` for the enlarged image source");var C=w.find("img")[0],D=C,E=D.src,F=b(D).attr("srcset"),G=b(D).attr("sizes"),H=B[0].href,I=(B[0].innerText,c+"-zoomed"),J=c+"-delay",K=b(D).closest(".enlarge_contain"),L=K,M=b(D).closest(".enlarge_pane")||w,N=b(this).data("zoomParent")||M;b(this).data("zoomParent",N);var O=w.data("zoomed")||!1;w.data("zoomed",O),w.data("lockedZoom",w.data("lockedZoom")||!1);var P=c+"-locked";if(!K.length)throw new Error(c+": requires an element above the image marked with the class `enlarge_contain`");if("string"!=typeof d){j(),w.data("updateOptions",function(a){f=b.extend(f,a),b(this).data("options",f),h(),i(),U=f.hoverZoomWithoutClick,f.image&&f.image.sizes&&(G=f.image.sizes,m()),j(),f.disabled&&w.data("zoomed")&&s()});var Q,R,S,T,U=f.hoverZoomWithoutClick,V=b('
').append(K.clone());V.insertAfter(M),k(),h(),i(),B.bind("keydown",function(a){(13===a.keyCode||32===a.keyCode)&&r(),32===a.keyCode&&(a.preventDefault(),b(this).trigger("click"))}).bind("click",function(a){a.preventDefault(),s()}),b(a).bind("resize",function(a){w.data("lockedZoom")&&s()}),b(a.document).bind("mouseup",function(a){w.data("lockedZoom")&&!b(a.target).closest(M).length&&s()}),b(C).bind("mouseenter touchstart",t).bind("mousemove touchmove",v).bind("mouseleave touchend",function(a){S=!1,O&&!w.data("lockedZoom")&&(l(),m(function(){q()})),u(a)}).bind("click",function(a){a.preventDefault(),T&&"inline"===f.placement&&s(),f.hoverZoomWithoutClick!==!1||T||(U=!U,U?b(this).trigger("mouseenter"):b(this).trigger("mouseleave"))}),b(this).bind("keydown keyup",function(a){37===a.keyCode||38===a.keyCode||39===a.keyCode||40===a.keyCode?(a.stopImmediatePropagation(),w.data("lockedZoom")||a.preventDefault()):"keyup"===a.type&&b(this).data("lockedZoom")&&27===a.keyCode&&(s(),B[0].focus(),a.stopImmediatePropagation())}),M.bind("scroll",function(){w.data("zoomed")&&(l(),m(function(){w.data("lockedZoom")&&o(),q()}))})}else{var W=Array.prototype.slice.call(e,1);switch(d){case"in":w.data("zoomed")||s();break;case"out":w.data("zoomed")&&s();break;case"isZoomed":g=w.data("zoomed");break;case"updateOptions":w.data("updateOptions")(W[0])}}});return void 0!==g?g:h}};"undefined"!=typeof module?module.exports=b:b()}("undefined"!=typeof global?global:this);