forked from potomak/jquery-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.github.js
77 lines (65 loc) · 1.92 KB
/
jquery.github.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
(function($){
$.fn.github = function(options) {
var that = this,
apiEndpoint = "https://api.github.com",
settings = {
organization: null
, onLoad: null
, onComplete: function(response) {
var length = typeof response.data != 'undefined' ? response.data.length : 0;
if(length > 0) {
for(var i = 0; i < length; i++) {
this.append(createMemberElement(response.data[i]));
}
}
else {
this.append(createEmptyElement());
}
}
};
options && $.extend(settings, options);
function createMemberElement(member) {
return $('<div>')
.addClass('github-member')
.attr('id', member.id)
.append(
$('<a>')
.attr('href', member.url)
.append(
$('<img>')
.addClass('github-member-avatar')
.attr('src', member.avatar_url)
)
);
}
function createEmptyElement() {
return $('<div>')
.addClass('github-member')
.attr('id', 'empty')
.html('No members for this organization');
}
function composeRequestURL() {
var url = apiEndpoint,
params = {};
if(settings.organization != null) {
url += "/orgs/" + settings.organization + "/members";
}
url += "?" + $.param(params)
return url;
}
function runIfNotNull(f, o, args) {
f != null && typeof f == 'function' && f.apply(o, args);
}
runIfNotNull(settings.onLoad, this, []);
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: composeRequestURL(),
success: function(response) {
settings.onComplete.apply(that, [response]);
}
});
return this;
};
})(jQuery);