Created
December 11, 2012 11:15
-
-
Save orng/4257861 to your computer and use it in GitHub Desktop.
jquery box2d bookmarklet helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://raw.github.com/gist/4257861/bf99710923dc4512338a9f193e05ff9928b0593b/jqb2d.js';})();