lightgallery.js.go 18 KB

123
  1. package assets
  2. var LightGalleryJs = []byte(`!function(){"use strict";var s={mode:"lg-slide",cssEasing:"ease",easing:"linear",speed:600,height:"100%",width:"100%",addClass:"",startClass:"lg-start-zoom",backdropDuration:150,hideBarsDelay:6e3,useLeft:!1,closable:!0,loop:!0,escKey:!0,keyPress:!0,controls:!0,slideEndAnimatoin:!0,hideControlOnEnd:!1,mousewheel:!0,getCaptionFromTitleOrAlt:!0,appendSubHtmlTo:".lg-sub-html",subHtmlSelectorRelative:!1,preload:1,showAfterLoad:!0,selector:"",selectWithin:"",nextHtml:"",prevHtml:"",index:!1,iframeMaxWidth:"100%",download:!0,counter:!0,appendCounterTo:".lg-toolbar",swipeThreshold:50,enableSwipe:!0,enableDrag:!0,dynamic:!1,dynamicEl:[],galleryId:1};function t(e,t){if(this.el=e,this.$el=$(e),this.s=$.extend({},s,t),this.s.dynamic&&"undefined"!==this.s.dynamicEl&&this.s.dynamicEl.constructor===Array&&!this.s.dynamicEl.length)throw"When using dynamic mode, you must also define dynamicEl as an Array.";return this.modules={},this.lGalleryOn=!1,this.lgBusy=!1,this.hideBartimeout=!1,this.isTouch="ontouchstart"in document.documentElement,this.s.slideEndAnimatoin&&(this.s.hideControlOnEnd=!1),this.s.dynamic?this.$items=this.s.dynamicEl:"this"===this.s.selector?this.$items=this.$el:""!==this.s.selector?this.s.selectWithin?this.$items=$(this.s.selectWithin).find(this.s.selector):this.$items=this.$el.find($(this.s.selector)):this.$items=this.$el.children(),this.$slide="",this.$outer="",this.init(),this}t.prototype.init=function(){var e=this;e.s.preload>e.$items.length&&(e.s.preload=e.$items.length);var t=window.location.hash;0<t.indexOf("lg="+this.s.galleryId)&&(e.index=parseInt(t.split("&slide=")[1],10),$("body").addClass("lg-from-hash"),$("body").hasClass("lg-on")||(setTimeout(function(){e.build(e.index)}),$("body").addClass("lg-on"))),e.s.dynamic?(e.$el.trigger("onBeforeOpen.lg"),e.index=e.s.index||0,$("body").hasClass("lg-on")||setTimeout(function(){e.build(e.index),$("body").addClass("lg-on")})):e.$items.on("click.lgcustom",function(t){try{t.preventDefault(),t.preventDefault()}catch(e){t.returnValue=!1}e.$el.trigger("onBeforeOpen.lg"),e.index=e.s.index||e.$items.index(this),$("body").hasClass("lg-on")||(e.build(e.index),$("body").addClass("lg-on"))})},t.prototype.build=function(e){var t=this;t.structure(),$.each($.fn.lightGallery.modules,function(e){t.modules[e]=new $.fn.lightGallery.modules[e](t.el)}),t.slide(e,!1,!1,!1),t.s.keyPress&&t.keyPress(),1<t.$items.length?(t.arrow(),setTimeout(function(){t.enableDrag(),t.enableSwipe()},50),t.s.mousewheel&&t.mousewheel()):t.$slide.on("click.lg",function(){t.$el.trigger("onSlideClick.lg")}),t.counter(),t.closeGallery(),t.$el.trigger("onAfterOpen.lg"),t.$outer.on("mousemove.lg click.lg touchstart.lg",function(){t.$outer.removeClass("lg-hide-items"),clearTimeout(t.hideBartimeout),t.hideBartimeout=setTimeout(function(){t.$outer.addClass("lg-hide-items")},t.s.hideBarsDelay)}),t.$outer.trigger("mousemove.lg")},t.prototype.structure=function(){var e,t="",s="",i=0,l="",o=this;for($("body").append('<div class="lg-backdrop"></div>'),$(".lg-backdrop").css("transition-duration",this.s.backdropDuration+"ms"),i=0;i<this.$items.length;i++)t+='<div class="lg-item"></div>';if(this.s.controls&&1<this.$items.length&&(s='<div class="lg-actions"><button class="lg-prev lg-icon">'+this.s.prevHtml+'</button><button class="lg-next lg-icon">'+this.s.nextHtml+"</button></div>"),".lg-sub-html"===this.s.appendSubHtmlTo&&(l='<div class="lg-sub-html"></div>'),e='<div class="lg-outer '+this.s.addClass+" "+this.s.startClass+'"><div class="lg" style="width:'+this.s.width+"; height:"+this.s.height+'"><div class="lg-inner">'+t+'</div><div class="lg-toolbar lg-group"><span class="lg-close lg-icon"></span></div>'+s+l+"</div></div>",$("body").append(e),this.$outer=$(".lg-outer"),this.$slide=this.$outer.find(".lg-item"),this.s.useLeft?(this.$outer.addClass("lg-use-left"),this.s.mode="lg-slide"):this.$outer.addClass("lg-use-css3"),o.setTop(),$(window).on("resize.lg orientationchange.lg",function(){setTimeout(function(){o.setTop()},100)}),this.$slide.eq(this.index).addClass("lg-current"),this.doCss()?this.$outer.addClass("lg-css3"):(this.$outer.addClass("lg-css"),this.s.speed=0),this.$outer.addClass(this.s.mode),this.s.enableDrag&&1<this.$items.length&&this.$outer.addClass("lg-grab"),this.s.showAfterLoad&&this.$outer.addClass("lg-show-after-load"),this.doCss()){var n=this.$outer.find(".lg-inner");n.css("transition-timing-function",this.s.cssEasing),n.css("transition-duration",this.s.speed+"ms")}setTimeout(function(){$(".lg-backdrop").addClass("in")}),setTimeout(function(){o.$outer.addClass("lg-visible")},this.s.backdropDuration),this.s.download&&this.$outer.find(".lg-toolbar").append('<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>'),this.prevScrollTop=$(window).scrollTop()},t.prototype.setTop=function(){if("100%"!==this.s.height){var e=$(window).height(),t=(e-parseInt(this.s.height,10))/2,s=this.$outer.find(".lg");e>=parseInt(this.s.height,10)?s.css("top",t+"px"):s.css("top","0px")}},t.prototype.doCss=function(){return!!function(){var e=["transition","MozTransition","WebkitTransition","OTransition","msTransition","KhtmlTransition"],t=document.documentElement,s=0;for(s=0;s<e.length;s++)if(e[s]in t.style)return!0}()},t.prototype.isVideo=function(e,t){var s;if(s=this.s.dynamic?this.s.dynamicEl[t].html:this.$items.eq(t).attr("data-html"),!e)return s?{html5:!0}:(console.error("lightGallery :- data-src is not pvovided on slide item "+(t+1)+". Please make sure the selector property is properly configured. More info - http://sachinchoolur.github.io/lightGallery/demos/html-markup.html"),!1);var i=e.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com|be-nocookie\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i),l=e.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i),o=e.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i),n=e.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);return i?{youtube:i}:l?{vimeo:l}:o?{dailymotion:o}:n?{vk:n}:void 0},t.prototype.counter=function(){this.s.counter&&$(this.s.appendCounterTo).append('<div id="lg-counter"><span id="lg-counter-current">'+(parseInt(this.index,10)+1)+'</span> / <span id="lg-counter-all">'+this.$items.length+"</span></div>")},t.prototype.addHtml=function(e){var t,s,i=null;if(this.s.dynamic?this.s.dynamicEl[e].subHtmlUrl?t=this.s.dynamicEl[e].subHtmlUrl:i=this.s.dynamicEl[e].subHtml:(s=this.$items.eq(e)).attr("data-sub-html-url")?t=s.attr("data-sub-html-url"):(i=s.attr("data-sub-html"),this.s.getCaptionFromTitleOrAlt&&!i&&(i=s.attr("title")||s.find("img").first().attr("alt"))),!t)if(null!=i){var l=i.substring(0,1);"."!==l&&"#"!==l||(i=this.s.subHtmlSelectorRelative&&!this.s.dynamic?s.find(i).html():$(i).html())}else i="";".lg-sub-html"===this.s.appendSubHtmlTo?t?this.$outer.find(this.s.appendSubHtmlTo).load(t):this.$outer.find(this.s.appendSubHtmlTo).html(i):t?this.$slide.eq(e).load(t):this.$slide.eq(e).append(i),null!=i&&(""===i?this.$outer.find(this.s.appendSubHtmlTo).addClass("lg-empty-html"):this.$outer.find(this.s.appendSubHtmlTo).removeClass("lg-empty-html")),this.$el.trigger("onAfterAppendSubHtml.lg",[e])},t.prototype.preload=function(e){var t=1,s=1;for(t=1;t<=this.s.preload&&!(t>=this.$items.length-e);t++)this.loadContent(e+t,!1,0);for(s=1;s<=this.s.preload&&!(e-s<0);s++)this.loadContent(e-s,!1,0)},t.prototype.loadContent=function(t,e,s){function i(e){for(var t=[],s=[],i=0;i<e.length;i++){var l=e[i].split(" ");""===l[0]&&l.splice(0,1),s.push(l[0]),t.push(l[1])}for(var o=$(window).width(),n=0;n<t.length;n++)if(parseInt(t[n],10)>o){a=s[n];break}}var l,a,o,n,r,d,g=this,h=!1;if(g.s.dynamic){if(g.s.dynamicEl[t].poster&&(h=!0,o=g.s.dynamicEl[t].poster),d=g.s.dynamicEl[t].html,a=g.s.dynamicEl[t].src,g.s.dynamicEl[t].responsive)i(g.s.dynamicEl[t].responsive.split(","));n=g.s.dynamicEl[t].srcset,r=g.s.dynamicEl[t].sizes}else{if(g.$items.eq(t).attr("data-poster")&&(h=!0,o=g.$items.eq(t).attr("data-poster")),d=g.$items.eq(t).attr("data-html"),a=g.$items.eq(t).attr("href")||g.$items.eq(t).attr("data-src"),g.$items.eq(t).attr("data-responsive"))i(g.$items.eq(t).attr("data-responsive").split(","));n=g.$items.eq(t).attr("data-srcset"),r=g.$items.eq(t).attr("data-sizes")}var u=!1;g.s.dynamic?g.s.dynamicEl[t].iframe&&(u=!0):"true"===g.$items.eq(t).attr("data-iframe")&&(u=!0);var c=g.isVideo(a,t);if(!g.$slide.eq(t).hasClass("lg-loaded")){if(u)g.$slide.eq(t).prepend('<div class="lg-video-cont lg-has-iframe" style="max-width:'+g.s.iframeMaxWidth+'"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="'+a+'" allowfullscreen="true"></iframe></div></div>');else if(h){var m="";m=c&&c.youtube?"lg-has-youtube":c&&c.vimeo?"lg-has-vimeo":"lg-has-html5",g.$slide.eq(t).prepend('<div class="lg-video-cont '+m+' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="'+o+'" /></div></div>')}else c?(g.$slide.eq(t).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>'),g.$el.trigger("hasVideo.lg",[t,a,d])):g.$slide.eq(t).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="'+a+'" /></div>');if(g.$el.trigger("onAferAppendSlide.lg",[t]),l=g.$slide.eq(t).find(".lg-object"),r&&l.attr("sizes",r),n){l.attr("srcset",n);try{picturefill({elements:[l[0]]})}catch(e){console.warn("lightGallery :- If you want srcset to be supported for older browser please include picturefil version 2 javascript library in your document.")}}".lg-sub-html"!==this.s.appendSubHtmlTo&&g.addHtml(t),g.$slide.eq(t).addClass("lg-loaded")}g.$slide.eq(t).find(".lg-object").on("load.lg error.lg",function(){var e=0;s&&!$("body").hasClass("lg-from-hash")&&(e=s),setTimeout(function(){g.$slide.eq(t).addClass("lg-complete"),g.$el.trigger("onSlideItemLoad.lg",[t,s||0])},e)}),c&&c.html5&&!h&&g.$slide.eq(t).addClass("lg-complete"),!0===e&&(g.$slide.eq(t).hasClass("lg-complete")?g.preload(t):g.$slide.eq(t).find(".lg-object").on("load.lg error.lg",function(){g.preload(t)}))},t.prototype.slide=function(e,t,s,i){var l=this.$outer.find(".lg-current").index(),o=this;if(!o.lGalleryOn||l!==e){var n=this.$slide.length,a=o.lGalleryOn?this.s.speed:0;if(!o.lgBusy){var r,d,g;if(this.s.download)(r=o.s.dynamic?!1!==o.s.dynamicEl[e].downloadUrl&&(o.s.dynamicEl[e].downloadUrl||o.s.dynamicEl[e].src):"false"!==o.$items.eq(e).attr("data-download-url")&&(o.$items.eq(e).attr("data-download-url")||o.$items.eq(e).attr("href")||o.$items.eq(e).attr("data-src")))?($("#lg-download").attr("href",r),o.$outer.removeClass("lg-hide-download")):o.$outer.addClass("lg-hide-download");if(this.$el.trigger("onBeforeSlide.lg",[l,e,t,s]),o.lgBusy=!0,clearTimeout(o.hideBartimeout),".lg-sub-html"===this.s.appendSubHtmlTo&&setTimeout(function(){o.addHtml(e)},a),this.arrowDisable(e),i||(e<l?i="prev":l<e&&(i="next")),t)this.$slide.removeClass("lg-prev-slide lg-current lg-next-slide"),2<n?(d=e-1,g=e+1,0===e&&l===n-1?(g=0,d=n-1):e===n-1&&0===l&&(g=0,d=n-1)):(d=0,g=1),"prev"===i?o.$slide.eq(g).addClass("lg-next-slide"):o.$slide.eq(d).addClass("lg-prev-slide"),o.$slide.eq(e).addClass("lg-current");else o.$outer.addClass("lg-no-trans"),this.$slide.removeClass("lg-prev-slide lg-next-slide"),"prev"===i?(this.$slide.eq(e).addClass("lg-prev-slide"),this.$slide.eq(l).addClass("lg-next-slide")):(this.$slide.eq(e).addClass("lg-next-slide"),this.$slide.eq(l).addClass("lg-prev-slide")),setTimeout(function(){o.$slide.removeClass("lg-current"),o.$slide.eq(e).addClass("lg-current"),o.$outer.removeClass("lg-no-trans")},50);o.lGalleryOn?(setTimeout(function(){o.loadContent(e,!0,0)},this.s.speed+50),setTimeout(function(){o.lgBusy=!1,o.$el.trigger("onAfterSlide.lg",[l,e,t,s])},this.s.speed)):(o.loadContent(e,!0,o.s.backdropDuration),o.lgBusy=!1,o.$el.trigger("onAfterSlide.lg",[l,e,t,s])),o.lGalleryOn=!0,this.s.counter&&$("#lg-counter-current").text(e+1)}o.index=e}},t.prototype.goToNextSlide=function(e){var t=this,s=t.s.loop;e&&t.$slide.length<3&&(s=!1),t.lgBusy||(t.index+1<t.$slide.length?(t.index++,t.$el.trigger("onBeforeNextSlide.lg",[t.index]),t.slide(t.index,e,!1,"next")):s?(t.index=0,t.$el.trigger("onBeforeNextSlide.lg",[t.index]),t.slide(t.index,e,!1,"next")):t.s.slideEndAnimatoin&&!e&&(t.$outer.addClass("lg-right-end"),setTimeout(function(){t.$outer.removeClass("lg-right-end")},400)))},t.prototype.goToPrevSlide=function(e){var t=this,s=t.s.loop;e&&t.$slide.length<3&&(s=!1),t.lgBusy||(0<t.index?(t.index--,t.$el.trigger("onBeforePrevSlide.lg",[t.index,e]),t.slide(t.index,e,!1,"prev")):s?(t.index=t.$items.length-1,t.$el.trigger("onBeforePrevSlide.lg",[t.index,e]),t.slide(t.index,e,!1,"prev")):t.s.slideEndAnimatoin&&!e&&(t.$outer.addClass("lg-left-end"),setTimeout(function(){t.$outer.removeClass("lg-left-end")},400)))},t.prototype.keyPress=function(){var t=this;1<this.$items.length&&$(window).on("keyup.lg",function(e){1<t.$items.length&&(37===e.keyCode&&(e.preventDefault(),t.goToPrevSlide()),39===e.keyCode&&(e.preventDefault(),t.goToNextSlide()))}),$(window).on("keydown.lg",function(e){!0===t.s.escKey&&27===e.keyCode&&(e.preventDefault(),t.$outer.hasClass("lg-thumb-open")?t.$outer.removeClass("lg-thumb-open"):t.destroy())})},t.prototype.arrow=function(){var e=this;this.$outer.find(".lg-prev").on("click.lg",function(){e.goToPrevSlide()}),this.$outer.find(".lg-next").on("click.lg",function(){e.goToNextSlide()})},t.prototype.arrowDisable=function(e){!this.s.loop&&this.s.hideControlOnEnd&&(e+1<this.$slide.length?this.$outer.find(".lg-next").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-next").attr("disabled","disabled").addClass("disabled"),0<e?this.$outer.find(".lg-prev").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-prev").attr("disabled","disabled").addClass("disabled"))},t.prototype.setTranslate=function(e,t,s){this.s.useLeft?e.css("left",t):e.css({transform:"translate3d("+t+"px, "+s+"px, 0px)"})},t.prototype.touchMove=function(e,t){var s=t-e;15<Math.abs(s)&&(this.$outer.addClass("lg-dragging"),this.setTranslate(this.$slide.eq(this.index),s,0),this.setTranslate($(".lg-prev-slide"),-this.$slide.eq(this.index).width()+s,0),this.setTranslate($(".lg-next-slide"),this.$slide.eq(this.index).width()+s,0))},t.prototype.touchEnd=function(e){var t=this;"lg-slide"!==t.s.mode&&t.$outer.addClass("lg-slide"),this.$slide.not(".lg-current, .lg-prev-slide, .lg-next-slide").css("opacity","0"),setTimeout(function(){t.$outer.removeClass("lg-dragging"),e<0&&Math.abs(e)>t.s.swipeThreshold?t.goToNextSlide(!0):0<e&&Math.abs(e)>t.s.swipeThreshold?t.goToPrevSlide(!0):Math.abs(e)<5&&t.$el.trigger("onSlideClick.lg"),t.$slide.removeAttr("style")}),setTimeout(function(){t.$outer.hasClass("lg-dragging")||"lg-slide"===t.s.mode||t.$outer.removeClass("lg-slide")},t.s.speed+100)},t.prototype.enableSwipe=function(){var t=this,s=0,i=0,l=!1;t.s.enableSwipe&&t.doCss()&&(t.$slide.on("touchstart.lg",function(e){t.$outer.hasClass("lg-zoomed")||t.lgBusy||(e.preventDefault(),t.manageSwipeClass(),s=e.originalEvent.targetTouches[0].pageX)}),t.$slide.on("touchmove.lg",function(e){t.$outer.hasClass("lg-zoomed")||(e.preventDefault(),i=e.originalEvent.targetTouches[0].pageX,t.touchMove(s,i),l=!0)}),t.$slide.on("touchend.lg",function(){t.$outer.hasClass("lg-zoomed")||(l?(l=!1,t.touchEnd(i-s)):t.$el.trigger("onSlideClick.lg"))}))},t.prototype.enableDrag=function(){var t=this,s=0,i=0,l=!1,o=!1;t.s.enableDrag&&t.doCss()&&(t.$slide.on("mousedown.lg",function(e){t.$outer.hasClass("lg-zoomed")||t.lgBusy||$(e.target).text().trim()||(e.preventDefault(),t.manageSwipeClass(),s=e.pageX,l=!0,t.$outer.scrollLeft+=1,t.$outer.scrollLeft-=1,t.$outer.removeClass("lg-grab").addClass("lg-grabbing"),t.$el.trigger("onDragstart.lg"))}),$(window).on("mousemove.lg",function(e){l&&(o=!0,i=e.pageX,t.touchMove(s,i),t.$el.trigger("onDragmove.lg"))}),$(window).on("mouseup.lg",function(e){o?(o=!1,t.touchEnd(i-s),t.$el.trigger("onDragend.lg")):($(e.target).hasClass("lg-object")||$(e.target).hasClass("lg-video-play"))&&t.$el.trigger("onSlideClick.lg"),l&&(l=!1,t.$outer.removeClass("lg-grabbing").addClass("lg-grab"))}))},t.prototype.manageSwipeClass=function(){var e=this.index+1,t=this.index-1;this.s.loop&&2<this.$slide.length&&(0===this.index?t=this.$slide.length-1:this.index===this.$slide.length-1&&(e=0)),this.$slide.removeClass("lg-next-slide lg-prev-slide"),-1<t&&this.$slide.eq(t).addClass("lg-prev-slide"),this.$slide.eq(e).addClass("lg-next-slide")},t.prototype.mousewheel=function(){var t=this;t.$outer.on("mousewheel.lg",function(e){e.deltaY&&(0<e.deltaY?t.goToPrevSlide():t.goToNextSlide(),e.preventDefault())})},t.prototype.closeGallery=function(){var t=this,s=!1;this.$outer.find(".lg-close").on("click.lg",function(){t.destroy()}),t.s.closable&&(t.$outer.on("mousedown.lg",function(e){s=!!($(e.target).is(".lg-outer")||$(e.target).is(".lg-item ")||$(e.target).is(".lg-img-wrap"))}),t.$outer.on("mousemove.lg",function(){s=!1}),t.$outer.on("mouseup.lg",function(e){($(e.target).is(".lg-outer")||$(e.target).is(".lg-item ")||$(e.target).is(".lg-img-wrap")&&s)&&(t.$outer.hasClass("lg-dragging")||t.destroy())}))},t.prototype.destroy=function(e){var t=this;e||(t.$el.trigger("onBeforeClose.lg"),$(window).scrollTop(t.prevScrollTop)),e&&(t.s.dynamic||this.$items.off("click.lg click.lgcustom"),$.removeData(t.el,"lightGallery")),this.$el.off(".lg.tm"),$.each($.fn.lightGallery.modules,function(e){t.modules[e]&&t.modules[e].destroy()}),this.lGalleryOn=!1,clearTimeout(t.hideBartimeout),this.hideBartimeout=!1,$(window).off(".lg"),$("body").removeClass("lg-on lg-from-hash"),t.$outer&&t.$outer.removeClass("lg-visible"),$(".lg-backdrop").removeClass("in"),setTimeout(function(){t.$outer&&t.$outer.remove(),$(".lg-backdrop").remove(),e||t.$el.trigger("onCloseAfter.lg")},t.s.backdropDuration+50)},$.fn.lightGallery=function(e){return this.each(function(){if($.data(this,"lightGallery"))try{$(this).data("lightGallery").init()}catch(e){console.error("lightGallery has not initiated properly")}else $.data(this,"lightGallery",new t(this,e))})},$.fn.lightGallery.modules={}}();`)