!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).lgVideo=o()}(this,function(){"use strict";function y(o){return Object.keys(o).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(o[e])}).join("&")}function g(e,o){return e.youtube?(e=e.youtube[2]?e.youtube[2].slice(1).split("&").map(function(e){return e.split("=")}).reduce(function(e,o){var o=o.map(decodeURIComponent),i=o[0],o=o[1];return e[i]=o,e},{}):"",o=o||{},o=i(i(i({},{wmode:"opaque",autoplay:0,mute:1,enablejsapi:1}),o),e),"?"+y(o)):""}var i=function(){return(i=Object.assign||function(e){for(var o,i=1,t=arguments.length;i";else if(n.vimeo){var r="lg-vimeo"+i,c=function(e,o){if(!o||!o.vimeo)return"";var i=o.vimeo[2]||"",e=e&&0!==Object.keys(e).length?"&"+y(e):"",t=((o.vimeo[0].split("/").pop()||"").split("?")[0]||"").split("#")[0],o=o.vimeo[1]!==t;return"?autoplay=0&muted=1"+(o?"&h="+t:"")+e+(i="?"==(i=o?i.replace("/"+t,""):i)[0]?"&"+i.slice(1):i||"")}(this.settings.vimeoPlayerParams,n);s='"}else if(n.wistia){e="lg-wistia"+i,c=y(this.settings.wistiaPlayerParams);s='"}else if(n.html5){for(var u="",h=0;h';if(t.tracks)for(h=0;h"}(h);var f="",p=t.attributes||{};Object.keys(p||{}).forEach(function(e){f+=e+'="'+p[e]+'" '}),s='"}return s},d.prototype.appendVideos=function(e,o){var i=this.getVideoHtml(o.src,o.addClass,o.index,o.html5Video),i=(e.find(".lg-video-cont").append(i),e.find(".lg-video-object").first());if(o.html5Video&&i.on("mousedown.lg.video",function(e){e.stopPropagation()}),this.settings.videojs&&null!=(e=this.core.galleryItems[o.index].__slideVideoInfo)&&e.html5)try{return videojs(i.get(),this.settings.videojsOptions)}catch(e){console.error("lightGallery:- Make sure you have included videojs")}},d.prototype.gotoNextSlideOnVideoEnd=function(e,o){var i=this,t=this.core.getSlideItem(o).find(".lg-video-object").first(),o=this.core.galleryItems[o].__slideVideoInfo||{};if(this.settings.gotoNextSlideOnVideoEnd)if(o.html5)t.on("ended",function(){i.core.goToNextSlide()});else if(o.vimeo)try{new Vimeo.Player(t.get()).on("ended",function(){i.core.goToNextSlide()})}catch(e){console.error("lightGallery:- Make sure you have included //github.com/vimeo/player.js")}else if(o.wistia)try{window._wq=window._wq||[],window._wq.push({id:t.attr("id"),onReady:function(e){e.bind("end",function(){i.core.goToNextSlide()})}})}catch(e){console.error("lightGallery:- Make sure you have included //fast.wistia.com/assets/external/E-v1.js")}},d.prototype.controlVideo=function(e,o){var i=this.core.getSlideItem(e).find(".lg-video-object").first(),e=this.core.galleryItems[e].__slideVideoInfo||{};if(i.get())if(e.youtube)try{i.get().contentWindow.postMessage('{"event":"command","func":"'+o+'Video","args":""}',"*")}catch(e){console.error("lightGallery:- "+e)}else if(e.vimeo)try{new Vimeo.Player(i.get())[o]()}catch(e){console.error("lightGallery:- Make sure you have included //github.com/vimeo/player.js")}else if(e.html5)if(this.settings.videojs)try{videojs(i.get())[o]()}catch(e){console.error("lightGallery:- Make sure you have included videojs")}else i.get()[o]();else if(e.wistia)try{window._wq=window._wq||[],window._wq.push({id:i.attr("id"),onReady:function(e){e[o]()}})}catch(e){console.error("lightGallery:- Make sure you have included //fast.wistia.com/assets/external/E-v1.js")}},d.prototype.loadVideoOnPosterClick=function(e,o){var i,t,s,n=this;e.hasClass("lg-video-loaded")?o&&this.playVideo(this.core.index):e.hasClass("lg-has-video")?this.playVideo(this.core.index):(e.addClass("lg-has-video"),o=void 0,i=this.core.galleryItems[this.core.index].src,(s=this.core.galleryItems[this.core.index].video)&&(o="string"==typeof s?JSON.parse(s):s),t=this.appendVideos(e,{src:i,addClass:"",index:this.core.index,html5Video:o}),this.gotoNextSlideOnVideoEnd(i,this.core.index),s=e.find(".lg-object").first().get(),e.find(".lg-video-cont").first().append(s),e.addClass("lg-video-loading"),t&&t.ready(function(){t.on("loadedmetadata",function(){n.onVideoLoadAfterPosterClick(e,n.core.index)})}),e.find(".lg-video-object").first().on("load.lg error.lg loadedmetadata.lg",function(){setTimeout(function(){n.onVideoLoadAfterPosterClick(e,n.core.index)},50)}))},d.prototype.onVideoLoadAfterPosterClick=function(e,o){e.addClass("lg-video-loaded"),this.playVideo(o)},d.prototype.destroy=function(){this.core.LGel.off(".lg.video"),this.core.LGel.off(".video")},d});