!function(n){"use strict";function t(t,i){this.$target=n(t);this.opts=n.extend({},s,i,this.$target.data());void 0===this.isOpen&&this._init()}var u,f,e,o,i,r,s={loadingNotice:"Loading image",errorNotice:"The image could not be loaded",errorDuration:2500,preventClicks:!0,onShow:n.noop,onHide:n.noop,onMove:n.noop};t.prototype._init=function(){this.$link=this.$target.find("a");this.$image=this.$target.find("img");this.$flyout=n('<div class="easyzoom-flyout" />');this.$notice=n('<div class="easyzoom-notice" />');this.$target.on({"mousemove.easyzoom touchmove.easyzoom":n.proxy(this._onMove,this),"mouseleave.easyzoom touchend.easyzoom":n.proxy(this._onLeave,this),"mouseenter.easyzoom touchstart.easyzoom":n.proxy(this._onEnter,this)});this.opts.preventClicks&&this.$target.on("click.easyzoom",function(n){n.preventDefault()})};t.prototype.show=function(n,t){var i,r,s,h,c=this;return this.isReady?(this.$target.append(this.$flyout),i=this.$target.width(),r=this.$target.height(),s=this.$flyout.width(),h=this.$flyout.height(),u=this.$zoom.width()-s,f=this.$zoom.height()-h,e=u/i,o=f/r,this.isOpen=!0,this.opts.onShow.call(this),void(n&&this._move(n))):this._loadImage(this.$link.attr("href"),function(){(c.isMouseOver||!t)&&c.show(n)})};t.prototype._onEnter=function(n){var t=n.originalEvent.touches;this.isMouseOver=!0;t&&1!=t.length||(n.preventDefault(),this.show(n,!0))};t.prototype._onMove=function(n){this.isOpen&&(n.preventDefault(),this._move(n))};t.prototype._onLeave=function(){this.isMouseOver=!1;this.isOpen&&this.hide()};t.prototype._onLoad=function(n){n.currentTarget.width&&(this.isReady=!0,this.$notice.detach(),this.$flyout.html(this.$zoom),this.$target.removeClass("is-loading").addClass("is-ready"),n.data.call&&n.data())};t.prototype._onError=function(){var n=this;this.$notice.text(this.opts.errorNotice);this.$target.removeClass("is-loading").addClass("is-error");this.detachNotice=setTimeout(function(){n.$notice.detach();n.detachNotice=null},this.opts.errorDuration)};t.prototype._loadImage=function(t,i){var r=new Image;this.$target.addClass("is-loading").append(this.$notice.text(this.opts.loadingNotice));this.$zoom=n(r).on("error",n.proxy(this._onError,this)).on("load",i,n.proxy(this._onLoad,this));r.style.position="absolute";r.src=t};t.prototype._move=function(n){var t,c,l;0===n.type.indexOf("touch")?(t=n.touches||n.originalEvent.touches,i=t[0].pageX,r=t[0].pageY):(i=n.pageX||i,r=n.pageY||r);var a=this.$target.offset(),v=r-a.top,y=i-a.left,s=Math.ceil(v*o),h=Math.ceil(y*e);0>h||0>s||h>u||s>f?this.hide():(c=-1*s,l=-1*h,this.$zoom.css({top:c,left:l}),this.opts.onMove.call(this,c,l))};t.prototype.hide=function(){this.isOpen&&(this.$flyout.detach(),this.isOpen=!1,this.opts.onHide.call(this))};t.prototype.swap=function(t,i,r){this.hide();this.isReady=!1;this.detachNotice&&clearTimeout(this.detachNotice);this.$notice.parent().length&&this.$notice.detach();this.$target.removeClass("is-loading is-ready is-error");this.$image.attr({src:t,srcset:n.isArray(r)?r.join():r});this.$link.attr("href",i)};t.prototype.teardown=function(){this.hide();this.$target.off(".easyzoom").removeClass("is-loading is-ready is-error");this.detachNotice&&clearTimeout(this.detachNotice);delete this.$link;delete this.$zoom;delete this.$image;delete this.$notice;delete this.$flyout;delete this.isOpen;delete this.isReady};n.fn.easyZoom=function(i){return this.each(function(){var r=n.data(this,"easyZoom");r?void 0===r.isOpen&&r._init():n.data(this,"easyZoom",new t(this,i))})};"function"==typeof define&&define.amd?define(function(){return t}):"undefined"!=typeof module&&module.exports&&(module.exports=t)}(jQuery)