Просмотр файла wu-static/js2/lightgallery/js/lightgallery.min.js

Размер файла: 17.25Kb
!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";function a(a,c){if(this.el=a,this.$el=$(a),this.s=$.extend({},b,c),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}var b={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};a.prototype.init=function(){var a=this;a.s.preload>a.$items.length&&(a.s.preload=a.$items.length);var b=window.location.hash;b.indexOf("lg="+this.s.galleryId)>0&&(a.index=parseInt(b.split("&slide=")[1],10),$("body").addClass("lg-from-hash"),$("body").hasClass("lg-on")||(setTimeout(function(){a.build(a.index)}),$("body").addClass("lg-on"))),a.s.dynamic?(a.$el.trigger("onBeforeOpen.lg"),a.index=a.s.index||0,$("body").hasClass("lg-on")||setTimeout(function(){a.build(a.index),$("body").addClass("lg-on")})):a.$items.on("click.lgcustom",function(b){try{b.preventDefault(),b.preventDefault()}catch(c){b.returnValue=!1}a.$el.trigger("onBeforeOpen.lg"),a.index=a.s.index||a.$items.index(this),$("body").hasClass("lg-on")||(a.build(a.index),$("body").addClass("lg-on"))})},a.prototype.build=function(a){var b=this;b.structure(),$.each($.fn.lightGallery.modules,function(a){b.modules[a]=new $.fn.lightGallery.modules[a](b.el)}),b.slide(a,!1,!1),b.s.keyPress&&b.keyPress(),b.$items.length>1&&(b.arrow(),setTimeout(function(){b.enableDrag(),b.enableSwipe()},50),b.s.mousewheel&&b.mousewheel()),b.counter(),b.closeGallery(),b.$el.trigger("onAfterOpen.lg"),b.$outer.on("mousemove.lg click.lg touchstart.lg",function(){b.$outer.removeClass("lg-hide-items"),clearTimeout(b.hideBartimeout),b.hideBartimeout=setTimeout(function(){b.$outer.addClass("lg-hide-items")},b.s.hideBarsDelay)})},a.prototype.structure=function(){var a,b="",c="",d=0,e="",f=this;for($("body").append('<div class="lg-backdrop"></div>'),$(".lg-backdrop").css("transition-duration",this.s.backdropDuration+"ms"),d=0;d<this.$items.length;d++)b+='<div class="lg-item"></div>';if(this.s.controls&&this.$items.length>1&&(c='<div class="lg-actions"><div class="lg-prev lg-icon">'+this.s.prevHtml+'</div><div class="lg-next lg-icon">'+this.s.nextHtml+"</div></div>"),".lg-sub-html"===this.s.appendSubHtmlTo&&(e='<div class="lg-sub-html"></div>'),a='<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">'+b+'</div><div class="lg-toolbar group"><span class="lg-close lg-icon"></span></div>'+c+e+"</div></div>",$("body").append(a),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"),f.setTop(),$(window).on("resize.lg orientationchange.lg",function(){setTimeout(function(){f.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&&this.$items.length>1&&this.$outer.addClass("lg-grab"),this.s.showAfterLoad&&this.$outer.addClass("lg-show-after-load"),this.doCss()){var g=this.$outer.find(".lg-inner");g.css("transition-timing-function",this.s.cssEasing),g.css("transition-duration",this.s.speed+"ms")}$(".lg-backdrop").addClass("in"),setTimeout(function(){f.$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()},a.prototype.setTop=function(){if("100%"!==this.s.height){var a=$(window).height(),b=(a-parseInt(this.s.height,10))/2,c=this.$outer.find(".lg");a>=parseInt(this.s.height,10)?c.css("top",b+"px"):c.css("top","0px")}},a.prototype.doCss=function(){var a=function(){var a=["transition","MozTransition","WebkitTransition","OTransition","msTransition","KhtmlTransition"],b=document.documentElement,c=0;for(c=0;c<a.length;c++)if(a[c]in b.style)return!0};return!!a()},a.prototype.isVideo=function(a,b){var c;if(c=this.s.dynamic?this.s.dynamicEl[b].html:this.$items.eq(b).attr("data-html"),!a&&c)return{html5:!0};var d=a.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i),e=a.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i),f=a.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i),g=a.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);return d?{youtube:d}:e?{vimeo:e}:f?{dailymotion:f}:g?{vk:g}:void 0},a.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>")},a.prototype.addHtml=function(a){var b,c,d=null;if(this.s.dynamic?this.s.dynamicEl[a].subHtmlUrl?b=this.s.dynamicEl[a].subHtmlUrl:d=this.s.dynamicEl[a].subHtml:(c=this.$items.eq(a),c.attr("data-sub-html-url")?b=c.attr("data-sub-html-url"):(d=c.attr("data-sub-html"),this.s.getCaptionFromTitleOrAlt&&!d&&(d=c.attr("title")||c.find("img").first().attr("alt")))),!b)if("undefined"!=typeof d&&null!==d){var e=d.substring(0,1);"."!==e&&"#"!==e||(d=this.s.subHtmlSelectorRelative&&!this.s.dynamic?c.find(d).html():$(d).html())}else d="";".lg-sub-html"===this.s.appendSubHtmlTo?b?this.$outer.find(this.s.appendSubHtmlTo).load(b):this.$outer.find(this.s.appendSubHtmlTo).html(d):b?this.$slide.eq(a).load(b):this.$slide.eq(a).append(d),"undefined"!=typeof d&&null!==d&&(""===d?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",[a])},a.prototype.preload=function(a){var b=1,c=1;for(b=1;b<=this.s.preload&&!(b>=this.$items.length-a);b++)this.loadContent(a+b,!1,0);for(c=1;c<=this.s.preload&&!(0>a-c);c++)this.loadContent(a-c,!1,0)},a.prototype.loadContent=function(a,b,c){var d,e,f,g,h,i,j=this,k=!1,l=function(a){for(var b=[],c=[],d=0;d<a.length;d++){var f=a[d].split(" ");""===f[0]&&f.splice(0,1),c.push(f[0]),b.push(f[1])}for(var g=$(window).width(),h=0;h<b.length;h++)if(parseInt(b[h],10)>g){e=c[h];break}};if(j.s.dynamic){if(j.s.dynamicEl[a].poster&&(k=!0,f=j.s.dynamicEl[a].poster),i=j.s.dynamicEl[a].html,e=j.s.dynamicEl[a].src,j.s.dynamicEl[a].responsive){var m=j.s.dynamicEl[a].responsive.split(",");l(m)}g=j.s.dynamicEl[a].srcset,h=j.s.dynamicEl[a].sizes}else{if(j.$items.eq(a).attr("data-poster")&&(k=!0,f=j.$items.eq(a).attr("data-poster")),i=j.$items.eq(a).attr("data-html"),e=j.$items.eq(a).attr("href")||j.$items.eq(a).attr("data-src"),j.$items.eq(a).attr("data-responsive")){var n=j.$items.eq(a).attr("data-responsive").split(",");l(n)}g=j.$items.eq(a).attr("data-srcset"),h=j.$items.eq(a).attr("data-sizes")}var o=!1;j.s.dynamic?j.s.dynamicEl[a].iframe&&(o=!0):"true"===j.$items.eq(a).attr("data-iframe")&&(o=!0);var p=j.isVideo(e,a);if(!j.$slide.eq(a).hasClass("lg-loaded")){if(o)j.$slide.eq(a).prepend('<div class="lg-video-cont" style="max-width:'+j.s.iframeMaxWidth+'"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="'+e+'"  allowfullscreen="true"></iframe></div></div>');else if(k){var q="";q=p&&p.youtube?"lg-has-youtube":p&&p.vimeo?"lg-has-vimeo":"lg-has-html5",j.$slide.eq(a).prepend('<div class="lg-video-cont '+q+' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="'+f+'" /></div></div>')}else p?(j.$slide.eq(a).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>'),j.$el.trigger("hasVideo.lg",[a,e,i])):j.$slide.eq(a).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="'+e+'" /></div>');if(j.$el.trigger("onAferAppendSlide.lg",[a]),d=j.$slide.eq(a).find(".lg-object"),h&&d.attr("sizes",h),g){d.attr("srcset",g);try{picturefill({elements:[d[0]]})}catch(r){console.error("Make sure you have included Picturefill version 2")}}".lg-sub-html"!==this.s.appendSubHtmlTo&&j.addHtml(a),j.$slide.eq(a).addClass("lg-loaded")}j.$slide.eq(a).find(".lg-object").on("load.lg error.lg",function(){var b=0;c&&!$("body").hasClass("lg-from-hash")&&(b=c),setTimeout(function(){j.$slide.eq(a).addClass("lg-complete"),j.$el.trigger("onSlideItemLoad.lg",[a,c||0])},b)}),p&&p.html5&&!k&&j.$slide.eq(a).addClass("lg-complete"),b===!0&&(j.$slide.eq(a).hasClass("lg-complete")?j.preload(a):j.$slide.eq(a).find(".lg-object").on("load.lg error.lg",function(){j.preload(a)}))},a.prototype.slide=function(a,b,c){var d=this.$outer.find(".lg-current").index(),e=this;if(!e.lGalleryOn||d!==a){var f=this.$slide.length,g=e.lGalleryOn?this.s.speed:0,h=!1,i=!1;if(!e.lgBusy){if(this.s.download){var j;j=e.s.dynamic?e.s.dynamicEl[a].downloadUrl!==!1&&(e.s.dynamicEl[a].downloadUrl||e.s.dynamicEl[a].src):"false"!==e.$items.eq(a).attr("data-download-url")&&(e.$items.eq(a).attr("data-download-url")||e.$items.eq(a).attr("href")||e.$items.eq(a).attr("data-src")),j?($("#lg-download").attr("href",j),e.$outer.removeClass("lg-hide-download")):e.$outer.addClass("lg-hide-download")}if(this.$el.trigger("onBeforeSlide.lg",[d,a,b,c]),e.lgBusy=!0,clearTimeout(e.hideBartimeout),".lg-sub-html"===this.s.appendSubHtmlTo&&setTimeout(function(){e.addHtml(a)},g),this.arrowDisable(a),b){var k=a-1,l=a+1;0===a&&d===f-1?(l=0,k=f-1):a===f-1&&0===d&&(l=0,k=f-1),this.$slide.removeClass("lg-prev-slide lg-current lg-next-slide"),e.$slide.eq(k).addClass("lg-prev-slide"),e.$slide.eq(l).addClass("lg-next-slide"),e.$slide.eq(a).addClass("lg-current")}else e.$outer.addClass("lg-no-trans"),this.$slide.removeClass("lg-prev-slide lg-next-slide"),d>a?(i=!0,0!==a||d!==f-1||c||(i=!1,h=!0)):a>d&&(h=!0,a!==f-1||0!==d||c||(i=!0,h=!1)),i?(this.$slide.eq(a).addClass("lg-prev-slide"),this.$slide.eq(d).addClass("lg-next-slide")):h&&(this.$slide.eq(a).addClass("lg-next-slide"),this.$slide.eq(d).addClass("lg-prev-slide")),setTimeout(function(){e.$slide.removeClass("lg-current"),e.$slide.eq(a).addClass("lg-current"),e.$outer.removeClass("lg-no-trans")},50);e.lGalleryOn?(setTimeout(function(){e.loadContent(a,!0,0)},this.s.speed+50),setTimeout(function(){e.lgBusy=!1,e.$el.trigger("onAfterSlide.lg",[d,a,b,c])},this.s.speed)):(e.loadContent(a,!0,e.s.backdropDuration),e.lgBusy=!1,e.$el.trigger("onAfterSlide.lg",[d,a,b,c])),e.lGalleryOn=!0,this.s.counter&&$("#lg-counter-current").text(a+1)}}},a.prototype.goToNextSlide=function(a){var b=this;b.lgBusy||(b.index+1<b.$slide.length?(b.index++,b.$el.trigger("onBeforeNextSlide.lg",[b.index]),b.slide(b.index,a,!1)):b.s.loop?(b.index=0,b.$el.trigger("onBeforeNextSlide.lg",[b.index]),b.slide(b.index,a,!1)):b.s.slideEndAnimatoin&&(b.$outer.addClass("lg-right-end"),setTimeout(function(){b.$outer.removeClass("lg-right-end")},400)))},a.prototype.goToPrevSlide=function(a){var b=this;b.lgBusy||(b.index>0?(b.index--,b.$el.trigger("onBeforePrevSlide.lg",[b.index,a]),b.slide(b.index,a,!1)):b.s.loop?(b.index=b.$items.length-1,b.$el.trigger("onBeforePrevSlide.lg",[b.index,a]),b.slide(b.index,a,!1)):b.s.slideEndAnimatoin&&(b.$outer.addClass("lg-left-end"),setTimeout(function(){b.$outer.removeClass("lg-left-end")},400)))},a.prototype.keyPress=function(){var a=this;this.$items.length>1&&$(window).on("keyup.lg",function(b){a.$items.length>1&&(37===b.keyCode&&(b.preventDefault(),a.goToPrevSlide()),39===b.keyCode&&(b.preventDefault(),a.goToNextSlide()))}),$(window).on("keydown.lg",function(b){a.s.escKey===!0&&27===b.keyCode&&(b.preventDefault(),a.$outer.hasClass("lg-thumb-open")?a.$outer.removeClass("lg-thumb-open"):a.destroy())})},a.prototype.arrow=function(){var a=this;this.$outer.find(".lg-prev").on("click.lg",function(){a.goToPrevSlide()}),this.$outer.find(".lg-next").on("click.lg",function(){a.goToNextSlide()})},a.prototype.arrowDisable=function(a){!this.s.loop&&this.s.hideControlOnEnd&&(a+1<this.$slide.length?this.$outer.find(".lg-next").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-next").attr("disabled","disabled").addClass("disabled"),a>0?this.$outer.find(".lg-prev").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-prev").attr("disabled","disabled").addClass("disabled"))},a.prototype.setTranslate=function(a,b,c){this.s.useLeft?a.css("left",b):a.css({transform:"translate3d("+b+"px, "+c+"px, 0px)"})},a.prototype.touchMove=function(a,b){var c=b-a;Math.abs(c)>15&&(this.$outer.addClass("lg-dragging"),this.setTranslate(this.$slide.eq(this.index),c,0),this.setTranslate($(".lg-prev-slide"),-this.$slide.eq(this.index).width()+c,0),this.setTranslate($(".lg-next-slide"),this.$slide.eq(this.index).width()+c,0))},a.prototype.touchEnd=function(a){var b=this;"lg-slide"!==b.s.mode&&b.$outer.addClass("lg-slide"),this.$slide.not(".lg-current, .lg-prev-slide, .lg-next-slide").css("opacity","0"),setTimeout(function(){b.$outer.removeClass("lg-dragging"),0>a&&Math.abs(a)>b.s.swipeThreshold?b.goToNextSlide(!0):a>0&&Math.abs(a)>b.s.swipeThreshold?b.goToPrevSlide(!0):Math.abs(a)<5&&b.$el.trigger("onSlideClick.lg"),b.$slide.removeAttr("style")}),setTimeout(function(){b.$outer.hasClass("lg-dragging")||"lg-slide"===b.s.mode||b.$outer.removeClass("lg-slide")},b.s.speed+100)},a.prototype.enableSwipe=function(){var a=this,b=0,c=0,d=!1;a.s.enableSwipe&&a.isTouch&&a.doCss()&&(a.$slide.on("touchstart.lg",function(c){a.$outer.hasClass("lg-zoomed")||a.lgBusy||(c.preventDefault(),a.manageSwipeClass(),b=c.originalEvent.targetTouches[0].pageX)}),a.$slide.on("touchmove.lg",function(e){a.$outer.hasClass("lg-zoomed")||(e.preventDefault(),c=e.originalEvent.targetTouches[0].pageX,a.touchMove(b,c),d=!0)}),a.$slide.on("touchend.lg",function(){a.$outer.hasClass("lg-zoomed")||(d?(d=!1,a.touchEnd(c-b)):a.$el.trigger("onSlideClick.lg"))}))},a.prototype.enableDrag=function(){var a=this,b=0,c=0,d=!1,e=!1;a.s.enableDrag&&!a.isTouch&&a.doCss()&&(a.$slide.on("mousedown.lg",function(c){a.$outer.hasClass("lg-zoomed")||($(c.target).hasClass("lg-object")||$(c.target).hasClass("lg-video-play"))&&(c.preventDefault(),a.lgBusy||(a.manageSwipeClass(),b=c.pageX,d=!0,a.$outer.scrollLeft+=1,a.$outer.scrollLeft-=1,a.$outer.removeClass("lg-grab").addClass("lg-grabbing"),a.$el.trigger("onDragstart.lg")))}),$(window).on("mousemove.lg",function(f){d&&(e=!0,c=f.pageX,a.touchMove(b,c),a.$el.trigger("onDragmove.lg"))}),$(window).on("mouseup.lg",function(f){e?(e=!1,a.touchEnd(c-b),a.$el.trigger("onDragend.lg")):($(f.target).hasClass("lg-object")||$(f.target).hasClass("lg-video-play"))&&a.$el.trigger("onSlideClick.lg"),d&&(d=!1,a.$outer.removeClass("lg-grabbing").addClass("lg-grab"))}))},a.prototype.manageSwipeClass=function(){var a=this.index+1,b=this.index-1,c=this.$slide.length;this.s.loop&&(0===this.index?b=c-1:this.index===c-1&&(a=0)),this.$slide.removeClass("lg-next-slide lg-prev-slide"),b>-1&&this.$slide.eq(b).addClass("lg-prev-slide"),this.$slide.eq(a).addClass("lg-next-slide")},a.prototype.mousewheel=function(){var a=this;a.$outer.on("mousewheel.lg",function(b){b.deltaY&&(b.deltaY>0?a.goToPrevSlide():a.goToNextSlide(),b.preventDefault())})},a.prototype.closeGallery=function(){var a=this,b=!1;this.$outer.find(".lg-close").on("click.lg",function(){a.destroy()}),a.s.closable&&(a.$outer.on("mousedown.lg",function(a){b=!!($(a.target).is(".lg-outer")||$(a.target).is(".lg-item ")||$(a.target).is(".lg-img-wrap"))}),a.$outer.on("mouseup.lg",function(c){($(c.target).is(".lg-outer")||$(c.target).is(".lg-item ")||$(c.target).is(".lg-img-wrap")&&b)&&(a.$outer.hasClass("lg-dragging")||a.destroy())}))},a.prototype.destroy=function(a){var b=this;a||b.$el.trigger("onBeforeClose.lg"),$(window).scrollTop(b.prevScrollTop),a&&(b.s.dynamic||this.$items.off("click.lg click.lgcustom"),$.removeData(b.el,"lightGallery")),this.$el.off(".lg.tm"),$.each($.fn.lightGallery.modules,function(a){b.modules[a]&&b.modules[a].destroy()}),this.lGalleryOn=!1,clearTimeout(b.hideBartimeout),this.hideBartimeout=!1,$(window).off(".lg"),$("body").removeClass("lg-on lg-from-hash"),b.$outer&&b.$outer.removeClass("lg-visible"),$(".lg-backdrop").removeClass("in"),setTimeout(function(){b.$outer&&b.$outer.remove(),$(".lg-backdrop").remove(),a||b.$el.trigger("onCloseAfter.lg")},b.s.backdropDuration+50)},$.fn.lightGallery=function(b){return this.each(function(){if($.data(this,"lightGallery"))try{$(this).data("lightGallery").init()}catch(c){console.error("lightGallery has not initiated properly")}else $.data(this,"lightGallery",new a(this,b))})},$.fn.lightGallery.modules={}}()});