/*! jg-video - v1 - 2020-04-10 * based on lg-video - v1.2.2 - 2018-05-01 * http://sachinchoolur.github.io/lightGallery * Copyright (C) 2023, 2024 Juergen Adams * Copyright (C) 2018 Sachin N; Licensed GPLv3 */ !function(e,o){"function"==typeof define&&define.amd?define(["jquery"],function(e){return o(e)}):"object"==typeof module&&module.exports?module.exports=o(require("jquery")):o(e.jQuery)}(this,function(e){!function(){"use strict";var o={videoMaxWidth:"855px",autoplayFirstVideo:!0,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};function a(e,o,i,a){var t=this;if(t.core.$slide.eq(o).find(".lg-video").append(t.loadVideo(i,"lg-object",!0,o,a)),a){if(t.core.s.videojs)try{videojs(t.core.$slide.eq(o).find(".lg-html5").get(0),t.core.s.videojsOptions,function(){!t.videoLoaded&&t.core.s.autoplayFirstVideo&&this.play()})}catch(r){console.error("Make sure you have included videojs")}else!t.videoLoaded&&t.core.s.autoplayFirstVideo&&t.core.$slide.eq(o).find(".lg-html5").get(0).play()}}function t(e,o){var i=this.core.$slide.eq(o).find(".lg-video-cont");i.hasClass("lg-has-iframe")||(i.css("max-width",this.core.s.videoMaxWidth),this.videoLoaded=!0)}function r(o,i,a){var t,r,s,l,d,c,n=this,m=setInterval(function(){if(r=(t=n.core.$slide.eq(i)).find(".lg-youtube").get(0),s=t.find(".lg-vimeo").get(0),l=t.find(".lg-dailymotion").get(0),c=t.find(".lg-vk").get(0),d=t.find(".lg-html5").get(0),r||s||l||c||d){if(r)r.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}',"*");else if(s)try{$f(s).api("pause")}catch(o){console.error("Make sure you have included froogaloop2 js")}else if(l)l.contentWindow.postMessage("pause","*");else if(d){if(n.core.s.videojs)try{videojs(d).pause()}catch(f){console.error("Make sure you have included videojs")}else d.pause()}c&&e(c).attr("src",e(c).attr("src").replace("&autoplay","&noplay")),u=n.core.s.dynamic?n.core.s.dynamicEl[a].src:n.core.$items.eq(a).attr("href")||n.core.$items.eq(a).attr("data-src");var u,y=n.core.isVideo(u,a)||{};(y.youtube||y.vimeo||y.dailymotion||y.vk)&&n.core.$outer.addClass("lg-hide-download"),clearInterval(m)}},10)}i.prototype.init=function(){var o=this;o.core.$el.on("hasVideo.lg.tm",a.bind(this)),o.core.$el.on("onAferAppendSlide.lg.tm",t.bind(this)),o.core.doCss()&&o.core.$items.length>1&&(o.core.s.enableSwipe||o.core.s.enableDrag)?o.core.$el.on("onSlideClick.lg.tm",function(){var e=o.core.$slide.eq(o.core.index);o.loadVideoOnclick(e)}):o.core.$slide.on("click.lg",function(){o.loadVideoOnclick(e(this))}),o.core.$el.on("onBeforeSlide.lg.tm",r.bind(this)),o.core.$el.on("onAfterSlide.lg.tm",function(e,i){o.core.$slide.eq(i).removeClass("lg-video-playing")}),o.core.s.autoplayFirstVideo&&o.core.$el.on("onAferAppendSlide.lg.tm",function(e,i){if(!o.core.lGalleryOn){var a=o.core.$slide.eq(i);setTimeout(function(){o.loadVideoOnclick(a)},100)}})},i.prototype.loadVideo=function(o,i,a,t,r){var s="",l=1,d="",c=this.core.isVideo(o,t)||{};if(a&&(l=this.videoLoaded?0:this.core.s.autoplayFirstVideo?1:0),c.youtube){var n=document.createElement("script");n.src="https://www.youtube.com/iframe_api";var m=document.getElementsByTagName("script")[0];m.parentNode.insertBefore(n,m),d="?wmode=opaque&autoplay="+l+"&enablejsapi=1",this.core.s.youtubePlayerParams&&(d=d+"&"+e.param(this.core.s.youtubePlayerParams)),s=''}else if(c.vimeo)d="?autoplay="+l+"&api=1",this.core.s.vimeoPlayerParams&&(d=d+"&"+e.param(this.core.s.vimeoPlayerParams)),s='';else if(c.dailymotion)d="?wmode=opaque&autoplay="+l+"&api=postMessage",this.core.s.dailymotionPlayerParams&&(d=d+"&"+e.param(this.core.s.dailymotionPlayerParams)),s='';else if(c.html5){var f=r.substring(0,1);("."===f||"#"===f)&&(r=e(r).html()),s=r}else c.vk&&(d="&autoplay="+l,this.core.s.vkPlayerParams&&(d=d+"&"+e.param(this.core.s.vkPlayerParams)),s='');return s},i.prototype.loadVideoOnclick=function(e){var o=this;if(e.find(".lg-object").hasClass("lg-has-poster")&&e.find(".lg-object").is(":visible")){if(e.hasClass("lg-has-video")){var i,a,t,r,s=setInterval(function(){if(i=e.find(".lg-youtube").get(0),a=e.find(".lg-vimeo").get(0),t=e.find(".lg-dailymotion").get(0),r=e.find(".lg-html5").get(0),i||a||t||r){if(i)i.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}',"*");else if(a)try{$f(a).api("play")}catch(l){console.error("Make sure you have included froogaloop2 js")}else if(t)t.contentWindow.postMessage("play","*");else if(r){if(o.core.s.videojs)try{videojs(r).play()}catch(d){console.error("Make sure you have included videojs")}else r.play()}e.addClass("lg-video-playing"),clearInterval(s)}},10);e.addClass("lg-video-playing")}else{e.addClass("lg-video-playing lg-has-video");var l,d,c=function(i,a){if(e.find(".lg-video").append(o.loadVideo(i,"",!1,o.core.index,a)),a){if(o.core.s.videojs){var t=o.core.$slide.eq(o.core.index).find(".lg-html5").get(0),r=o.core.s.videojsOptions;try{videojs(t,r,function(){this.addClass("my-test-ready-class"),this.play()})}catch(s){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?c(l=o.core.s.dynamicEl[o.core.index].src,d=o.core.s.dynamicEl[o.core.index].html):c(l=o.core.$items.eq(o.core.index).attr("href")||o.core.$items.eq(o.core.index).attr("data-src"),d=o.core.$items.eq(o.core.index).attr("data-html"));var n=e.find(".lg-object");e.find(".lg-video").append(n),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")}))}}},i.prototype.destroy=function(){this.videoLoaded=!1},e.fn.lightGallery.modules.video=i}()});