forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchdata.js
88 lines (77 loc) · 1.95 KB
/
searchdata.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
steal(function(){
// Makes a JSON object for search data
DocumentJS.searchData = function(options){
var searchData = {
list: {}
};
addToSearchData(DocumentJS.objects, searchData)
return new DocumentJS.File(options.out + "/searchData.json").save(DocumentJS.out(searchData, false));
}
// goes through list and adds to search data
var addToSearchData = function( list, searchData ) {
var c, parts, part, p, fullName;
for ( var name in list ) {
if (list.hasOwnProperty(name)){
c = list[name];
if ( c.type == 'script' ) {
continue;
}
//break up into parts
fullName = c.name;
searchData.list[fullName] = {
name: c.name,
type: c.type
};
if ( c.title ) {
searchData.list[fullName].title = c.title
}
if ( c.tags ) {
searchData.list[fullName].tags = c.tags
}
if ( c.hide ) {
searchData.list[fullName].hide = c.hide
}
parts = fullName.split(".");
for ( p = 0; p < parts.length; p++ ) {
part = parts[p].toLowerCase();
if ( part == "jquery" ){
continue;
}
addTagToSearchData(fullName, part, searchData)
}
//now add tags if there are tags
if ( c.tags ) {
for ( var t = 0; t < c.tags.length; t++ ){
addTagToSearchData(fullName, c.tags[t], searchData);
}
}
}
}
},
//adds a component to the search data
addTagToSearchData = function( data, tag, searchData ) {
var letter, l, depth = 2,
current = searchData;
for ( l = 0; l < depth; l++ ) {
letter = tag.substring(l, l + 1);
if (!current[letter] ) {
current[letter] = {};
current[letter].list = [];
}
if ( indexOf(current[letter].list, data) == -1 ) {
current[letter].list.push(data);
}
current = current[letter];
}
},
indexOf = function( array, item ) {
var i = 0,
length = array.length;
for (; i < length; i++ ){
if ( array[i] === item ){
return i;
}
}
return -1;
}
})