Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Created December 14, 2012 23:07
Show Gist options
  • Save blackrobot/4289439 to your computer and use it in GitHub Desktop.
Save blackrobot/4289439 to your computer and use it in GitHub Desktop.
(function() {
var jQuery = window.jQuery,
frag = document.createDocumentFragment(),
js = document.createElement('script'),
css = document.createElement('link'),
head = document.getElementsByTagName('head');
if (jQuery === undefined || jQuery.fn.jquery !== '1.8.2') {
jq = document.createElement('script');
jq.href = "//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js";
jq.type = "text/javascript";
jq.onload = function() {
jQuery = window.jQuery.noconflict(true);
};
frag.appendChild(jq);
}
js.async = js.src = "//mysite.com/the-other-script.js";
js.type = "text/javascript";
js.onload = function() {
/* Call your init function with our jQuery variable. */
window.MyWidget(jQuery);
};
css.href = "//mysite.com/my-css-file.css";
css.type = "text/css";
css.rel = "stylesheet";
frag.appendChild(js);
frag.appendChild(css);
head.appendChild(frag);
}());
document.write('<div id="the-widget-container" style="display:none"><!-- all your other stuff here? --></div>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment