var TF_Notices=function(){function t(){this.app_ajax_url="?option=com_ajax&format=raw&plugin=nrframework&task=Notices",this.notices=document.querySelector(".tf-notices"),this.root_url=this.notices.dataset.root,this.token=this.notices.dataset.token,this.ext_element=this.notices.dataset.extElement,this.ext_xml=this.notices.dataset.extXml,this.ext_type=this.notices.dataset.extType,this.exclude=JSON.parse(this.notices.dataset.exclude),this.current_url=this.notices.dataset.currentUrl,this.init()}var e=t.prototype;return e.init=function(){this.showNotices(),this.initEvents()},e.showNotices=function(){var e=this,t={ext_element:this.ext_element,ext_xml:this.ext_xml,ext_type:this.ext_type,exclude:this.exclude,current_url:this.current_url,action:"ajaxnotices"},o=["downloadkey","license","outdated","geolocation","update","upgradetopro","upgradetobundle","error"];this.call(t,function(t){for(index in o)t.notices[o[index]]&&(e.notices.innerHTML+=t.notices[o[index]]);!t.notices.license&&t.notices.rate&&(e.notices.innerHTML+=t.notices.rate),""===e.notices.innerHTML&&e.notices.remove()})},e.initEvents=function(){var e=this;document.addEventListener("click",function(t){e.onNoticeClose(t,"outdated",7),e.onNoticeClose(t,"rate",30),e.onAlreadyRatedClose(t),e.onNoticeClose(t,"update",1),e.onNoticeClose(t,"expired",7),e.onNoticeClose(t,"expiring",1),e.onNoticeClose(t,"geolocation",30),e.onNoticeClose(t,"upgradeToPro",30),e.onNoticeClose(t,"upgradeToBundle",30),e.updateDownloadKey(t)}),document.addEventListener("mouseover",function(t){e.onTooltipEnter(t)}),document.addEventListener("mouseout",function(t){e.onTooltipExit(t)}),window.addEventListener("resize",function(t){e.updateTooltipPosition()},!0)},e.onTooltipEnter=function(t){var t=t.target.closest(".notice-tooltip-icon");!t||(t=t.closest(".notice-tooltip-wrapper").querySelector(".notice-tooltip")).classList.contains("is-visible")||(this.hideOtherTooltips(),t.classList.add("is-visible"),this.elementInViewport(t)?t.classList.remove("leftPosition"):t.classList.add("leftPosition"))},e.onTooltipExit=function(t){t.relatedTarget&&!t.relatedTarget.closest(".notice-tooltip-wrapper")&&this.hideOtherTooltips()},e.hideOtherTooltips=function(){var t=document.querySelectorAll(".notice-tooltip.is-visible");t.length&&t.forEach(function(t){t.classList.remove("is-visible"),t.classList.remove("leftPosition")})},e.elementInViewport=function(t){t=t.getBoundingClientRect();return 0<=t.top&&0<=t.left&&20<t.left&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)},e.updateTooltipPosition=function(){var e=this;document.querySelectorAll(".notice-tooltip").forEach(function(t){e.elementInViewport(t)?1300<window.innerWidth&&t.classList.remove("leftPosition"):t.classList.add("leftPosition")})},e.onAlreadyRatedClose=function(t){var e=t.target.closest(".tf-rate-already-rated");e&&(t.preventDefault(),e.closest(".tf-notice").remove(),this.setCookie("tfNoticeHideRateNotice_"+this.ext_element,9999))},e.onNoticeClose=function(t,e,o){void 0===o&&(o="");var i=t.target.closest(".btn-close");i&&i.closest(".tf-notice."+e)&&(t.preventDefault(),i.closest(".tf-notice").remove(),o)&&this.setCookie("tfNoticeHide"+this.capitalizeFirstLetter(e)+"Notice_"+this.ext_element,o)},e.onOutdatedNotice=function(){this.setCookie("tfNoticeHideOutdatedNotice_"+this.ext_element,3)},e.onRateNotice=function(){this.setCookie("tfNoticeHideRateNotice_"+this.ext_element,9999)},e.onUpdateNotificationNotice=function(){this.setCookie("tfNoticeHideUpdateNotice_"+this.ext_element,1)},e.onExpiredNotice=function(t){this.setCookie("tfNoticeHideExpiredNotice_"+this.ext_element,7)},e.onExpiringNotice=function(t){this.setCookie("tfNoticeHideExpiringNotice_"+this.ext_element,1)},e.updateDownloadKey=function(t){var e,o,i=t.target.closest(".tf-notice-download-key-btn");i&&(t.preventDefault(),""===(t=i.previousElementSibling.value).trim()?alert("Download Key entered is invalid"):(e=i.closest(".tf-notice"),o=i.closest(".actions"),i.classList.add("loading"),this.call({download_key:t,action:"downloadkey"},function(t){t.error?alert(t.response):(o.innerHTML=t.response,o.classList.add("green-text"),setTimeout(function(){e.remove()},1500)),i.classList.remove("loading")})))},e.capitalizeFirstLetter=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},e.setCookie=function(t,e){void 0===e&&(e=1);var o=new Date,i=o.getTime(),i=(o.setTime(i+1e3*(24*e*60*60)),"; expires="+o.toGMTString());document.cookie=t+"=true"+i+"; path=/"},e.call=function(e,o){var t=this.root_url+this.app_ajax_url+"&"+this.token+"=1",i=Object.keys(e).map(function(t){return encodeURIComponent(t)+"="+encodeURIComponent(e[t])}).join("&");fetch(t+"&"+i).then(function(t){return t.json()}).then(function(t){o(t)}).catch(function(t){console.error("Novarain Framework Notices: "+t)})},t}();document.addEventListener("DOMContentLoaded",function(){new TF_Notices});

