var TF_Video_Input_Previewer=function(){function e(){this.initAll(),this.initEvents()}var t=e.prototype;return t.initAll=function(){var e,i,t;window.IntersectionObserver&&(e=document.querySelectorAll(".tf-video-url-input-value"))&&(i=this,t=new IntersectionObserver(function(e,t){e.forEach(function(e){e.isIntersecting&&""!==(e=e.target).value&&!e.classList.contains("done")&&(e.classList.add("done"),i.update(e))})},{rootMargin:"0px 0px 0px 0px"}),e.forEach(function(e){t.observe(e)}))},t.initEvents=function(){document.addEventListener("click",function(e){this.onClear(e)}.bind(this)),document.addEventListener("change",function(e){this.onChange(e)}.bind(this)),document.addEventListener("focusout",function(e){this.onFinishTyping(e)}.bind(this))},t.onClear=function(e){var t,e=e.target.closest(".button-clear");e&&(e=e.closest(".controls"))&&e.querySelector(".tf-video-input-previewer-wrapper")&&(t=new CustomEvent("focusout",{bubbles:!0}),e.querySelector(".tf-video-url-input-value").dispatchEvent(t))},t.onChange=function(e){var t,e=e.target.closest(".controls");e&&e.querySelector(".tf-video-input-previewer-wrapper")&&(t=new CustomEvent("focusout",{bubbles:!0}),e.querySelector(".tf-video-url-input-value").dispatchEvent(t))},t.onFinishTyping=function(e){e=e.target.closest(".tf-video-url-input-value");e&&this.update(e)},t.update=function(e){var t=e.closest(".controls").querySelector(".tf-video-input-previewer-wrapper");if((t.innerHTML="")===e.value)t.classList.remove("is-visible");else{var i=t.dataset.provider,o=this.getVideoDetails(e.value);if(o.provider!==i.toLowerCase())t.classList.remove("is-visible");else switch(t.classList.add("is-visible"),o.provider){case"youtube":case"vimeo":case"dailymotion":t.innerHTML='<iframe height="280" src="'+o.url+'" />';break;case"facebook":t.innerHTML='<iframe width="500" height="280" src="https://www.facebook.com/plugins/video.php?width=500&href='+o.url+'"></iframe>';break;case"selfhostedvideo":var n=o.url.replace(/^\/|\/$/g,""),r=n;r.includes("http")||(r=[t.dataset.rootUrl,n].join("/")),t.innerHTML='<video controls><source src="'+r+'" /></video>'}}},t.getVideoDetails=function(e){var t,i={url:e,provider:"selfhostedvideo"},o=e.match(/^(?:https?:\/\/(?:m\.|www\.)?youtube\.com\/(?:shorts\/|[^/]+\/.+[=/]|watch[?/].*v=|embed\/)?([a-zA-Z0-9_-]{11})|https?:\/\/youtu\.be\/([a-zA-Z0-9_-]{11})).*/);return o&&(t=o?o[1]||o[2]:null,i.url="https://youtube.com/embed/"+t,i.provider="youtube"),(o=e.match(/^https?:\/\/(?:www\.)?(?:player\.)?vimeo\.com\/(\d+)/))&&(t=o?o[1]:null,i.url="https://player.vimeo.com/video/"+t,i.provider="vimeo"),/^(?:(?:https?:)?\/\/)?(?:www\.)?facebook\.com\/(?:watch\/\?v=|[\w\.]+\/videos\/(?:[\w\.]+\/)?)?(\d+)/.test(e)&&(i.provider="facebook"),(o=e.match(/(?:dailymotion\.com\/(?:video|hub)\/|dai\.ly\/)([a-zA-Z0-9]+)/))&&(t=o?o[1]:null,i.url="https://www.dailymotion.com/embed/video/"+t,i.provider="dailymotion"),i},e}();document.addEventListener("DOMContentLoaded",function(){new TF_Video_Input_Previewer});

