/*! lg-video - v1.1.0 - 2017-08-08
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */ !function(e,o){"function"==typeof define&&define.amd?define(["jquery"],function(e){return o(e)}):"object"==typeof exports?module.exports=o(require("jquery")):o(jQuery)}(this,function(e){var o,i;o={videoMaxWidth:"855px",youtubePlayerParams:!1,vimeoPlayerParams:!1,dailymotionPlayerParams:!1,vkPlayerParams:!1,videojs:!1,videojsOptions:{}},(i=function(i){return this.core=e(i).data("lightGallery"),this.$el=e(i),this.core.s=e.extend({},o,this.core.s),this.videoLoaded=!1,this.init(),this}).prototype.init=function(){var o=this;o.core.$el.on("hasVideo.lg.tm",function(e,i,a,l){if(o.core.$slide.eq(i).find(".lg-video").append(o.loadVideo(a,"lg-object",!0,i,l)),l){if(o.core.s.videojs)try{videojs(o.core.$slide.eq(i).find(".lg-html5").get(0),o.core.s.videojsOptions,function(){o.videoLoaded||this.play()})}catch(r){console.error("Make sure you have included videojs")}else o.videoLoaded||o.core.$slide.eq(i).find(".lg-html5").get(0).play()}}),o.core.$el.on("onAferAppendSlide.lg.tm",function(e,a){var l=o.core.$slide.eq(a).find(".lg-video-cont");l.hasClass("lg-has-iframe")||(l.css("max-width",o.core.s.videoMaxWidth),o.videoLoaded=!0,i(l))});var i=function(e){if(e.find(".lg-object").hasClass("lg-has-poster")&&e.find(".lg-object").is(":visible")){if(e.hasClass("lg-has-video")){var i=e.find(".lg-youtube").get(0),a=e.find(".lg-vimeo").get(0),l=e.find(".lg-dailymotion").get(0),r=e.find(".lg-html5").get(0);if(i)i.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}',"*");else if(a)try{$f(a).api("play")}catch(t){console.error("Make sure you have included froogaloop2 js")}else if(l)l.contentWindow.postMessage("play","*");else if(r){if(o.core.s.videojs)try{videojs(r).play()}catch(s){console.error("Make sure you have included videojs")}else r.play()}e.addClass("lg-video-playing")}else{e.addClass("lg-video-playing lg-has-video");var d,c,n=function(i,a){if(e.find(".lg-video").append(o.loadVideo(i,"",!1,o.core.index,a)),a){if(o.core.s.videojs)try{videojs(o.core.$slide.eq(o.core.index).find(".lg-html5").get(0),o.core.s.videojsOptions,function(){this.play()})}catch(l){console.error("Make sure you have included videojs")}else o.core.$slide.eq(o.core.index).find(".lg-html5").get(0).play()}};o.core.s.dynamic?n(d=o.core.s.dynamicEl[o.core.index].src,c=o.core.s.dynamicEl[o.core.index].html):n(d=o.core.$items.eq(o.core.index).attr("href")||o.core.$items.eq(o.core.index).attr("data-src"),c=o.core.$items.eq(o.core.index).attr("data-html"));var m=e.find(".lg-object");e.find(".lg-video").append(m),e.find(".lg-video-object").hasClass("lg-html5")||(e.removeClass("lg-complete"),e.find(".lg-video-object").on("load.lg error.lg",function(){e.addClass("lg-complete")}))}}};o.core.doCss()&&o.core.$items.length>1&&(o.core.s.enableSwipe||o.core.s.enableDrag)?o.core.$el.on("onSlideClick.lg.tm",function(){i(o.core.$slide.eq(o.core.index))}):o.core.$slide.on("click.lg",function(){i(e(this))}),o.core.$el.on("onBeforeSlide.lg.tm",function(i,a,l){var r,t=o.core.$slide.eq(a),s=t.find(".lg-youtube").get(0),d=t.find(".lg-vimeo").get(0),c=t.find(".lg-dailymotion").get(0),n=t.find(".lg-vk").get(0),m=t.find(".lg-html5").get(0);if(s)s.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}',"*");else if(d)try{$f(d).api("pause")}catch(f){console.error("Make sure you have included froogaloop2 js")}else if(c)c.contentWindow.postMessage("pause","*");else if(m){if(o.core.s.videojs)try{videojs(m).pause()}catch(u){console.error("Make sure you have included videojs")}else m.pause()}n&&e(n).attr("src",e(n).attr("src").replace("&autoplay","&noplay")),r=o.core.s.dynamic?o.core.s.dynamicEl[l].src:o.core.$items.eq(l).attr("href")||o.core.$items.eq(l).attr("data-src");var g=o.core.isVideo(r,l)||{};(g.youtube||g.vimeo||g.dailymotion||g.vk)&&o.core.$outer.addClass("lg-hide-download")}),o.core.$el.on("onAfterSlide.lg.tm",function(e,i){o.core.$slide.eq(i).removeClass("lg-video-playing")})},i.prototype.loadVideo=function(o,i,a,l,r){var t="",s=1,d="",c=this.core.isVideo(o,l)||{};if(a&&(s=this.videoLoaded?0:1),c.youtube)d="?wmode=opaque&autoplay="+s+"&enablejsapi=1",this.core.s.youtubePlayerParams&&(d=d+"&"+e.param(this.core.s.youtubePlayerParams)),t='';else if(c.vimeo)d="?autoplay="+s+"&api=1",this.core.s.vimeoPlayerParams&&(d=d+"&"+e.param(this.core.s.vimeoPlayerParams)),t='';else if(c.dailymotion)d="?wmode=opaque&autoplay="+s+"&api=postMessage",this.core.s.dailymotionPlayerParams&&(d=d+"&"+e.param(this.core.s.dailymotionPlayerParams)),t='';else if(c.html5){var n=r.substring(0,1);("."===n||"#"===n)&&(r=e(r).html()),t=r}else c.vk&&(d="&autoplay="+s,this.core.s.vkPlayerParams&&(d=d+"&"+e.param(this.core.s.vkPlayerParams)),t='');return t},i.prototype.destroy=function(){this.videoLoaded=!1},e.fn.lightGallery.modules.video=i});