(function () { init_iframe(); })(); function init_iframe(ev) { let im_obj = { init: function () { this.add_style(); this.btn = Array.from(document.getElementsByClassName('im_btn_show_iframe')); this.affiliate_id = null; this.affiliate_typ = null; this.additional_value = null; if(this.btn.length < 1) return; this.shorty = this.btn[0].getAttribute('data-webinar-shorty'); if(!this.shorty) return; for(let b of this.btn){ b.removeAttribute('disabled'); b.removeAttribute('onclick'); } this.iframe = null; let script = document.currentScript; if (!script){ this.sub = location.host; if(this.btn[0].hasAttribute('data-memo')){ this.additional_value = this.btn[0].getAttribute('data-memo'); } if(this.btn[0].hasAttribute('data-tracking')){ this.affiliate_typ = this.btn[0].getAttribute('data-tracking'); this.add_digi_affiliate(); } } else { this.sub = script.src.split('/')[2]; if(script.getAttribute('data-tracking')){ this.affiliate_typ = script.getAttribute('data-tracking'); this.add_digi_affiliate(); } if(script.getAttribute('data-memo')){ this.additional_value = script.getAttribute('data-memo'); } } this.register_events(); }, create_iframe: function () { if(document.getElementById('im_iframe_ov_webinar')){ im_obj.iframe = document.getElementById('im_iframe_ov_webinar'); return; } im_obj.iframe = document.createElement('iframe'); let link_var = ''; link_var = ((im_obj.affiliate_typ)? '?id='+im_obj.affiliate_id+'&type='+im_obj.affiliate_typ : ''); if(im_obj.additional_value){ link_var = link_var+((link_var !== '') ? '&' : '?')+'memo='+im_obj.additional_value; } im_obj.iframe.src = 'https://'+im_obj.sub+'/i/wov/'+im_obj.shorty+link_var; im_obj.iframe.id = 'im_iframe_ov_webinar'; let container = document.body.getElementsByTagName('main')[0]; if(!container) container = document.body; container.insertBefore(im_obj.iframe, container.lastChild); }, register_events: function () { let eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; let eventer = window[eventMethod]; let messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message"; eventer(messageEvent, function (e) { if(e.data.hasOwnProperty('close_frame')){ im_obj.hide_iframe(); } else if(e.data.hasOwnProperty('redirect')){ window.location = e.data.redirect; } }); for(let b of im_obj.btn){ b.onclick = im_obj.show_iframe; } if(this.button_clicked){ im_obj.show_iframe(); } }, add_style: function(){ if(document.head){ let style = document.createElement('style'); style.innerHTML = 'button.im_btn_show_iframe:disabled {background: gray !important; color: white !important; cursor: not-allowed !important;}'; document.head.append(style); } }, hide_iframe: function () { if(!im_obj.iframe) im_obj.iframe = document.getElementById('im_iframe_ov_webinar'); im_obj.iframe.setAttribute('style', 'width: 0; height:0; display: none;'); }, show_iframe: function () { if(!im_obj.iframe) im_obj.create_iframe(); im_obj.iframe.setAttribute('style', 'width: 100vw; min-height:100vh; z-index: 99999; position: fixed; top: 0; left:0; border: none;'); }, add_digi_affiliate: function () { window.addEventListener('digistore24_affiliate', function (event) { im_obj.affiliate_id = event.detail.affiliate; }, false); } }; im_obj.button_clicked = (ev !== undefined); im_obj.init(); }