var OpeningSoundPreviewer=function(){function e(){this.select='select[name="jform[opening_sound][source]"]',this.customFile='input[name="jform[opening_sound][file]"]',this.customUrl='input[name="jform[opening_sound][url]"]',this.initEvents()}var t=e.prototype;return t.initEvents=function(){var t=this;this.initJ3Events(),document.addEventListener("change",function(e){t.onChangeOpeningSoundSource(e)}),document.querySelector(this.customFile).addEventListener("blur",function(e){t.onTypedCustomFile(Joomla.getOptions("engagebox_editor_object").siteUrl+e.target.value)}),document.querySelector(this.customFile).addEventListener("change",function(e){t.onTypedCustomFile(Joomla.getOptions("engagebox_editor_object").siteUrl+e.target.value)}),document.querySelector(this.customUrl).addEventListener("blur",function(e){t.onTypedCustomUrl(e.target.value)})},t.initJ3Events=function(){var t=this;window.jQuery&&jQuery(this.select).on("change",function(e){t.onChangeOpeningSoundSource(e)})},t.onTypedCustomFile=function(e){var t;""!==e&&e!==(t=this.getCustomFileElement()).dataset.prevValue&&(t.setAttribute("data-prev-value",e),this.playSound(e))},t.onTypedCustomUrl=function(e){var t;""!==e&&e!==(t=this.getCustomUrlElement()).dataset.prevValue&&(t.setAttribute("data-prev-value",e),this.playSound(e))},t.onChangeOpeningSoundSource=function(e){e=e.target.closest(this.select);if(e){var t=e.value;switch(t){case"file":this.getCustomFileElement().removeAttribute("data-prev-value"),this.onTypedCustomUrl(Joomla.getOptions("engagebox_editor_object").siteUrl+this.getCustomFileValue());break;case"url":this.getCustomUrlElement().removeAttribute("data-prev-value"),this.onTypedCustomUrl(this.getCustomUrlValue());break;case"earth":case"jupiter":case"mars":case"moon":case"uranus":var n=Joomla.getOptions("engagebox_editor_object").siteUrl+"media/com_rstbox/sound/"+t+".mp3";this.playSound(n)}}},t.getCustomFileElement=function(){return document.querySelector(this.customFile)},t.getCustomFileValue=function(){return this.getCustomFileElement().value},t.getCustomUrlElement=function(){return document.querySelector(this.customUrl)},t.getCustomUrlValue=function(){return this.getCustomUrlElement().value},t.playSound=function(e){e=new Audio(e);e.pause(),e.currentTime=0,e.play()},e}();document.addEventListener("DOMContentLoaded",function(){new OpeningSoundPreviewer});

