Add the Tumblr MP3 Player Asyncronously
Anyone that knows me knows that the first thing I do with new technology is figure out how to make it play music. So it makes sense that a week-or-so in to my Tumblr blog, I would create an mp3 player for it. So here is my first stab at it. You can see it in action at the bottom of this blog.
Love this mp3 player widget but I do not love javascripts that slow down page load. I hacked this script (by modifying the bookmarklet version that dankantor also posted) and inserting it with a body onload javascript event. The result, your tumblog loads fast and the streampad player loads afterwards. Here’s what you need in your template to make this work:
<script type="text/javascript" charset="utf-8">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() { oldonload(); func(); }
}
}
addLoadEvent(function(){
/* streampad */
var s=document.createElement("script");
s.src="http://static.streampad.com/streampad-tumblr.js?ref=kortina";
s.onload=function(){ streampadPlayer.init() };
document.body.appendChild(s);
});
</script>
Enjoy!
