This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
/
All_Samples.js
342 lines (275 loc) · 8.43 KB
/
All_Samples.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
/* Code here should be shared with All_Repos2.js and All_Repos.js */
// Utility function to shorten those very long repo names
function shortName(name) {
if (name.length > 14) {
return name.slice(0, 7) + '...' + name.slice(-7);
}
return name;
}
// Companion annotation for hyperlinks
function explainShortName(name) {
if (name.length > 14) {
return " title='"+name+"' ";
}
return '';
}
// add new widget called repeatHeaders
$.tablesorter.addWidget({
// give the widget a id
id: "repeatHeaders",
// format is called when the on init and when a sorting has finished
format: function(table) {
// This should be changed to cache the headers based on the table object
// because we are sorting multiple tables.
// Invalidating the cache will work for now
// invalidate the cache
this.headers = null;
// cache and collect all TH headers
if(!this.headers) {
var h = this.headers = [];
$("thead th",table).each(function() {
h.push(
"<th>" + $(this).text() + "</th>"
);
});
}
// remove appended headers by classname.
$("tr.repeated-header",table).remove();
// loop all tr elements and insert a copy of the "headers"
for(var i=0; i < table.tBodies[0].rows.length; i++) {
// insert a copy of the table head every 10th row
if((i%20) == 19) {
$("tbody tr:eq(" + i + ")",table).before(
$("<tr></tr>").addClass("repeated-header").html(this.headers.join(""))
);
}
}
}
});
/*
* parseRepoData()
*
* data - from JASON parse
* tagSet - map of tags used in the samples, if null, skip
*
* showTypeColumn - platform type
* showBB10Column - tested / ported to bb10
* showNativeColumn - BB10, PlayBook, Cascades
* showTagsData
* -- only one of showNativeColumn and showBB10Column can be true
*
* typeTag - "html5", "native", "otherclient", "other"
*
* return - items
*
* Note: Should rewrite with callback funtions on columns and tags
*/
function parseRepoData(data,
tagSet,
showTypeColumn,
showBB10Column, showNativeColumn,
showTagsData,
typeTag) {
var items = [];
if ( showBB10Column && showNativeColumn ) {
alert ("argh!"); // remove and leave below
showBB10Column = false; // force it
}
/* total hack on the overlap; need to fix */
items.push('<thead>' +
'<tr>' +
'<th>Sample</th>' +
'<th>Description</th>' +
'<th>Repository</th>' +
( showBB10Column ? '<th>BB10</th>' : '' ) +
( showNativeColumn ? '<th>Native</th>' : '' ) +
( showTypeColumn ? '<th>Type</th>' : '' ) +
'</tr>' +
'</thead>')
$.each(data, function(key, val) {
/* The "_comment_" record is used to document the JSON format */
if ( key === "_comment_" ) {
return true; /* skip this item */
}
/* special tags */
var isHtml5 = ($.inArray("html5", val.tags) >= 0);
var isNative = ($.inArray("native", val.tags) >= 0);
var isClient = ($.inArray("client", val.tags) >= 0);
var isCascades = ($.inArray("cascades", val.tags) >= 0);
var isBB10 = ($.inArray("bb10", val.tags) >= 0);
var isPlayBook = ($.inArray("playbook", val.tags) >= 0);
if ( (typeTag === "html5") && (! isHtml5) ) {
return true; /* skip this item */
}
if ( (typeTag === "native") && (! isNative) ) {
return true; /* skip this item */
}
if ( (typeTag == "otherclient") &&
((! isClient) || isHtml5 || isNative)) {
return true; /* skip this item */
}
if ( (typeTag === "other") &&
(isClient || isHtml5 || isNative)) {
return true; /* skip this item */
}
items.push('<tr>' +
/* Start Row */
/* Repository */
'<td>'+
'<span style="white-space: nowrap;">' +
'<a href="' + val.url + '" target="_blank">' + key + '</a>' +
'</span>' +
'</td>' +
/* Description */
'<td>' + val.desc +
( showTagsData
? ' <span class="question" left="yes" tip="' + val.tags.join(", ") + '">T</span>'
: ''
) +
( ( val.note )
? ' <span class="question" tip="' + val.note + '">?</span>'
: ''
) +
( ( val.warning )
? ' <span class="warning" tip="' + val.warning + '">!</span>'
: ''
) +
'</td>' +
/* Repository */
'<td>' +
'<span style="white-space: nowrap;">' +
( ' <a href="' + val.repourl + '"' +
explainShortName(val.repo) + '>' +
shortName(val.repo) + '</a>'
) +
'</span>' +
'</td>' +
/* Type */
( showTypeColumn
? '<td class="centered">' + val.type + '</td>'
: '' ) +
/* BB10 */
( showBB10Column
? ( '<td class="centered">' +
( isBB10
? '✓'
: ( isPlayBook
? '<span class="question" left="yes" tip="Tested on PlayBook, not yet on BB10">?</span>'
: '')) +
'</td>')
: '' ) +
/* Native */
( showNativeColumn
? ( '<td class="centered">' +
( isCascades ? 'cascades'
: ( isBB10 ? 'bb10'
: ( isPlayBook ? 'pb'
: '' ))) +
'</td>' )
: '' ) +
'</tr>');
});
return items;
}
$(document).ready(function(){
$.getJSON('/Community/All_Samples.json', function(data) {
/* ================= */
/* Process the tags */
allTags = new Object();
/* Collect tags */
$.each(data, function(key, val) {
/* The "_comment_" record is used to document the JSON format */
if ( key === "_comment_" ) {
return true; /* skip this item */
}
/* add all val.tags to tagSet */
$.each(val.tags, function(key,data) {
allTags[data] = true;
});
});
/* Insert tags */
items = [];
$.each(allTags, function (key, val) {
items.push('<em>' + key + '</em>');
});
/* Sort */
items.sort();
/* Inject */
$('#tagsList').append($('<p/>', {
html: items.join(', ')
})).addClass("taglist"); /* TODO: add style for taglist */
/* ====================== */
/* Table of HTML5 Samples */
/* Parse JSON data into items
* showTypeColumn, showBB10Column, showNativeColumn, showTagsData, typeTag */
items = parseRepoData(data, allTags, false, true, false, true, "html5");
if (items.length > 1) {
/* Inject into page */
$('<table/>', {
'id': 'samplesHtml5Table',
html: items.join('')
}).appendTo('#samplesHtml5').addClass("tablesorter");
$("#samplesHtml5Table").tablesorter({
widgets: ['zebra', 'repeatHeaders'] // Stripping looking
});
}
/* Table of Native Samples */
/* Parse JSON data into items
* showTypeColumn, showBB10Column, showNativeColumn, showTagsData, typeTag */
items = parseRepoData(data, allTags, false, false, true, true, "native");
if (items.length > 1) {
/* Inject into page */
$('<table/>', {
'id': 'samplesNativeTable',
html: items.join('')
}).appendTo('#samplesNative').addClass("tablesorter");
$("#samplesNativeTable").tablesorter({
widgets: ['zebra', 'repeatHeaders'] // Stripping looking
});
}
/* Table of Other Client Samples */
/* Parse JSON data into items
* showTypeColumn, showBB10Column, showNativeColumn, showTagsData, typeTag */
items = parseRepoData(data, allTags, false, true, false, true, "otherclient");
if (items.length > 1) {
/* Inject into page */
$('<table/>', {
'id': 'samplesOtherClientTable',
html: items.join('')
}).appendTo('#samplesOtherClient').addClass("tablesorter");
$("#samplesOtherClientTable").tablesorter({
widgets: ['zebra', 'repeatHeaders'] // Stripping looking
});
}
/* Table of Other Samples */
/* Parse JSON data into items
* showTypeColumn, showBB10Column, showNativeColumn, showTagsData, typeTag */
items = parseRepoData(data, allTags, false, false, false, true, "other");
if (items.length > 1) {
/* Inject into page */
$('<table/>', {
'id': 'samplesOtherTable',
html: items.join('')
}).appendTo('#samplesOther').addClass("tablesorter");
$("#samplesOtherTable").tablesorter({
widgets: ['zebra', 'repeatHeaders'] // Stripping looking
});
}
/* ========= */
/* Add the tooltips */
$("span.question, span.warning").hover(function() {
if ($(this).attr("left")=="yes") {
$(this).append('<div class="tooltipLeft"><p>' +
$(this).attr("tip") +
'</p></div>');
} else {
$(this).append('<div class="tooltip"><p>' +
$(this).attr("tip") +
'</p></div>');
}
}, function () {
$("div.tooltip").remove();
$("div.tooltipLeft").remove();
});
});
});