MultipleWidgets = new function() { loadJquery=function(){ var script; if (!(typeof jQuery!=="undefined"&&jQuery!==null)) { script=document.createElement("script"); script.type="text/javascript"; script.onload=script.onreadystatechange=init; script.src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; return document.getElementsByTagName('head')[0].appendChild(script); } else { return init(); } }; if (window.addEventListener){ window.addEventListener("load",loadJquery,false) } else if(window.attachEvent){ window.attachEvent("onload",loadJquery); } function init() { requestStylesheet(); getPolitifactData(getPunditfactData); } function requestStylesheet() { stylesheet = document.createElement("link"); stylesheet.rel = "stylesheet"; stylesheet.type = "text/css"; stylesheet.href = "https://static.politifact.com/js/widget/politifactwidget2.css"; stylesheet.media = "all"; document.lastChild.firstChild.appendChild(stylesheet); } function getPolitifactData(callback) { var url = 'https://www.politifact.com/api/statements/truth-o-meter/multiple/json/?n=5'; //default gives you 5 var divId = 'politifact-5'; var div = document.getElementById(divId); if (typeof div !== 'undefined') { fillWidgetDiv(divId,5,url); } divId = 'politifact-3'; div = document.getElementById(divId); if (typeof div !== 'undefined') { fillWidgetDiv(divId,3,url); } $(function() { $("#politifact-3, #politifact-5, #punditfact-3, #punditfact-5").addClass('widget-politifact'); }); callback(); } function getPunditfactData() { //callback var url = 'https://www.politifact.com/api/statements/punditfact/multiple/json/?n=5'; var divId = 'punditfact-5'; var div = document.getElementById(divId); if (typeof div !== 'undefined') { fillWidgetDiv(divId,5,url); } divId = 'punditfact-3'; div = document.getElementById(divId); if (typeof div !== 'undefined') { fillWidgetDiv(divId,3,url); } } function fillWidgetDiv(id,count,urlService) { var data = ''; $.ajax({ url : urlService, dataType : "jsonp", crossDomain: true, success: function (data) { var div = document.getElementById(id); if (typeof div !== undefined) { //alert("div is not undefined! "+id); var widgetBlock = ''; var headerBlock = ''; var botmBlock = ''; var innerBlock = ''; //alert("getting widget for "+id+" url="+urlService); if (id.indexOf('punditfact') > -1) { headerBlock += '
\n'; // innerBlock +='