var TF_Video_Input_Previewer=function(){function e(){this.initAll(),this.initEvents()}var t=e.prototype;return t.initAll=function(){var e,o,t;window.IntersectionObserver&&(e=document.querySelectorAll(".tf-video-url-input-value"))&&(o=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"),o.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 o=t.dataset.provider,i=("FacebookVideo"==o&&(o="facebook"),this.getVideoDetails(e.value));if(i.provider!==o.toLowerCase())t.classList.remove("is-visible");else switch(t.classList.add("is-visible"),i.provider){case"youtube":case"vimeo":case"dailymotion":t.innerHTML='<iframe height="280" src="'+i.url+'" />';break;case"facebook":t.innerHTML='<iframe width="500" height="280" src="https://www.facebook.com/plugins/video.php?width=500&href='+i.url+'"></iframe>';break;case"selfhostedvideo":var n=i.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,o={url:e,provider:"selfhostedvideo"},i=e.match(/^https?:\/\/(?:m\.|www\.)?youtube\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/|live\/)?([a-zA-Z0-9_-]{11})(?:[&?][^\s]*)?|^https?:\/\/youtu\.be\/([a-zA-Z0-9_-]{11})(?:[&?][^\s]*)?/);return i&&(t=i?i[1]||i[2]:null,o.url="https://youtube.com/embed/"+t,o.provider="youtube"),(i=e.match(/^https?:\/\/(?:www\.)?(?:player\.)?vimeo\.com\/(\d+)/))&&(t=i?i[1]:null,o.url="https://player.vimeo.com/video/"+t,o.provider="vimeo"),/^(?:(?:https?:)?\/\/)?(?:www\.)?facebook\.com\/(?:watch\/\?v=|[\w\.]+\/videos\/(?:[\w\.]+\/)?)?(\d+)/.test(e)&&(o.provider="facebook"),(i=e.match(/(?:dailymotion\.com\/(?:video|hub)\/|dai\.ly\/)([a-zA-Z0-9]+)/))&&(t=i?i[1]:null,o.url="https://www.dailymotion.com/embed/video/"+t,o.provider="dailymotion"),o},e}();document.addEventListener("DOMContentLoaded",function(){new TF_Video_Input_Previewer});

