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
|
var BCLSVJS = (function (window, document, docData) {
'use strict';
var title = document.getElementsByTagName('title')[0],
// data structures
classes = [],
// elements
main,
doc_body = document.getElementsByTagName('body')[0],
// functions
isDefined,
findObjectsInArray,
getSubArray,
sortArray,
createEl,
bclslog,
addHeaderContent,
addIndex,
init;
/**
* Logging function - safe for IE
* @param {string} context - description of the data
* @param {*} message - the data to be logged by the console
* @return {}
*/
bclslog = function (context, message) {
if (window['console'] && console['log']) {
console.log(context, message);
}
return;
};
/**
* tests for all the ways a variable might be undefined or not have a value
* @param {*} x the variable to test
* @return {Boolean} true if variable is defined and has a value
*/
isDefined = function (x) {
if (x !== '' && x !== null && x !== undefined && x !== NaN) {
return true;
}
return false;
};
/**
* find indexes of a set of object in array of objects
* based on some property value
* generally useful for finding several objects
*
* @param {array} targetArray - array to search
* @param {string} objProperty - object property to search
* @param {string|number} value - value of the property to search for
* @return {array} array of indexes for matching objects
*/
findObjectsInArray = function (targetArray, objProperty, value) {
var i, totalItems = targetArray.length, newArr = [];
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
newArr.push(i);
}
}
return newArr;
};
/**
* get a subset of objects in array of objects
* based on some property value
*
* @param {array} targetArray - array to search
* @param {string} objProperty - object property to search
* @param {string|number} value - value of the property to search for
* @return {array} array of objects with matching property value
*/
getSubArray = function (targetArray, objProperty, value) {
var i, totalItems = targetArray.length, idxArr = [];
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
idxArr.push(targetArray[i]);
}
}
return idxArr;
};
/**
* sort an array of objects based on an object property
* @param {array} targetArray - array to sort
* @param {string} objProperty - property whose value to sort on
* @return {array} the sorted array
*/
sortArray = function (targetArray, objProperty) {
targetArray.sort(function (a, b) {
var propA = a[objProperty].toLowerCase(), propB = b[objProperty].toLowerCase();
// sort ascending; reverse propA and propB to sort descending
if (propA < propB) {
return -1;
} else if (propA > propB) {
return 1;
}
return 0;
});
return targetArray;
};
/**
* create an element
* @param {string} type - the element type
* @param {object} attributes - attributes to add to the element
* @return {object} the HTML element
*/
createEl = function (type, attributes) {
var el;
if (isDefined(type)) {
el = document.createElement(type);
if (isDefined(attributes)) {
var attr;
for (attr in attributes) {
el.setAttribute(attr, attributes[attr]);
}
}
return el;
}
};
/**
* add the class header content
*/
addHeaderContent = function () {
var doc_body = document.getElementsByTagName('body')[0],
mainContent = createEl('div', {id: 'main'}),
topSection = createEl('section', {id: 'top', class: 'section'}),
mainLink = createEl('a', {href: '//docs.videojs.com/', style: 'float:right;font-weight:bold;margin-top:-3em;background-color:#ECEEF1;padding:2px 4px;'}),
header = createEl('h1'),
text = document.createTextNode('video.js API Documentation Index'),
topP,
topPtext,
topLink,
topLinkStrong;
// add elements
mainLink.appendChild(document.createTextNode('Documentation Home'));
topSection.appendChild(mainLink);
header.appendChild(text);
topSection.appendChild(header);
// add paragraph for videojs function
topP = createEl('p');
topPtext = document.createTextNode('If you are new to video.js, look first at ');
topP.appendChild(topPtext);
topLink = createEl('a', {href: 'video.html'});
topP.appendChild(topLink);
topPtext = document.createTextNode('videojs');
topLinkStrong = createEl('strong');
topLink.appendChild(topLinkStrong);
topLinkStrong.appendChild(topPtext);
topPtext = document.createTextNode(', which Doubles as the main function for users to create a player instance and also the main library object.');
topP.appendChild(topPtext);
topSection.appendChild(topP);
// add paragraph for the player class
topP = createEl('p');
topPtext = document.createTextNode('Next, look at the ');
topP.appendChild(topPtext);
topLink = createEl('a', {href: 'player.html'});
topP.appendChild(topLink);
topPtext = document.createTextNode('player');
topLinkStrong = createEl('strong');
topLink.appendChild(topLinkStrong);
topLinkStrong.appendChild(topPtext);
topPtext = document.createTextNode(' class. An instance of the Player class is created when any of the Video.js setup methods are used to initialize a video. The methods and events of the player object are the most commonly used for managing the player and playback.');
topP.appendChild(topPtext);
topSection.appendChild(topP);
// add the top section to the document
mainContent.appendChild(topSection);
doc_body.appendChild(mainContent);
main = document.getElementById('main');
};
/**
* add the side nav
*/
addIndex = function () {
var section = createEl('section', {id: 'index', class: 'section'}),
sectionHeader = createEl('h2'),
classlists = {},
alphaArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
firstLetter,
numberAlphaItems = 0,
itemsPerColumn,
columnDiv,
item,
indexEls = [],
indexListHolder,
indexList,
indexListHeader,
listItem,
listLink,
listText,
text,
i,
iMax,
j,
jMax,
counter = 0;
text = document.createTextNode('Index of classes');
sectionHeader.appendChild(text);
// create alpha arrays
iMax = classes.length;
for (i = 0; i < iMax; i++) {
item = classes[i];
firstLetter = item.name.charAt(0).toLowerCase();
// create alpha array if non-existent, push item
if (isDefined(classlists[firstLetter]) === false) {
classlists[firstLetter] = [];
numberAlphaItems++;
}
classlists[firstLetter].push({name: item.name, filename: item.meta.filename});
}
itemsPerColumn = Math.ceil(numberAlphaItems / 3);
bclslog('classlists', classlists);
iMax = alphaArr.length;
for (i = 0; i < iMax; i++) {
if (isDefined(classlists[alphaArr[i]])) {
indexListHolder = createEl('div');
indexListHeader = createEl('h4', {class: 'indexHeader'});
text = document.createTextNode('~' + alphaArr[i].toUpperCase() + '~');
indexListHeader.appendChild(text);
indexListHolder.appendChild(indexListHeader);
indexList = createEl('ul');
indexListHolder.appendChild(indexList);
jMax = classlists[alphaArr[i]].length;
bclslog('jMax', jMax);
for (j = 0; j < jMax; j++) {
bclslog('classlists[alphaArr[i]', classlists[alphaArr[i]]);
listItem = createEl('li');
indexList.appendChild(listItem);
listLink = createEl('a', {href: classlists[alphaArr[i]][j].filename.replace('.js', '.html')});
listItem.appendChild(listLink);
listText = document.createTextNode(classlists[alphaArr[i]][j].name);
listLink.appendChild(listText);
}
indexEls.push(indexListHolder);
}
}
section.appendChild(sectionHeader);
iMax = indexEls.length;
for (i = 0; i < iMax; i++) {
if (counter > itemsPerColumn) {
counter = 0;
}
if (counter === 0) {
columnDiv = createEl('div', {class: 'indexColumn'});
section.appendChild(columnDiv);
}
columnDiv.appendChild(indexEls[i]);
}
main.appendChild(section);
};
/**
* init gets things going
*/
init = function () {
var privateItems = [],
videojs = {name: 'videojs', meta: {filename: 'video.js'}},
j;
// get the data objects for all classes
classes = getSubArray(docData, 'kind', 'class');
// videojs is a special case
classes.push(videojs);
bclslog('classes', classes);
// set the doc title
title.innerHTML = 'API Documentation Index';
// remove any private items
privateItems = findObjectsInArray(classes, 'access', 'private');
bclslog('privateItems', privateItems);
j = privateItems.length;
bclslog('j', j);
while (j > 0) {
j--;
classes.splice(privateItems[j], 1);
}
// sort the array
classes = sortArray(classes, 'name');
bclslog('classes', classes);
// now we're ready to roll
addHeaderContent();
addIndex();
};
init();
return {
};
})(window, document, docData);
|