verticalMyID = "log_vertical"; if ((window.jQuery)) { //console.log( verticalMyID + " Jquery is loaded. Continuing to ajaxRenderWidget()."); setCookie("jqLoading", false, null); verticalAjaxRenderWidget(); } else { if (getCookie("jqLoading") == true) { //console.log( verticalMyID + " Jquery is not loaded. Running waitForJq()"); waitForJq(); } else if (getCookie("jqLoading") == false) { //console.log( verticalMyID + " Jquery is NOW loaded. Running ajaxRenderWidget()"); verticalAjaxRenderWidget(); } else { //console.log( verticalMyID + " Jquery is being loaded..."); setCookie("jqLoading", false, null); dynamicJQLoad(); } } function verticalAjaxRenderWidget() { if (getCookie("injectLoading") == true) { //console.log(verticalMyID + " injectLoading is true. Going to loop in waitForInjectLoad..."); waitForInjectLoad(); } else { //console.log(verticalMyID + " injectLoading being set true, running render widgets."); setCookie("injectLoading", true, null); jQuery.ajax({ dataType:'jsonp', cache: false, url:"http://www.twylah.com/transportgooru/widgets/trending_render?layout=vertical&widget_caption=", crossDomain:true, success:function (data) { jQuery("#twylah-trending-transportgooru-vertical").html(htmlDecode(data.trending_widgets)); //console.log(verticalMyID + " using div_id: " + "#twylah-trending-transportgooru-vertical"); //console.log(verticalMyID + " loaded html, setting injectLoading to false."); setCookie("injectLoading", false, null); } }); } } function dynamicJQLoad() { //console.log( verticalMyID + " loading JQuery into head."); setCookie("jqLoading", true, null); var s = document.createElement('script'); s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'); s.setAttribute('type', 'text/javascript'); document.getElementsByTagName('head')[0].appendChild(s); s.onload = function () { //console.log( verticalMyID + " loading into head completed."); jQuery.noConflict(); setCookie("jqLoading", false, null); verticalAjaxRenderWidget(); } } function waitForInjectLoad() { //console.log(verticalMyID + " waitForInject") if (getCookie("injectLoading") == true) { //console.log(verticalMyID + " Still waiting for injectLoading to go false."); setTimeout("waitForInjectLoad()", 5000); } else if (getCookie("injectLoading") == false) { //console.log(verticalMyID + " injectLoading is now false. calling verticalAjaxRenderWidget()"); verticalAjaxRenderWidget(); } } function waitForJq() { if (getCookie("jqLoading") == true) { //console.log( verticalMyID + " inside waitForJq. Waiting for load..."); setTimeout("waitForJq()", 5000); } else if (getCookie("jqLoading") == false) { //console.log( verticalMyID + " inside waitForJq. JQ load completed. next verticalAjaxRenderWidget()..."); verticalAjaxRenderWidget(); } } function htmlDecode(input) { var e = document.createElement('div'); e.innerHTML = input; if (e.childNodes.length === 0) { return ""; } else { return e.childNodes[0].nodeValue.replace(/(^")|("$)/g, ""); } } function getCookie(c_name) { var i, x, y, ARRcookies = document.cookie.split(";"); for (i = 0; i < ARRcookies.length; i++) { x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=")); y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == c_name) { return unescape(y); } } } function setCookie(c_name, value, exdays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()); document.cookie = c_name + "=" + c_value; }