/
github-badge-launcher.js
55 lines (47 loc) · 1.88 KB
/
github-badge-launcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var GitHubBadge = GitHubBadge || {};
GitHubBadge.Launcher = new function() {
var filename = "github-badge-launcher"; // without .js
function requestContent( url, callback ) {
// inserting via DOM fails in Safari 2.0, so brute force approach
onLoadStr = (typeof callback == "undefined") ? "" : 'onload="' + callback + '()"';
document.write('<script ' + onLoadStr + 'type="text/javascript" src="'+url+'"></script>');
}
function basePath() {
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(\?.*)?/)) {
return scripts[i].src.replace(/github-badge-launcher\.js(\?.*)?/, '');
}
}
}
this.init = function() {
var libraries = [
[typeof jQuery, "ext/jquery"],
// ["undefined", "ext/jquery"],
[typeof jQuery != "undefined" && typeof jQuery.template, "ext/jquery.template"]
];
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(\?.*)?/)) {
var 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 = path + libraries[i][1] + ".js";
if (i == libraries.length - 1) {
requestContent(url, "GitHubBadge.Launcher.loadedLibraries");
} else {
requestContent(url);
}
}
}
break;
}
}
}
this.loadedLibraries = function() {
if(typeof jQuery == 'undefined' || typeof jQuery.template == 'undefined')
throw("GitHub Badge requires jQuery and jQuery.template");
GitHubBadge.buildUserBadge();
}
}
GitHubBadge.Launcher.init();