// // ZorgDNA QDNA widget load code // This code loads the QDNA widget // // check if the browser has the minimal requirements for us to continue... if(typeof(window)==="undefined") { console.error("This browser does not support the environment we require"); } else { // yes, the minimal setup is there! // check if the basic skillset is present if(typeof(window.ZorgDNA)==="undefined"||typeof(window.ZorgDNA.QDNA)==="undefined") { window.ZorgDNA = { QDNA: { version: 2, host: "https://portal.qdna.nl", sessions: [] } }; // are we missing prototypes? if(typeof(String.prototype.replaceAll)!=="function") { String.prototype.replaceAll = function(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); }; } if(typeof(String.prototype.includes)!=="function") { String.prototype.includes = function(item) { return this.indexOf(item)!==-1; }; } if(typeof(Array.prototype.includes)!=="function") { Array.prototype.includes = function(dinges) { var tak = false; for(var i = 0 ; i < this.length ; i++){ if(this[i]===dinges){ tak = true; } } return tak; }; } if(typeof(Number.prototype.isNaN)!=="function") { Number.prototype.isNaN = function(dinges){ return Number(dinges) != dinges; }; } window.addEventListener("message",function(event){ // we got a event! if(event.data.length>0) { // its a valid event! if(event.data[0]==="zorgdna.qdna") { // its a qdna event! // get event data var selectedsession = null; var keydata = event.data[3]; for(var i = 0 ; i < window.ZorgDNA.QDNA.sessions.length ; i++) { if(window.ZorgDNA.QDNA.sessions[0].parameters.widget_key==keydata) { selectedsession = window.ZorgDNA.QDNA.sessions[0]; } } if(selectedsession==null) { throw new Error("Invalid session"); } // do the task if(event.data[1]=="setsize") { selectedsession.iframeElement.style.height = event.data[2] + "px"; } else { throw new Error("No such option: " + event.data[1]); } } } },false); } // the raw basics are setup // lets initialise the scriptitems which are not set to completed var scriptitems = document.getElementsByTagName('script'); for(var scriptitemsindex = 0 ; scriptitemsindex < scriptitems.length ; scriptitemsindex++) { var activescriptitem = scriptitems[scriptitemsindex]; // is the item of the right type? if(!(activescriptitem instanceof HTMLScriptElement)) { // no, it is not, skip! continue; } // is it the right scripttype? if(activescriptitem.getAttribute("type")!=="text/javascript") { // no, this is not the right type continue; } // check the URL var hosturl = activescriptitem.getAttribute("src"); if(typeof(hosturl)!=="string") { // it does not have a SRC tag... skip it! continue; } if(!hosturl.includes(window.ZorgDNA.QDNA.host)) { // it does not have the host URL continue; } // create the session var activeSession = {}; activeSession.finished = false; activeSession.initiator = activescriptitem; // handle the parameters var queryurl = hosturl.includes("?")?hosturl.split("?")[1]:""; activeSession.parameters = []; var tokens = queryurl.split("&"); for(var tokenindex = 0 ; tokenindex < tokens.length ; tokenindex++) { var pair = tokens[tokenindex].split("="); activeSession.parameters[pair[0]] = pair[1]; } // do we have all required parameters? if(!Object.keys(activeSession.parameters).includes("widget_key")) { throw new Error("The script url which initialised the QDNA widget misses a obligatory parameter: widget_key"); } // lets load the latest information var xhr = new XMLHttpRequest(); xhr.open('GET', window.ZorgDNA.QDNA.host + "/api/getwidget?widget_key=" + activeSession.parameters.widget_key + "&nocache=1", true); xhr.onreadystatechange = function(event){ if(this.readyState==4) { // yes, we are loaded if(this.status==200) { // status is 200 // lets get the required information! var widget_object = JSON.parse(this.responseText); if(widget_object.error!==null) { throw new Error("Could not finish the QDNA widget API call without errors. QDNA specified an error message: "+widget_object.error); } // // lets create the iframe activeSession.iframeElement = document.createElement("iframe"); activeSession.iframeElement.style.border = "0px"; activeSession.iframeElement.style.overflow = "hidden"; activeSession.iframeElement.style.overflow = "hidden"; activeSession.iframeElement.scrolling = "no"; activeSession.iframeElement.allowtransparency = true; activeSession.initiator.parentNode.insertBefore(activeSession.iframeElement, activeSession.initiator.nextSibling); activeSession.iframeElement.src = 'about:blank'; activeSession.iframeElement.style.background = "transparent"; // // lets initiate all other information if(typeof widget_object.info.Height_type === "undefined") { widget_object.info.Height_type = "px"; } if(typeof widget_object.info.Width_type === "undefined") { widget_object.info.Width_type = "px"; } activeSession.iframeElement.style.width = widget_object.info.Width + widget_object.info.Width_type; activeSession.iframeElement.style.height = widget_object.info.Height + widget_object.info.Height_type ; activeSession.iframeElement.className = widget_object.info.ClassName; var sessioncompleted = function(){ activeSession.iframeElement.contentWindow.ZorgDNA.QDNA.setHost(window.ZorgDNA.QDNA.host); activeSession.iframeElement.contentWindow.ZorgDNA.QDNA.setArguments(activeSession.parameters); activeSession.iframeElement.contentWindow.ZorgDNA.QDNA.initialise(); }; setTimeout(function(){ activeSession.iframeElement.contentWindow.widget_object=widget_object; activeSession.iframeElement.contentWindow.document.body.innerHTML="
Loading widget... |
[whatsapp_button id=”1870″]