Created
July 30, 2010 03:46
-
-
Save rwaldron/499852 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Badges</title> | |
</head> | |
<body> | |
<script src="badge.js?type=jedi"></script> | |
<script src="badge.js?type=ninja"></script> | |
<script> | |
console.log(twitBadges); | |
</script> | |
</body> | |
</html> |
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
;(function(window) { | |
window.twitBadges = window['twitBadges'] ? window.twitBadges : { 'length': 0 }; | |
if(!("jQuery" in window)) { | |
var head = document.getElementsByTagName('head')[0], | |
script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'; | |
script.onload = start; | |
head.appendChild(script); | |
} else { | |
start(); | |
} | |
var js = /badge\.js(\?.*)?$/, | |
id = twitBadges['length'], | |
wgdt; | |
document.write('<div class="twtpic-widget"></div>'); | |
function start() { | |
wdgt = new TwitPic_Widget(); | |
$('script[src]').each(function (i,src) { | |
var $attr = $(src).attr('src'), | |
incs = $attr.match(/\?.*type=([a-z]*)/); | |
if ( incs && incs.length === 2 && !twitBadges[incs[1]] ) { | |
twitBadges[incs[1]] = wdgt; | |
twitBadges['length']++; | |
$('.twtpic-widget').attr({ | |
id: function (i) { return i; } | |
}) | |
} | |
}); | |
} | |
function TwitPic_Widget() { | |
this.id = id; | |
this.div_id = '#twtpic-wdgt-' + twitBadges['length']; | |
this.init(); | |
} | |
TwitPic_Widget.prototype.init = function() { | |
this.inject_css(); | |
this.build_widget(); | |
} | |
TwitPic_Widget.prototype.inject_css = function() { | |
$('head').append(this.CSS); | |
} | |
TwitPic_Widget.prototype.build_widget = function() { | |
$(this.div_id).html(this.HTML); | |
} | |
TwitPic_Widget.prototype.HTML = ""; | |
TwitPic_Widget.prototype.CSS = ""; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment