forked from astropy/astropy.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
executable file
·435 lines (357 loc) · 14.4 KB
/
functions.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
$( document ).ready(function(){
$('#responsive-menu-button').sidr({
name: 'sidr-main',
source: '#navigation'
});
$("div#documentation span").click(function() { //When trigger is clicked...
$("div#documentation ul").slideDown('fast').show(); //Drop down the subnav on click
$(this).parent().hover(function() {
}, function(){
$(this).parent().find("ul").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
});
//Following events are applied to the trigger (Hover events for the trigger)
}).hover(function() {
$(this).addClass("subhover"); //On hover over, add class "subhover"
}, function(){ //On Hover Out
$(this).removeClass("subhover"); //On hover out, remove class "subhover"
});
//creating Astropy roles table & roles lists using roles.json
var request = new XMLHttpRequest();
var dataURL = "roles.json";
request.open('GET', dataURL);
request.responseType = 'json';
request.send();
//log error when request gets failed
request.onerror = function () {
console.log("XHR error");
};
request.onload = function () {
//received json data via XHR
var data = request.response;
//creating roles table from json data
createRolesTable(data);
//creating roles lists from json data
createRolesDescription(data);
};
function createRolesTable(roles) {
//roles is an array of objects called "role"
var rows = '';
roles.forEach(function (role) {
//role is an object containing information about each team role
//index marks current people
var index = 0;
// for roles where there are no sub-roles, the people are defined
// at the top-level of the JSON role dict - for convenience below we create
// a virtual sub-role with no heading
if (!('sub-roles' in role)) {
role['sub-roles'] = [{'role': '',
'people': role['people']}];
}
//creating each row by iterating over each person in a role
role["sub-roles"].forEach(function (subrole) {
//rowRole is displayed once for each role
rowRole = index == 0 ? '<a href="#' + role["url"] + '">' + role["role"] + '</a>' : "";
var rowSubRole = subrole['role'];
if (subrole['people'][0] == "Unfilled") {
rowPeople = '<a href="mailto:[email protected]"><span style="font-style: italic;">Unfilled</span></a>';
} else {
rowPeople = subrole['people'].join(', ');
}
//generating rows
if (index == 0) {
rows += '<tr class="border-top">';
} else {
rows += '<tr>';
}
rows += '<td>' + rowRole + '</td>' +
'<td>' + rowSubRole + '</td>' +
'<td>' + rowPeople + '</td>' +
'</tr>';
index++;
});
});
$("#roles-table").append(rows);
}
function createRolesDescription(roles) {
//roles is an array of objects called "role"
var blocks = "";
roles.forEach(function (role) {
//role is an object containing information about each team role
var list = "";
//checking if role["description"] array isn't empty
if (role["responsibilities"] != null) {
// If responsibilities is a dict, wrap inside a list so that all entries have a list
// dicts
if (role['responsibilities'].constructor == Object) {
role['responsibilities'] = [role['responsibilities']];
}
console.log(role['responsibilities']);
blocks += '<br/>' +
'<h3 id="' + role["url"] + '">' + role["role-head"] + '</h3>';
index = 0;
role['responsibilities'].forEach(function (resp) {
console.log(resp);
detail_list = '';
resp["details"].forEach(function (detail) {
detail_list += '<li>' + detail + '</li>';
});
if ('subrole-head' in resp) {
if (index > 0) {
blocks += '<br>';
}
blocks += '<strong>' + resp["subrole-head"] + '</strong>';
}
blocks += '<p>' + resp["description"] + '</p>' +
'<ul>' + detail_list + '</ul>';
index += 1;
})
}
});
$("#roles-description").append(blocks);
}
$('#os-selector ul').each(function(){
// For each set of tabs, we want to keep track of
// which tab is active and it's associated content
var hash, $active, $content, $links = $(this).find('a');
// If the location.hash matches one of the links, use that as the active tab.
// If no location.hash is given, use a tab determined by guess_os()
// If no match is found, use the first link as the initial active tab.
hash = (location.hash === "") ? '#' + guess_os() : location.hash;
$active = $($links.filter('[href="'+hash+'"]')[0] || $links[0]);
$active.addClass('active');
$content = $($active.attr('href'));
// Hide the remaining content
$links.not($active).each(function () {
$($(this).attr('href')).hide();
});
// Bind the click event handler
$(this).on('click', 'a', function(e){
// Make the old tab inactive.
$active.removeClass('active');
$content.hide();
// Update the variables with the new link and content
$active = $(this);
$content = $($(this).attr('href'));
// Make the tab active.
$active.addClass('active');
$content.show();
// Prevent the anchor's default click action
e.preventDefault();
});
// Now go through and find any links that are *not* in the above list
// but should point to a tab.
$('a').each(function(){
//For every link check if it matches one of the tabs.
//If so, replace with "clicking" on the tab.
var $curra = $(this);
var currhref = $curra.attr('href');
$links.each(function() {
var $currlia = $(this);
if ((currhref == $currlia.attr('href'))) {
//Don't press the tab itself, that's above
if (! $curra.is($currlia)) {
$curra.on('click', function(e){
//act like we clicked on the tab itself instead of this link
$currlia.click();
// We let the default through here, because
// you probably want to jump to the revealed tab
e.preventDefault();
});
}
}
});
});
});
// makes permalink visible only when user moves cursor on headline, otherwise hidden
$("h1").hover(function() {
$(this).children("a").css("visibility", "visible");
}, function() {
$(this).children("a").css("visibility", "hidden");
});
$("h2").hover(function() {
$(this).children("a").css("visibility", "visible");
}, function() {
$(this).children("a").css("visibility", "hidden");
});
$("h3").hover(function() {
$(this).children("a").css("visibility", "visible");
}, function() {
$(this).children("a").css("visibility", "hidden");
});
}); // Document Ready
//Using jQuery is ok because it is needed by and bundled with sphinx
//Quirk to note: the jQuery.getJSON function fails if you open this locally
//with Chrome, because Chrome thinks local JSON files are unsafe for some
//reason. Use basically any other modern browser, or it works fine if its
//actually on the web server even with chrome.
function url_translator(urltext) {
if (urltext === undefined) {
return 'None';
} else {
return '<a href="' + urltext + '">' + 'Website' + '</a>';
}
}
function repo_translator(urltext) {
if (urltext === undefined) {
return 'None';
} else {
return '<a href="' + urltext + '">' + 'Repository' + '</a>';
}
}
function pypi_translator(pypiname) {
if (pypiname === undefined) {
return 'None';
} else {
var urltext = 'https://pypi.python.org/pypi/' + pypiname;
return '<a href="' + urltext + '">' + 'PyPI' + '</a>';
}
}
function bool_translator(stable) {
if (stable) {
return 'Yes';
} else {
return 'No';
}
}
function ghuser_translator(fullname, ghname) {
if (fullname === undefined || ghname === undefined) {
return 'None';
} else {
var urltext = 'https://github.com/' + ghname;
return '<a href="' + urltext + '">' + fullname + '</a>';
}
}
var _email_regex_str = '[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}';
var _email_regex = new RegExp(_email_regex_str, 'i');
var _email_with_name_regex = new RegExp('(.+)<(' + _email_regex_str + ')>', 'i');
function maintainer_translator(maint, pkgnm) {
var url, match;
if (_email_with_name_regex.test(maint)) {
match = _email_with_name_regex.exec(maint);
url = 'mailto:' + match[2] + '?subject=Astropy%20affiliated%20package%20' + pkgnm;
return '<a href="' + url + '">' + match[1] + '</a>';
} else if (_email_regex.test(maint)) {
url = 'mailto:' + maint + '?subject=Astropy%20affiliated%20package%20' + pkgnm;
return '<a href="' + url + '">' + maint + '</a>';
} else {
return maint;
}
}
function populateTables(data, tstat, xhr) {
populatePackageTable('coordinated', filter_pkg_data(data, "coordinated", true));
populatePackageTable('affiliated', filter_pkg_data(data, "coordinated", false));
}
function filter_pkg_data(data, field, value) {
if (data === null) {
return null;
}
var pkgs = data.packages;
var filtered_data = [];
for (i=0; i<pkgs.length; i++) {
if (pkgs[i][field] == value) {
filtered_data.push(pkgs[i]);
}
}
return {'packages': filtered_data};
}
function populatePackageTable(tableid, data) {
// Now we get the table and prepare it
var tab = document.getElementById(tableid + "-package-table");
var ncols = tab.rows[0].cells.length;
//we have to delete the "Loading..." row
tab.deleteRow(1);
if (data === null) {
var row = tab.insertRow(1);
row.insertCell(0).innerHTML = 'Could not load registry file!';
for (i=0;i<(ncols - 1);i++) { row.insertCell(i + 1).innerHTML = ' '; }
} else {
var pkgs = data.packages;
//inserting total number of affiliated packages at top of table
$("#total-" + tableid + "-pkgs").text(pkgs.length);
//First figure out the correct order if we sort on the name
var nmarr = new Array(pkgs.length);
var sortorder = new Array(pkgs.length);
for (i=0; i<pkgs.length; i++) {
pkgi = pkgs[i];
nmarr[i] = pkgi.name.toLowerCase();
sortorder[i] = i;
}
// This "sorts" the indicies using a compare function that actually sorts nmarr
sortorder.sort(function (a, b) { return nmarr[a] < nmarr[b] ? -1 : nmarr[a] > nmarr[b] ? 1 : 0; });
var pkgi;
var namerow, descrow, shieldrow, maintrow;
var nmcell, pypicell, urlcell, repocell;
var desccell, maintcell, shieldcell;
for (i=0; i<sortorder.length; i++) {
pkgi = pkgs[sortorder[i]];
namerow = tab.insertRow(i*4 + 1);
nmcell = namerow.insertCell(0);
urlcell = namerow.insertCell(1);
repocell = namerow.insertCell(2);
pypicell = namerow.insertCell(3);
nmcell.innerHTML = pkgi.name;
nmcell.className = 'first-package-row'
nmcell.setAttribute('width', 100)
urlcell.innerHTML = url_translator(pkgi.home_url);
repocell.innerHTML = repo_translator(pkgi.repo_url);
pypicell.innerHTML = pypi_translator(pkgi.pypi_name);
descrow = tab.insertRow(i*4 + 2);
descrow.insertCell(0).innerHTML = "";
desccell = descrow.insertCell(1);
desccell.colSpan = "3";
desccell.innerHTML = pkgi.description;
maintrow = tab.insertRow(i*4 + 3);
maintrow.insertCell(0).innerHTML = "";
maintcell = maintrow.insertCell(1);
maintcell.colSpan = "3";
maintcell.innerHTML = "Maintainer(s): " + maintainer_translator(pkgi.maintainer, pkgi.name);
shieldrow = tab.insertRow(i*4 + 4);
shieldrow.insertCell(0).innerHTML = "";
shieldcell = shieldrow.insertCell(1);
shieldcell.colSpan = "3";
shieldcell.innerHTML = makeShields(pkgi)
}
}
}
var review_name_map = {"functionality": "Functionality",
"ecointegration": "Astropy%20integration",
"documentation": "Docs",
"testing": "Tests",
"devstatus": "Development",
"python3": "Python 3"
};
var review_default_color = "brightgreen";
var review_color_map = {'Unmaintained': "red",
"Functional but low activity": "orange",
"Good": "brightgreen",
"Partial": "orange",
"No": "orange",
"Needs work": "red"
};
function makeShields(pkg) {
var shield_string = "";
var key, shield_name, pkgvalue, color, url;
for (key in review_name_map) {
console.log("K"+key);
if (review_name_map.hasOwnProperty(key)) {
shield_name = review_name_map[key];
if ("review" in pkg && key in pkg.review ) {
pkgvalue = pkg.review[key];
color = review_color_map[pkgvalue];
if (typeof color == 'undefined') {
color = review_default_color;
}
url = "https://img.shields.io/badge/" + shield_name + "-" + pkgvalue + "-" + color + ".svg";
shield_string += "<img src=\"" + url + "\">" + " "
}
}
}
return shield_string
}
function guess_os() {
var OSName="source";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="osx";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="linux";
return OSName;
}