1 line
8.7 KiB
JavaScript
Executable File
1 line
8.7 KiB
JavaScript
Executable File
var __assign=function(){return(__assign=Object.assign||function(e){for(var o,t=1,i=arguments.length;t<i;t++)for(var s in o=arguments[t])Object.prototype.hasOwnProperty.call(o,s)&&(e[s]=o[s]);return e}).apply(this,arguments)},videoSettings={autoplayFirstVideo:!0,youTubePlayerParams:!1,vimeoPlayerParams:!1,wistiaPlayerParams:!1,gotoNextSlideOnVideoEnd:!0,autoplayVideoOnSlide:!1,videojs:!1,videojsTheme:"",videojsOptions:{}},lGEvents={afterAppendSlide:"lgAfterAppendSlide",init:"lgInit",hasVideo:"lgHasVideo",containerResize:"lgContainerResize",updateSlides:"lgUpdateSlides",afterAppendSubHtml:"lgAfterAppendSubHtml",beforeOpen:"lgBeforeOpen",afterOpen:"lgAfterOpen",slideItemLoad:"lgSlideItemLoad",beforeSlide:"lgBeforeSlide",afterSlide:"lgAfterSlide",posterClick:"lgPosterClick",dragStart:"lgDragStart",dragMove:"lgDragMove",dragEnd:"lgDragEnd",beforeNextSlide:"lgBeforeNextSlide",beforePrevSlide:"lgBeforePrevSlide",beforeClose:"lgBeforeClose",afterClose:"lgAfterClose",rotateLeft:"lgRotateLeft",rotateRight:"lgRotateRight",flipHorizontal:"lgFlipHorizontal",flipVertical:"lgFlipVertical",autoplay:"lgAutoplay",autoplayStart:"lgAutoplayStart",autoplayStop:"lgAutoplayStop"},param=function(o){return Object.keys(o).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(o[e])}).join("&")},paramsToObject=function(e){return e.slice(1).split("&").map(function(e){return e.split("=")}).reduce(function(e,o){var o=o.map(decodeURIComponent),t=o[0],o=o[1];return e[t]=o,e},{})},getYouTubeParams=function(e,o){if(!e.youtube)return"";e=e.youtube[2]?paramsToObject(e.youtube[2]):"",o=o||{},o=__assign(__assign(__assign({},{wmode:"opaque",autoplay:0,mute:1,enablejsapi:1}),o),e);return"?"+param(o)},isYouTubeNoCookie=function(e){return e.includes("youtube-nocookie.com")},getVimeoURLParams=function(e,o){if(!o||!o.vimeo)return"";var t=o.vimeo[2]||"",e=e&&0!==Object.keys(e).length?"&"+param(e):"",i=((o.vimeo[0].split("/").pop()||"").split("?")[0]||"").split("#")[0],o=o.vimeo[1]!==i;return"?autoplay=0&muted=1"+(o?"&h="+i:"")+e+(t="?"==(t=o?t.replace("/"+i,""):t)[0]?"&"+t.slice(1):t||"")},Video=function(){function e(e){return this.core=e,this.settings=__assign(__assign({},videoSettings),this.core.settings),this}return e.prototype.init=function(){var o=this;this.core.LGel.on(lGEvents.hasVideo+".video",this.onHasVideo.bind(this)),this.core.LGel.on(lGEvents.posterClick+".video",function(){var e=o.core.getSlideItem(o.core.index);o.loadVideoOnPosterClick(e)}),this.core.LGel.on(lGEvents.slideItemLoad+".video",this.onSlideItemLoad.bind(this)),this.core.LGel.on(lGEvents.beforeSlide+".video",this.onBeforeSlide.bind(this)),this.core.LGel.on(lGEvents.afterSlide+".video",this.onAfterSlide.bind(this))},e.prototype.onSlideItemLoad=function(e){var o=this,e=e.detail,t=e.isFirstSlide,i=e.index;this.settings.autoplayFirstVideo&&t&&i===this.core.index&&setTimeout(function(){o.loadAndPlayVideo(i)},200),!t&&this.settings.autoplayVideoOnSlide&&i===this.core.index&&this.loadAndPlayVideo(i)},e.prototype.onHasVideo=function(e){var e=e.detail,o=e.index,t=e.src,i=e.html5Video;e.hasPoster||(this.appendVideos(this.core.getSlideItem(o),{src:t,addClass:"lg-object",index:o,html5Video:i}),this.gotoNextSlideOnVideoEnd(t,o))},e.prototype.onBeforeSlide=function(e){this.core.lGalleryOn&&(e=e.detail.prevIndex,this.pauseVideo(e))},e.prototype.onAfterSlide=function(e){var o=this,e=e.detail,t=e.index,e=e.prevIndex,i=this.core.getSlideItem(t);this.settings.autoplayVideoOnSlide&&t!==e&&i.hasClass("lg-complete")&&setTimeout(function(){o.loadAndPlayVideo(t)},100)},e.prototype.loadAndPlayVideo=function(e){var o=this.core.getSlideItem(e);this.core.galleryItems[e].poster?this.loadVideoOnPosterClick(o,!0):this.playVideo(e)},e.prototype.playVideo=function(e){this.controlVideo(e,"play")},e.prototype.pauseVideo=function(e){this.controlVideo(e,"pause")},e.prototype.getVideoHtml=function(e,o,t,i){var s="",l=this.core.galleryItems[t].__slideVideoInfo||{},r=this.core.galleryItems[t],r=(r=r.title||r.alt)?'title="'+r+'"':"",n='allowtransparency="true"\n frameborder="0"\n scrolling="no"\n allowfullscreen\n mozallowfullscreen\n webkitallowfullscreen\n oallowfullscreen\n msallowfullscreen';if(l.youtube)var a="lg-youtube"+t,d=getYouTubeParams(l,this.settings.youTubePlayerParams),s='<iframe allow="autoplay" id='+a+' class="lg-video-object lg-youtube '+o+'" '+r+' src="'+(isYouTubeNoCookie(e)?"//www.youtube-nocookie.com/":"//www.youtube.com/")+"embed/"+(l.youtube[1]+d)+'" '+n+"></iframe>";else if(l.vimeo){var a="lg-vimeo"+t,c=getVimeoURLParams(this.settings.vimeoPlayerParams,l);s='<iframe allow="autoplay" id='+a+' class="lg-video-object lg-vimeo '+o+'" '+r+' src="//player.vimeo.com/video/'+(l.vimeo[1]+c)+'" '+n+"></iframe>"}else if(l.wistia){e="lg-wistia"+t,c=param(this.settings.wistiaPlayerParams);s='<iframe allow="autoplay" id="'+e+'" src="//fast.wistia.net/embed/iframe/'+(l.wistia[4]+(c=c?"?"+c:""))+'" '+r+' class="wistia_embed lg-video-object lg-wistia '+o+'" name="wistia_embed" '+n+"></iframe>"}else if(l.html5){for(var u="",g=0;g<i.source.length;g++)u+='<source src="'+i.source[g].src+'" type="'+i.source[g].type+'">';if(i.tracks)for(g=0;g<i.tracks.length;g++)!function(e){var o="",t=i.tracks[e];Object.keys(t||{}).forEach(function(e){o+=e+'="'+t[e]+'" '}),u+="<track "+o+">"}(g);var f="",p=i.attributes||{};Object.keys(p||{}).forEach(function(e){f+=e+'="'+p[e]+'" '}),s='<video class="lg-video-object lg-html5 '+(this.settings.videojs&&this.settings.videojsTheme?this.settings.videojsTheme+" ":"")+" "+(this.settings.videojs?" video-js":"")+'" '+f+">\n "+u+"\n Your browser does not support HTML5 video.\n </video>"}return s},e.prototype.appendVideos=function(e,o){var t=this.getVideoHtml(o.src,o.addClass,o.index,o.html5Video),t=(e.find(".lg-video-cont").append(t),e.find(".lg-video-object").first());if(o.html5Video&&t.on("mousedown.lg.video",function(e){e.stopPropagation()}),this.settings.videojs&&null!=(e=this.core.galleryItems[o.index].__slideVideoInfo)&&e.html5)try{return videojs(t.get(),this.settings.videojsOptions)}catch(e){console.error("lightGallery:- Make sure you have included videojs")}},e.prototype.gotoNextSlideOnVideoEnd=function(e,o){var t=this,i=this.core.getSlideItem(o).find(".lg-video-object").first(),o=this.core.galleryItems[o].__slideVideoInfo||{};if(this.settings.gotoNextSlideOnVideoEnd)if(o.html5)i.on("ended",function(){t.core.goToNextSlide()});else if(o.vimeo)try{new Vimeo.Player(i.get()).on("ended",function(){t.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:i.attr("id"),onReady:function(e){e.bind("end",function(){t.core.goToNextSlide()})}})}catch(e){console.error("lightGallery:- Make sure you have included //fast.wistia.com/assets/external/E-v1.js")}},e.prototype.controlVideo=function(e,o){var t=this.core.getSlideItem(e).find(".lg-video-object").first(),e=this.core.galleryItems[e].__slideVideoInfo||{};if(t.get())if(e.youtube)try{t.get().contentWindow.postMessage('{"event":"command","func":"'+o+'Video","args":""}',"*")}catch(e){console.error("lightGallery:- "+e)}else if(e.vimeo)try{new Vimeo.Player(t.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(t.get())[o]()}catch(e){console.error("lightGallery:- Make sure you have included videojs")}else t.get()[o]();else if(e.wistia)try{window._wq=window._wq||[],window._wq.push({id:t.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")}},e.prototype.loadVideoOnPosterClick=function(e,o){var t,i,s,l=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,t=this.core.galleryItems[this.core.index].src,(s=this.core.galleryItems[this.core.index].video)&&(o="string"==typeof s?JSON.parse(s):s),i=this.appendVideos(e,{src:t,addClass:"",index:this.core.index,html5Video:o}),this.gotoNextSlideOnVideoEnd(t,this.core.index),s=e.find(".lg-object").first().get(),e.find(".lg-video-cont").first().append(s),e.addClass("lg-video-loading"),i&&i.ready(function(){i.on("loadedmetadata",function(){l.onVideoLoadAfterPosterClick(e,l.core.index)})}),e.find(".lg-video-object").first().on("load.lg error.lg loadedmetadata.lg",function(){setTimeout(function(){l.onVideoLoadAfterPosterClick(e,l.core.index)},50)}))},e.prototype.onVideoLoadAfterPosterClick=function(e,o){e.addClass("lg-video-loaded"),this.playVideo(o)},e.prototype.destroy=function(){this.core.LGel.off(".lg.video"),this.core.LGel.off(".video")},e}();export default Video; |