(function () { var scriptName = "embed.js"; var jQuery; //noconflict var jqueryPath = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"; var jqueryVersion = "1.8.3"; var scriptTag; //referencia to the html script tag /******** Get reference to self (scriptTag) *********/ var allScripts = document.getElementsByTagName('script'); var targetScripts = []; for (var i in allScripts) { var name = allScripts[i].src if(name && name.indexOf(scriptName) > 0) targetScripts.push(allScripts[i]); } scriptTag = targetScripts[targetScripts.length - 1]; /******** helper function to load external scripts *********/ function loadScript(src, onLoad) { var script_tag = document.createElement('script'); script_tag.setAttribute("type", "text/javascript"); script_tag.setAttribute("src", src); if (script_tag.readyState) { script_tag.onreadystatechange = function () { if (this.readyState == 'complete' || this.readyState == 'loaded') { onLoad(); } }; } else { script_tag.onload = onLoad; } (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } /******** load external css *********/ function loadCss(href) { var link_tag = document.createElement('link'); link_tag.setAttribute("type", "text/css"); link_tag.setAttribute("rel", "stylesheet"); link_tag.setAttribute("href", href); (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link_tag); } /******** load jquery into 'jQuery' ********/ if (window.jQuery === undefined || window.jQuery.fn.jquery !== jqueryVersion) { loadScript(jqueryPath, initjQuery); } else { initjQuery(); } function initjQuery() { jQuery = window.jQuery.noConflict(true); main(); } function main() { jQuery(document).ready(function ($) { loadCss("http://smonitor.com.br/static/ung-r.css"); // jsonp call var jsonp_url = "http://smonitor.com.br/widget/?site=ung-r&qtd=3&tipo=mix&rank=tx"; jQuery.getJSON(jsonp_url, function(result) { $('#sm-widget-container').html(result.html); }); }); } })();