class AFormPopup { constructor(options) { var _this = this; _this.id = '_' + Math.random().toString(36).substr(2, 9); _this.options = options; } setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } init() { var _this = this; _this.remove(); var div = document.createElement("div"); div.innerHTML = `
`; div.classList.add("acelle-popup"); div.id = 'Popup_' + _this.id; document.body.appendChild(div); this.node = div; this.iframe = document.getElementById('Popup'+_this.id+'Frame'); this.loadCss('{{ url('core/css/form_popup.css') }}'); window.addEventListener("message", function(event) { if (typeof(event.data.frameSize) != 'undefined') { _this.adjustIframeSize(event.data.frameSize); } if (typeof(event.data.alert) != 'undefined') { alert(event.data.alert.message); } if (typeof(event.data.loaded) != 'undefined') { var es = document.getElementsByClassName('acelle-popup'); if(es.length > 0){ es[0].classList.add("acelle-popup-loaded"); } } }); document.getElementById('Popup'+_this.id+'Close').addEventListener("click", function() { _this.hide(); }); // set opacity _this.setOverlayOpacity(); } setOverlayOpacity() { if (this.options.overlayOpacity) { var es = document.getElementsByClassName('acelle-popup'); if(es.length > 0){ es[0].style.background = 'rgba(0,0,0,'+this.options.overlayOpacity+')'; } } } remove() { var oldEs = document.getElementsByClassName('acelle-popup'); if(oldEs.length > 0){ oldEs[0].parentNode.removeChild(oldEs[0]); } } adjustIframeSize(size) { this.iframe.style.height = size.height + 'px'; } loadCss(url) { if (window.form_popup_css == null) { var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = url; link.media = 'all'; head.appendChild(link); window.form_popup_css = link; } } show() { document.body.classList.add("acelle-popup-open"); } hide() { document.body.classList.remove("acelle-popup-open"); } loadOneTime() { if (this.getCookie('popupLoaded') === "") { this.init(); this.show(); this.setCookie('popupLoaded', true); } } load(options) { // update options if (typeof(options) !== 'undefined') { this.options = $.extend({}, this.options, options); } this.init(); this.show(); } };