// 1a. Get location path - replaces getting referrer via PHP var referrer = window.location.href; // console.log(referrer); var l = getLocation(referrer); var path_name = String(l.pathname); // console.log(path_name); drawPortal(path_name, "highlandscurrent", "puzzle"); function getLocation(href) { var l = document.createElement("a"); l.href = href; return l; }; // 2. load jquery var jQueryScriptOutputted = false; initJQuery(); // 3. load re-sizer plugin for host page (function(d, script) { script = d.createElement('script'); script.type = 'text/javascript'; script.async = true; script.onload = function(){ // 4. init resizer // iFrameResize({log:false}); iFrameResize({ log: false }, '#kingportal') console.log() }; script.src = '//puzzles.kingdigital.com/v6.1/js/iframeResizer.min.js'; d.getElementsByTagName('body')[0].appendChild(script); }(document)); /* Get args from URI */ function get(name) { var q = unescape(location.search.substring(1)).split(/[=&]/); for (var j=0; j= 2) return stringValue; if (stringValue.length == 1) return ("0" + stringValue); return "00"; } /****************************************************************************************/ /* Draws portal */ function drawPortal(this_path, clientID, contentType, contentID) { // get args passed in URI var content_name = get("content_name"); // support for old contentID's switch (content_name) { case "joseph": content_name="xw_joseph"; break; case "sheffer": content_name="xw_sheffer"; break; case "premier": content_name="xw_premier"; break; } var date = get("date"); var print_opt = get("print_opt"); if (contentID!=null) { // puzzle can only be alacarte based on this request; ignore content_name var isAlacarte = "yes"; var content_name = contentID; } else { var isAlacarte = "no"; } // if it's a sample, default to first day of last month, if no month is provided if ((date==null) && (clientID=="sample_alacarte")){ var tempDate = new Date(); var curYear = tempDate.getFullYear(); var curMonth = tempDate.getMonth(); var sampleDate=new Date(curYear, curMonth-1, 0); sampleDate.setDate(sampleDate.getDate()+1); // add a day date = dateToString(sampleDate); } // set base iframe url; add clientID and a la carte opt var viewURL = ("//puzzles.kingdigital.com/v6.1/server/display.php?clientID="+clientID+"&alacarte="+isAlacarte); viewURL += ("&path_name="+this_path); // if content_name is specified, check for date; append viewURL as needed if (content_name!=null){ if (date!=null){ viewURL += ("&date="+date); } if (print_opt!=null){ viewURL += ("&print_opt="+print_opt); // DEPRICATE?? } viewURL += ("&content_name="+content_name); } /******** Write iframe code to page ******/ /*NEW*/ // create the special div var puzzdiv = document.createElement("div"); puzzdiv.setAttribute("id", "kingpuzz"); // create the iframe inside div var kingiframe = document.createElement("iframe"); kingiframe.setAttribute("id", "kingportal"); kingiframe.setAttribute("name", "kingportal"); kingiframe.setAttribute("src", viewURL); kingiframe.setAttribute("width", "100%"); kingiframe.setAttribute("height", 1500); kingiframe.setAttribute("scrolling", "no"); kingiframe.setAttribute("style", "border:0px; max-width:1000px"); // add iframe to div puzzdiv.appendChild(kingiframe); // get the current script in the DOM var kingscript = document.currentScript; // draw the div, placing it before the script element on the page kingscript.parentNode.insertBefore(puzzdiv, kingscript); // -- Check for device type var ua = navigator.userAgent; var checker = { iphone: ua.match(/(iPhone|iPod|iPad)/), blackberry: ua.match(/BlackBerry/), android: ua.match(/Android/) }; if (checker.android || checker.iphone || checker.blackberry) { // scroll puzzle frame into view document.getElementById('kingportal').scrollIntoView(); } } /****************************************************************************************/ /* initialize jQuery if it's not present */ function initJQuery() { // if the jQuery object isn't available if (typeof(jQuery) == 'undefined') { if (! jQueryScriptOutputted) { //output the script (load it from jquery api) var script = document.createElement("SCRIPT"); script.src = 'https://code.jquery.com/jquery-latest.min.js'; script.type = 'text/javascript'; script.onload = function() { var $ = window.jQuery; }; document.getElementsByTagName("body")[0].appendChild(script); // output the script once. jQueryScriptOutputted = true; } setTimeout("initJQuery()", 50); } } /* get stored game data by either LS or Richie */ function getCookie(cname, callback) { var ua = navigator.userAgent; var checker = { iphone: ua.match(/(iPhone|iPod|iPad)/), android: ua.match(/Android/) }; if (checker.android) { // if(richie) { richie.getGlobalPersistedParameter(cname, function (storedValue) { // alert(cname); // alert(storedValue); var temp = (cname + " | " + storedValue); if (storedValue !== null) { callback(temp); } }); } else { var Saved = localStorage.getItem(cname); if (Saved !== null) { var temp = (cname + " | " + Saved); callback(temp); } } } /* bind message event to action */ function bindEvent(element, eventName, eventHandler) { element.addEventListener(eventName, eventHandler, false); } /* send a message to the child iframe */ var iframeEl = document.getElementById('kingportal'); // specific iframe we are to message function sendMessage(msg) { // console.log(iframeEl); // console.log(msg); iframeEl.contentWindow.postMessage(msg, '*'); }; // Listen to all messages, sent or received bindEvent(window, 'message', function (e) { // where "e.data" is the actual message if (e.data.includes("-Saved-")){ var ua = navigator.userAgent; var checker = { iphone: ua.match(/(iPhone|iPod|iPad)/), android: ua.match(/Android/) }; // is it game data needing to be saved? if (e.data.includes(" | ")){ var message = e.data.split(' | '); if (checker.android) { richie.setGlobalPersistedParameter(message[0], message[1]); } else { try { localStorage.setItem(message[0], message[1]); } catch(error) { console.error(error); } } // or is it game data being sent back to engine? } else { getCookie(e.data, function(value) { sendMessage(value); }); } } });