@@ -59,7 +59,7 @@ function shiftWindow() {
59
59
}
60
60
61
61
function initSearch ( ) {
62
- var index ;
62
+ var index ; // the JSON data
63
63
64
64
function findMatches ( q , cb ) {
65
65
var matches , substringRegex ;
@@ -74,22 +74,44 @@ function initSearch() {
74
74
// contains the substring `q`, add it to the `matches` array
75
75
$ . each ( index , function ( i , element ) {
76
76
if ( substrRegex . test ( element . name ) ) {
77
- matches . push ( element . name ) ;
77
+ matches . push ( element ) ;
78
78
}
79
79
} ) ;
80
80
81
81
cb ( matches ) ;
82
82
} ;
83
83
84
84
function initTypeahead ( ) {
85
+ $ ( '#search-box' ) . prop ( 'disabled' , false ) ;
86
+
85
87
$ ( '#search-box.typeahead' ) . typeahead ( {
86
88
hint : true ,
87
89
highlight : true ,
88
90
minLength : 3
89
91
} ,
90
92
{
91
93
name : 'elements' ,
92
- source : findMatches
94
+ source : findMatches ,
95
+ display : function ( element ) { return element . name ; } ,
96
+ templates : {
97
+ suggestion : function ( match ) {
98
+ return [
99
+ '<div>' ,
100
+ match . name ,
101
+ ' ' ,
102
+ match . type . toLowerCase ( ) ,
103
+ ( match . enclosedBy ? [
104
+ '<div class="search-from-lib">from ' ,
105
+ match . enclosedBy . name ,
106
+ '</div>' ] . join ( '' ) : '' ) ,
107
+ '</div>'
108
+ ] . join ( '' ) ;
109
+ }
110
+ }
111
+ } ) ;
112
+
113
+ $ ( '#search-box.typeahead' ) . bind ( 'typeahead:select' , function ( ev , suggestion ) {
114
+ window . location = suggestion . href ;
93
115
} ) ;
94
116
}
95
117
@@ -100,7 +122,6 @@ function initSearch() {
100
122
initTypeahead ( ) ;
101
123
} ) ;
102
124
jsonReq . send ( ) ;
103
-
104
125
}
105
126
106
127
document . addEventListener ( "DOMContentLoaded" , function ( ) {
0 commit comments