Skip to content

Instantly share code, notes, and snippets.

@orng
Created December 11, 2012 11:15
Show Gist options
  • Save orng/4257861 to your computer and use it in GitHub Desktop.
Save orng/4257861 to your computer and use it in GitHub Desktop.
jquery box2d bookmarklet helper
//Code by Örn Guðjónsson
// with a lot of help from Vincent Robert (http://stackoverflow.com/a/756526/611292)
function loadScript(url, callback)
{
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
// Attach handlers for all browsers
var done = false;
script.onload = script.onreadystatechange = function()
{
if( !done && ( !this.readyState
|| this.readyState == "loaded"
|| this.readyState == "complete") )
{
done = true;
// Continue your code
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
head.removeChild( script );
}
};
head.appendChild(script);
}
// Usage:
// This code loads jQuery and executes some code when jQuery is loaded
loadScript("http://code.jquery.com/jquery-latest.js", function()
{
loadScript("http://www.fullstackoptimization.com/box2d-jquery/js/lib/jquery.box2d.min.js", function()
{
$(document).ready(function(){
$('h1, div, img').box2d({'y-velocity':5});
});
});
});
@orng
Copy link
Author

orng commented Dec 11, 2012

javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://raw.github.com/gist/4257861/bf99710923dc4512338a9f193e05ff9928b0593b/jqb2d.js';})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment