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