Permalink
Browse files

if jquery is already installed the badge now works (was using the wro…

…ng $.getScript call for a callback)
  • Loading branch information...
1 parent 5a4183c commit a7010d93aa554a98103fa68bbef79e388b8d497a @drnic committed Mar 3, 2010
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/github-badge-launcher.js
@@ -26,15 +26,17 @@ GitHubBadge.Launcher = new function() {
var libraries = [
[typeof jQuery, "ext/jquery"],
[typeof jQuery != "undefined" && typeof jQuery.template, "ext/jquery.template"],
- [false, "github-badge"]
+ [typeof GitHubBadge.loadUserInfo, "github-badge"]
];
var scripts = document.getElementsByTagName("script");
for (var i=0; i < scripts.length; i++) {
if (scripts[i].src && scripts[i].src.match(/github-badge-launcher\.js(\?.*)?/)) {
this.path = scripts[i].src.replace(/github-badge-launcher\.js(\?.*)?/, '');
for (var i=0; i < libraries.length; i++) {
- if (libraries[i][0] == "undefined" || !libraries[i][0]) {
- var url = this.path + libraries[i][1] + ".js";
+ var libraryInstalled = libraries[i][0];
+ var relativeLibraryPath = libraries[i][1];
+ if (libraryInstalled == "undefined" || !libraryInstalled) {
+ var url = this.path + relativeLibraryPath + ".js";
if (i == libraries.length - 1) {
this.requestContent(url, "GitHubBadge.Launcher.loadedLibraries");
} else {
@@ -64,10 +66,17 @@ GitHubBadge.Launcher = new function() {
GitHubBadge.Launcher.requestContent = function( url, callback ) {
// inserting via DOM fails in Safari 2.0, so brute force approach
- if ("jQuery" in window) {
- jQuery.getScript(url,callback);
+ if ("jQuery" in window && url.match(/^http/)) {
+ if (typeof callback != "undefined") {
+ // console.debug("jQuery.getScript('" + url + "', '" + callback + "');");
+ jQuery.getScript(url,function() { eval(callback + "()") });
+ } else {
+ // console.debug("jQuery.getScript('" + url + "');");
+ jQuery.getScript(url);
+ }
} else {
- onLoadStr = (typeof callback == "undefined") ? "" : 'onload="' + callback + '()"';
+ onLoadStr = (typeof callback == "undefined") ? "" : 'onload="' + callback + '()" ';
+ // console.debug('<script ' + onLoadStr + 'type="text/javascript" src="'+url+'"></script>');
document.write('<script ' + onLoadStr + 'type="text/javascript" src="'+url+'"></script>');
}
}

0 comments on commit a7010d9

Please sign in to comment.