// 1a. Get location path - replaces getting referrer via PHP var host_location = window.location.href; var host_url = new URL(host_location); var host_origin = String(host_url.origin); var host_path = String(host_url.pathname); console.log(host_location); console.log(host_url); console.log(host_origin); // everything after domain console.log(host_path); // everything after domain // 1b. load iframe drawPortal(host_origin, host_path, "gannett"); // 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 = '//g-king.comicskingdom.net/v2/js/iframeResizer.min.js'; d.getElementsByTagName('body')[0].appendChild(script); }(document)); /****************************************************************************************/ /* STAR OF THE SHOW */ /****************************************************************************************/ /* Draws portal */ function drawPortal(this_origin, this_path, clientID, contentID) { // get args passed in URI var content_id = get_fr_uri("content_id"); var pubDate = get_fr_uri("pubdate"); var print_opt = get_fr_uri("print_opt"); if (contentID!=null) { // puzzle can only be alacarte based on this request; ignore content_id var isAlacarte = "yes"; var content_id = contentID; } else { var isAlacarte = "no"; } // if it's a sample, default to first day of last month, if no month is provided if ((pubDate==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 pubDate = dateToString(sampleDate); } // set base iframe url; add clientID and a la carte opt var viewURL = ("//g-king.comicskingdom.net/v2/server/display.php?client_id="+clientID+"&alacarte="+isAlacarte); viewURL += ("&host_origin="+this_origin); viewURL += ("&host_path="+this_path); // if content_id is specified, check for pubDate; append viewURL as needed if (content_id!=null){ if (pubDate!=null){ viewURL += ("&pubdate="+pubDate); } if (print_opt!=null){ viewURL += ("&print_opt="+print_opt); // DEPRICATE?? } viewURL += ("&content_id="+content_id); } /******** Write iframe code to page ******/ /*NEW*/ // get special div if it's already present var puzzdiv = document.getElementById("comicwidget"); if (puzzdiv==null){ // create the special div var puzzdiv = document.createElement("div"); puzzdiv.setAttribute("id", "comicwidget"); var divCreated = true; } else { var divCreated = false; } // 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", 600); // use to be 1500, but that's way too big kingiframe.setAttribute("scrolling", "no"); kingiframe.setAttribute("style", "border:0px"); // 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 if (divCreated) { 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(); } } /****************************************************************************************/ /* GENERAL FUNCTIONS */ /****************************************************************************************/ /* 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.async = true; script.type = 'text/javascript'; script.src = 'https://code.jquery.com/jquery-latest.min.js'; script.onload = function() { var $ = window.jQuery; }; document.getElementsByTagName("body")[0].appendChild(script); // output the script once. jQueryScriptOutputted = true; } setTimeout("initJQuery()", 50); } } /****************************************************************************************/ /* Parse individual arg from URI */ function get_fr_uri(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"; } /****************************************************************************************/ /* DEPRICATED? */ /****************************************************************************************/ /* 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); }); } } }); */