/*! lg-zoom - v1.1.0 - 2017-08-08
* http://sachinchoolur.github.io/lightgallery
* copyright (c) 2017 sachin n; licensed gplv3 */
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jquery)}(this,function(a){!function(){"use strict";var b=function(){var a=!1,b=navigator.useragent.match(/chrom(e|ium)\/([0-9]+)\./);return b&&parseint(b[2],10)<54&&(a=!0),a},c={scale:1,zoom:!0,actualsize:!0,enablezoomafter:300,useleftforzoom:b()},d=function(b){return this.core=a(b).data("lightgallery"),this.core.s=a.extend({},c,this.core.s),this.core.s.zoom&&this.core.docss()&&(this.init(),this.zoomabletimeout=!1,this.pagex=a(window).width()/2,this.pagey=a(window).height()/2+a(window).scrolltop()),this};d.prototype.init=function(){var b=this,c='';b.core.s.actualsize&&(c+=''),b.core.s.useleftforzoom?b.core.$outer.addclass("lg-use-left-for-zoom"):b.core.$outer.addclass("lg-use-transition-for-zoom"),this.core.$outer.find(".lg-toolbar").append(c),b.core.$el.on("onslideitemload.lg.tm.zoom",function(c,d,e){var f=b.core.s.enablezoomafter+e;a("body").hasclass("lg-from-hash")&&e?f=0:a("body").removeclass("lg-from-hash"),b.zoomabletimeout=settimeout(function(){b.core.$slide.eq(d).addclass("lg-zoomable")},f+30)});var d=1,e=function(c){var d,e,f=b.core.$outer.find(".lg-current .lg-image"),g=(a(window).width()-f.prop("offsetwidth"))/2,h=(a(window).height()-f.prop("offsetheight"))/2+a(window).scrolltop();d=b.pagex-g,e=b.pagey-h;var i=(c-1)*d,j=(c-1)*e;f.css("transform","scale3d("+c+", "+c+", 1)").attr("data-scale",c),b.core.s.useleftforzoom?f.parent().css({left:-i+"px",top:-j+"px"}).attr("data-x",i).attr("data-y",j):f.parent().css("transform","translate3d(-"+i+"px, -"+j+"px, 0)").attr("data-x",i).attr("data-y",j)},f=function(){d>1?b.core.$outer.addclass("lg-zoomed"):b.resetzoom(),d<1&&(d=1),e(d)},g=function(c,e,g,h){var i,j=e.prop("offsetwidth");i=b.core.s.dynamic?b.core.s.dynamicel[g].width||e[0].naturalwidth||j:b.core.$items.eq(g).attr("data-width")||e[0].naturalwidth||j;var k;b.core.$outer.hasclass("lg-zoomed")?d=1:i>j&&(k=i/j,d=k||2),h?(b.pagex=a(window).width()/2,b.pagey=a(window).height()/2+a(window).scrolltop()):(b.pagex=c.pagex||c.originalevent.targettouches[0].pagex,b.pagey=c.pagey||c.originalevent.targettouches[0].pagey),f(),settimeout(function(){b.core.$outer.removeclass("lg-grabbing").addclass("lg-grab")},10)},h=!1;b.core.$el.on("onaferappendslide.lg.tm.zoom",function(a,c){var d=b.core.$slide.eq(c).find(".lg-image");d.on("dblclick",function(a){g(a,d,c)}),d.on("touchstart",function(a){h?(cleartimeout(h),h=null,g(a,d,c)):h=settimeout(function(){h=null},300),a.preventdefault()})}),a(window).on("resize.lg.zoom scroll.lg.zoom orientationchange.lg.zoom",function(){b.pagex=a(window).width()/2,b.pagey=a(window).height()/2+a(window).scrolltop(),e(d)}),a("#lg-zoom-out").on("click.lg",function(){b.core.$outer.find(".lg-current .lg-image").length&&(d-=b.core.s.scale,f())}),a("#lg-zoom-in").on("click.lg",function(){b.core.$outer.find(".lg-current .lg-image").length&&(d+=b.core.s.scale,f())}),a("#lg-actual-size").on("click.lg",function(a){g(a,b.core.$slide.eq(b.core.index).find(".lg-image"),b.core.index,!0)}),b.core.$el.on("onbeforeslide.lg.tm",function(){d=1,b.resetzoom()}),b.zoomdrag(),b.zoomswipe()},d.prototype.resetzoom=function(){this.core.$outer.removeclass("lg-zoomed"),this.core.$slide.find(".lg-img-wrap").removeattr("style data-x data-y"),this.core.$slide.find(".lg-image").removeattr("style data-scale"),this.pagex=a(window).width()/2,this.pagey=a(window).height()/2+a(window).scrolltop()},d.prototype.zoomswipe=function(){var a=this,b={},c={},d=!1,e=!1,f=!1;a.core.$slide.on("touchstart.lg",function(c){if(a.core.$outer.hasclass("lg-zoomed")){var d=a.core.$slide.eq(a.core.index).find(".lg-object");f=d.prop("offsetheight")*d.attr("data-scale")>a.core.$outer.find(".lg").height(),e=d.prop("offsetwidth")*d.attr("data-scale")>a.core.$outer.find(".lg").width(),(e||f)&&(c.preventdefault(),b={x:c.originalevent.targettouches[0].pagex,y:c.originalevent.targettouches[0].pagey})}}),a.core.$slide.on("touchmove.lg",function(g){if(a.core.$outer.hasclass("lg-zoomed")){var h,i,j=a.core.$slide.eq(a.core.index).find(".lg-img-wrap");g.preventdefault(),d=!0,c={x:g.originalevent.targettouches[0].pagex,y:g.originalevent.targettouches[0].pagey},a.core.$outer.addclass("lg-zoom-dragging"),i=f?-math.abs(j.attr("data-y"))+(c.y-b.y):-math.abs(j.attr("data-y")),h=e?-math.abs(j.attr("data-x"))+(c.x-b.x):-math.abs(j.attr("data-x")),(math.abs(c.x-b.x)>15||math.abs(c.y-b.y)>15)&&(a.core.s.useleftforzoom?j.css({left:h+"px",top:i+"px"}):j.css("transform","translate3d("+h+"px, "+i+"px, 0)"))}}),a.core.$slide.on("touchend.lg",function(){a.core.$outer.hasclass("lg-zoomed")&&d&&(d=!1,a.core.$outer.removeclass("lg-zoom-dragging"),a.touchendzoom(b,c,e,f))})},d.prototype.zoomdrag=function(){var b=this,c={},d={},e=!1,f=!1,g=!1,h=!1;b.core.$slide.on("mousedown.lg.zoom",function(d){var f=b.core.$slide.eq(b.core.index).find(".lg-object");h=f.prop("offsetheight")*f.attr("data-scale")>b.core.$outer.find(".lg").height(),g=f.prop("offsetwidth")*f.attr("data-scale")>b.core.$outer.find(".lg").width(),b.core.$outer.hasclass("lg-zoomed")&&a(d.target).hasclass("lg-object")&&(g||h)&&(d.preventdefault(),c={x:d.pagex,y:d.pagey},e=!0,b.core.$outer.scrollleft+=1,b.core.$outer.scrollleft-=1,b.core.$outer.removeclass("lg-grab").addclass("lg-grabbing"))}),a(window).on("mousemove.lg.zoom",function(a){if(e){var i,j,k=b.core.$slide.eq(b.core.index).find(".lg-img-wrap");f=!0,d={x:a.pagex,y:a.pagey},b.core.$outer.addclass("lg-zoom-dragging"),j=h?-math.abs(k.attr("data-y"))+(d.y-c.y):-math.abs(k.attr("data-y")),i=g?-math.abs(k.attr("data-x"))+(d.x-c.x):-math.abs(k.attr("data-x")),b.core.s.useleftforzoom?k.css({left:i+"px",top:j+"px"}):k.css("transform","translate3d("+i+"px, "+j+"px, 0)")}}),a(window).on("mouseup.lg.zoom",function(a){e&&(e=!1,b.core.$outer.removeclass("lg-zoom-dragging"),!f||c.x===d.x&&c.y===d.y||(d={x:a.pagex,y:a.pagey},b.touchendzoom(c,d,g,h)),f=!1),b.core.$outer.removeclass("lg-grabbing").addclass("lg-grab")})},d.prototype.touchendzoom=function(a,b,c,d){var e=this,f=e.core.$slide.eq(e.core.index).find(".lg-img-wrap"),g=e.core.$slide.eq(e.core.index).find(".lg-object"),h=-math.abs(f.attr("data-x"))+(b.x-a.x),i=-math.abs(f.attr("data-y"))+(b.y-a.y),j=(e.core.$outer.find(".lg").height()-g.prop("offsetheight"))/2,k=math.abs(g.prop("offsetheight")*math.abs(g.attr("data-scale"))-e.core.$outer.find(".lg").height()+j),l=(e.core.$outer.find(".lg").width()-g.prop("offsetwidth"))/2,m=math.abs(g.prop("offsetwidth")*math.abs(g.attr("data-scale"))-e.core.$outer.find(".lg").width()+l);(math.abs(b.x-a.x)>15||math.abs(b.y-a.y)>15)&&(d&&(i<=-k?i=-k:i>=-j&&(i=-j)),c&&(h<=-m?h=-m:h>=-l&&(h=-l)),d?f.attr("data-y",math.abs(i)):i=-math.abs(f.attr("data-y")),c?f.attr("data-x",math.abs(h)):h=-math.abs(f.attr("data-x")),e.core.s.useleftforzoom?f.css({left:h+"px",top:i+"px"}):f.css("transform","translate3d("+h+"px, "+i+"px, 0)"))},d.prototype.destroy=function(){var b=this;b.core.$el.off(".lg.zoom"),a(window).off(".lg.zoom"),b.core.$slide.off(".lg.zoom"),b.core.$el.off(".lg.tm.zoom"),b.resetzoom(),cleartimeout(b.zoomabletimeout),b.zoomabletimeout=!1},a.fn.lightgallery.modules.zoom=d}()});