-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathdemo.js
198 lines (160 loc) · 6.55 KB
/
demo.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
document.addEventListener('DOMContentLoaded', function () {
/* Navbar scroll to that perticular section of page */
$('.navbar a').on('click', function(e){
if(this.hash !== ''){
e.preventDefault();
const hash = this.hash;
$('html,body').animate({
scrollTop: $(hash).offset().top
},800);
}
});
/* language section */
var request = new XMLHttpRequest()
request.open('GET', 'https://api.github.com/users/publiclab/repos', true);
request.onload = function () {
var data = JSON.parse(this.response);
var statusHTML = '';
$.each(data, function (i, status) {
statusHTML += '<div class="conatiner-language">';
statusHTML += '<div class="repo-name"><a href="' + status.html_url + '">' + status.name + '</a></div>';
if(status.language == null){
statusHTML += '<span class="badge">' + 'N/A' + '</span>';
}else{
statusHTML += '<span class="badge">' + status.language + '</span>';
}
statusHTML += '</div>';
});
$('#tbody').html(statusHTML);
}
request.send();
/* langauge section ends */
/*Scroll to top when arrow up clicked BEGIN*/
$(window).scroll(function() {
// Setting for back to top button
let height = $(window).scrollTop();
if (height > 100) {
$('#back2Top').fadeIn();
} else {
$('#back2Top').fadeOut();
}
});
$("#back2Top").click(function(event) {
event.preventDefault();
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
$('.stale').hover((e) => {
e.preventDefault();
let height = $('.stale').prop("scrollHeight")
let top = $('.stale').prop("scrollTop")
if(top==0) {
$('.stale').animate({ scrollTop: height*0.05 }, 'slow')
}
}, (e) => {
e.preventDefault();
})
let toolbox;
(function() {
let org = urlHash().getUrlHashParameter('o') || 'publiclab';
let repo = urlHash().getUrlHashParameter('r') || 'plots2';
let ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only';
let candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate';
let recencyLabel = urlHash().getUrlHashParameter('l') || 'week';
let leaderboardState = urlHash().getUrlHashParameter('s') || 'week';
toolbox = CommunityToolbox(org, repo);
if (repo === 'all') {
toolbox.getIssuesForOrg(org, { qs: { labels: ftoLabel } })
.then(displayIssuesAndFtoAuthors('.first-timers-only'));
toolbox.getIssuesForOrg(org, { qs: { labels: candidateLabel } })
.then(displayIssuesAndFtoAuthors('.candidates'));
toolbox.initialize(org, repo).then((res)=> {
if(res) {
// Fetches and shows recent contributors' list
toolbox.showRecentContributors(org, repo, recencyLabel);
// compile and display all contributors for given org
toolbox.showAllContributors(org, repo);
toolbox.dropdownInit();
// Fetch stale issues
toolbox.showStaleIssues(org, repo);
}
})
} else {
toolbox.api.Issues
.getIssuesForRepo(org, repo, { qs: { labels: ftoLabel } })
.then(displayIssuesAndFtoAuthors('.first-timers-only'));
toolbox.api.Issues
.getIssuesForRepo(org, repo, { qs: { labels: candidateLabel } })
.then(displayIssuesAndFtoAuthors('.candidates'));
toolbox.initialize(org, repo).then((res)=> {
if(res) {
// Fetches and shows recent contributors' list
toolbox.showRecentContributors(org, repo, recencyLabel);
// compile and display all contributors for given repo
toolbox.showRepoContributors(org, repo);
toolbox.dropdownInit();
// Fetch stale issues
toolbox.showStaleIssues(org, repo);
}
})
}
function displayIssuesAndFtoAuthors(selector) {
let ftoAuthorSet = new Set([]);
let ftoAuthArray=[];
return function displayIssuesAndFtoAuthors(issues) {
if (typeof issues === "string") issues = JSON.parse(issues).items;
issues.forEach(function(issue) {
toolbox.issuesUI.insertIssue(issue, selector);
issue.labels.forEach((ftoLabel) => {
if(ftoLabel.name==="first-timers-only" || ftoLabel.name==="fto") {
if(!ftoAuthorSet.has(issue.user.login)) {
ftoAuthorSet.add(issue.user.login);
ftoAuthArray.push(issue);
}
}
})
})
toolbox.ftoAuthorsUI.insertFtoIssueAuthor(ftoAuthArray);
}
}
// EVENT LISTENERS FOR FILTER IN RECENT CONTRIBUTORS SECTION
$('#alphabetic').click((e)=> {
e.preventDefault();
toolbox.filter(org, 'alphabetic');
})
$('#mostrecentfirst').click((e)=> {
e.preventDefault();
toolbox.filter(org, 'mostrecentfirst');
})
$('#leaderboard').click((e)=> {
e.preventDefault();
toolbox.filter(org, 'leaderboard');
})
$(".past").click((e) => {
e.preventDefault();
let timeSpan = e.target.textContent;
$('#dropdownMenuButtonRCS > #content').html(timeSpan);
let forMonths = 6;
if(timeSpan.includes('Week')) {
timeSpan = 'week';
}else {
let mid = timeSpan.split('Last ')[1].split(' ')[0];
timeSpan = 'month';
forMonths = mid;
}
toolbox.showRecentContributors(org, repo, timeSpan, forMonths);
})
$('#refresh-button').click((e) => {
e.preventDefault();
toolbox.clearDB().then((isDBRefreshed) => {
if(isDBRefreshed) {
location.reload();
}
})
})
$('.org-wide-issues').on('click', ()=>{
location.href = $('.org-wide-issues').attr("href")
location.reload();
})
})();
})