-
Notifications
You must be signed in to change notification settings - Fork 43
/
widget.js
105 lines (105 loc) · 2.79 KB
/
widget.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(function(e) {
var t = "//lab.lepture.com/github-cards/";
var r, i = 0;
var a = e.getElementsByTagName("meta");
var n, l, c, d;
for (r = 0; r < a.length; r++) {
var u = a[r].getAttribute("name");
var f = a[r].getAttribute("content");
if (u === "gc:url") {
n = f
} else if (u === "gc:base") {
t = f
} else if (u === "gc:client-id") {
l = f
} else if (u === "gc:client-secret") {
c = f
} else if (u === "gc:theme") {
d = f
}
}
function s(t) {
if (e.querySelectorAll) {
return e.querySelectorAll("." + t)
}
var i = e.getElementsByTagName("div");
var a = [];
for (r = 0; r < i.length; r++) {
if (~i[r].className.split(" ").indexOf(t)) {
a.push(i[r])
}
}
return a
}
function g(e, t) {
return e.getAttribute("data-" + t)
}
function h(e) {
if (window.addEventListener) {
window.addEventListener("message",
function(t) {
if (e.id === t.data.sender) {
e.height = t.data.height
}
},
false)
}
}
function o(r, a) {
a = a || n;
if (!a) {
var u = g(r, "theme") || d || "default";
a = t + "cards/" + u + ".html"
}
var f = g(r, "user");
var s = g(r, "repo");
var o = g(r, "github");
if (o) {
o = o.split("/");
if (o.length && !f) {
f = o[0];
s = s || o[1]
}
}
if (!f) {
return
}
i += 1;
var v = g(r, "width");
var m = g(r, "height");
var b = g(r, "target");
var w = g(r, "client-id") || l;
var p = g(r, "client-secret") || c;
var A = "ghcard-" + f + "-" + i;
var y = e.createElement("iframe");
y.setAttribute("id", A);
y.setAttribute("frameborder", 0);
y.setAttribute("scrolling", 0);
y.setAttribute("allowtransparency", true);
var E = a + "?user=" + f + "&identity=" + A;
if (s) {
E += "&repo=" + s
}
if (b) {
E += "&target=" + b
}
if (w && p) {
E += "&client_id=" + w + "&client_secret=" + p
}
y.src = E;
y.width = v || Math.min(r.parentNode.clientWidth || 400, 400);
if (m) {
y.height = m
}
h(y);
r.parentNode.replaceChild(y, r);
return y
}
var v = s("github-card");
for (r = 0; r < v.length; r++) {
o(v[r])
}
if (window.githubCard) {
window.githubCard.render = o
}
})(document);