@@ -52,26 +52,12 @@ api.search.findConstants_ = function(str) {
52
52
return res ;
53
53
} ;
54
54
55
- /**
55
+ /**
56
56
* @private
57
- * @param {string } str
58
- * @param {string } container
59
- * @param {string } key
57
+ * @param {Array } res
60
58
* @return {Array }
61
59
*/
62
- api . search . findGrouped_ = function ( str , container , key ) {
63
- var data = api . search . data_ ;
64
- var contains = api . search . match_ ;
65
- var res = [ ] ;
66
- for ( var i = 0 ; i < data [ container ] . length ; i ++ ) {
67
- var c = data [ container ] [ i ] ;
68
- for ( var j = 0 ; j < c [ key ] . length ; j ++ ) {
69
- var m = c [ key ] [ j ] ;
70
- if ( contains ( m . name , m [ "full-name" ] , str ) ) {
71
- res . push ( m ) ;
72
- }
73
- }
74
- }
60
+ api . search . setMultiple_ = function ( res ) {
75
61
var actual = [ ] ;
76
62
for ( var i = 0 ; i < res . length ; i ++ ) {
77
63
var item = res [ i ] ;
@@ -92,6 +78,29 @@ api.search.findGrouped_ = function(str, container, key) {
92
78
return actual ;
93
79
} ;
94
80
81
+ /**
82
+ * @private
83
+ * @param {string } str
84
+ * @param {string } container
85
+ * @param {string } key
86
+ * @return {Array }
87
+ */
88
+ api . search . findGrouped_ = function ( str , container , key ) {
89
+ var data = api . search . data_ ;
90
+ var contains = api . search . match_ ;
91
+ var res = [ ] ;
92
+ for ( var i = 0 ; i < data [ container ] . length ; i ++ ) {
93
+ var c = data [ container ] [ i ] ;
94
+ for ( var j = 0 ; j < c [ key ] . length ; j ++ ) {
95
+ var m = c [ key ] [ j ] ;
96
+ if ( contains ( m . name , m [ "full-name" ] , str ) ) {
97
+ res . push ( m ) ;
98
+ }
99
+ }
100
+ }
101
+ return api . search . setMultiple_ ( res ) ;
102
+ } ;
103
+
95
104
/**
96
105
* @private
97
106
* @param {string } str
@@ -177,7 +186,7 @@ api.search.showGrouped_ = function(item, prefix, postfix) {
177
186
var $res = $ ( "<ul></ul>" ) ;
178
187
for ( var i = 0 ; i < item . group . length ; i ++ ) {
179
188
var entry = item . group [ i ] ;
180
- $res . append ( "<li><a class='item-link' href='/" + api . config . version + "/" + entry . link + "'>" + prefix + entry [ "full-name " ] + postfix + "</a></li>" ) ;
189
+ $res . append ( "<li><a class='item-link' href='/" + api . config . version + "/" + entry . link + "'>" + prefix + entry [ "full_name " ] + postfix + "</a></li>" ) ;
181
190
}
182
191
183
192
api . config . page = null ;
@@ -213,7 +222,7 @@ api.search.addToResults_ = function($res, items, prefix, postfix, title) {
213
222
for ( var i = 0 ; i < items . length ; i ++ ) {
214
223
var item = items [ i ] ;
215
224
if ( ! item . multiple )
216
- $res . append ( "<li><a class='item-link' href='/" + api . config . version + "/" + item . link + "'>" + prefix + item [ "full-name " ] + postfix + "</a></li>" ) ;
225
+ $res . append ( "<li><a class='item-link' href='/" + api . config . version + "/" + item . link + "'>" + prefix + item [ "full_name " ] + postfix + "</a></li>" ) ;
217
226
}
218
227
} ;
219
228
@@ -254,11 +263,65 @@ api.search.search_ = function(query) {
254
263
255
264
/**
256
265
* @private
257
- * @param {Object } data
266
+ * @param {Array } data
267
+ * @param {string } query
258
268
*/
259
- api . search . onLoad_ = function ( data ) {
269
+ api . search . onDataLoad_ = function ( data , query ) {
260
270
api . search . data_ = data ;
271
+ var constants = [ ] ;
272
+ var functions = [ ] ;
273
+ var methods = [ ] ;
274
+ var namespaces = [ ] ;
275
+ var enums = [ ] ;
276
+ var classes = [ ] ;
277
+ var typedefs = [ ] ;
278
+ for ( var i = 0 ; i < data . length ; i ++ ) {
279
+ var item = data [ i ] ;
280
+ switch ( item . type ) {
281
+ case "method" : methods . push ( item ) ; break ;
282
+ case "function" : functions . push ( item ) ; break ;
283
+ case "class" : classes . push ( item ) ; break ;
284
+ case "typedef" : typedefs . push ( item ) ; break ;
285
+ case "enum" : enums . push ( item ) ; break ;
286
+ case "namespace" : namespaces . push ( item ) ; break ;
287
+ case "constant" : constants . push ( item ) ; break ;
288
+ }
289
+ }
290
+ methods = api . search . setMultiple_ ( methods ) ;
291
+ functions = api . search . setMultiple_ ( functions ) ;
292
+
293
+ var $res = $ ( "<ul></ul>" ) ;
294
+ api . search . addToResults_ ( $res , constants , "" , "" , "Constants" ) ;
295
+ api . search . addToResults_ ( $res , functions , "" , "()" , "Functions" ) ;
296
+ api . search . addToResults_ ( $res , methods , "" , "()" , "Methods" ) ;
297
+ api . search . addToResults_ ( $res , namespaces , "" , "" , "Namespaces" ) ;
298
+ api . search . addToResults_ ( $res , enums , "[" , "]" , "Enums" ) ;
299
+ api . search . addToResults_ ( $res , typedefs , "{" , "}" , "Typedefs" ) ;
300
+ api . search . addToResults_ ( $res , classes , "" , "" , "Classes" ) ;
301
+ $res . find ( "a.item-link" ) . click ( api . links . typeLinkClick ) ;
302
+
303
+ if ( ! $res . find ( "a" ) . length ) api . search . showEmpty_ ( $res ) ;
261
304
305
+ $ ( "#search-results-new" ) . show ( ) ;
306
+ $ ( "#search-results-new" ) . html ( "" ) ;
307
+ $ ( "#search-results-new" ) . append ( $res ) ;
308
+ } ;
309
+
310
+ /**
311
+ * @private
312
+ * @param {string } query
313
+ */
314
+ api . search . makeSearchReq = function ( query ) {
315
+ if ( query . length < 2 ) {
316
+ api . search . hide ( ) ;
317
+ return ;
318
+ }
319
+ $ . get ( "/" + api . config . version + "/search.json?q=" + query , function ( data ) {
320
+ api . search . onDataLoad_ ( data , query ) ;
321
+ } ) ;
322
+ } ;
323
+
324
+ api . search . init = function ( ) {
262
325
$ ( "#search-results-new" ) . click ( function ( e ) {
263
326
e . stopPropagation ( ) ;
264
327
} ) ;
@@ -268,19 +331,24 @@ api.search.onLoad_ = function(data) {
268
331
return false ;
269
332
} ) ;
270
333
$ ( "#search" ) . focus ( function ( ) {
271
- api . search . search_ ( $ ( this ) . val ( ) ) ;
334
+ if ( $ ( this ) . val ( ) != '' ) {
335
+ $ ( "#search-results-new" ) . show ( ) ;
336
+ }
272
337
} ) ;
273
-
338
+
339
+ var timeout = null ;
274
340
$ ( "#search" ) . keyup ( function ( e ) {
275
341
if ( e . keyCode == 27 ) { //esc
276
342
api . search . hide ( ) ;
277
343
$ ( "#search" ) . val ( '' ) ;
278
344
} else {
279
- api . search . search_ ( $ ( this ) . val ( ) ) ;
345
+ if ( timeout !== null ) {
346
+ window . clearTimeout ( timeout ) ;
347
+ }
348
+ timeout = window . setTimeout ( function ( ) {
349
+ api . search . makeSearchReq ( $ ( "#search" ) . val ( ) ) ;
350
+ } , 250 ) ;
280
351
}
281
352
} ) ;
282
353
} ;
283
354
284
- api . search . init = function ( ) {
285
- $ . get ( "/" + api . config . version + "/data/search.json" , api . search . onLoad_ ) ;
286
- } ;
0 commit comments