File tree Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,14 @@ td p {
199
199
color : # 000000 ;
200
200
}
201
201
202
+ .ui-autocomplete-category {
203
+ font-weight : bold;
204
+ font-style : italic;
205
+ background-color : # DAFE8C ;
206
+ padding : 2px 5px ;
207
+ line-height : 1.5 ;
208
+ }
209
+
202
210
.menu {
203
211
border : none;
204
212
text-align : center;
Original file line number Diff line number Diff line change @@ -587,9 +587,9 @@ sub write-search-file () {
587
587
my $ items = $ * DR . get-kinds. map (-> $ kind {
588
588
$ * DR . lookup($ kind , : by<kind >). categorize ({escape . name })\
589
589
. pairs . sort ({. key }). map : -> (: key($ name ), : value(@ docs )) {
590
- qq [[ \{ label : "{
590
+ qq [[ \{ category : "{
591
591
( @ docs > 1 ?? $ kind !! @ docs . [0 ]. subkinds[0 ] ). wordcase
592
- } : $ name ", value: "$ name ", url: "{ @ docs . [0 ]. url} " \} ]] # "
592
+ } ", value: "$ name ", url: "{ @ docs . [0 ]. url} " \} ]] # "
593
593
}
594
594
}). flat . join (" ,\n " );
595
595
spurt (" html/js/search.js" , $ template . subst (" ITEMS" , $ items ));
Original file line number Diff line number Diff line change 1
1
$ ( function ( ) {
2
- $ ( "#query" ) . autocomplete ( {
2
+ $ . widget ( "custom.catcomplete" , $ . ui . autocomplete , {
3
+ _create : function ( ) {
4
+ this . _super ( ) ;
5
+ this . widget ( ) . menu ( "option" , "items" , "> :not(.ui-autocomplete-category)" ) ;
6
+ } ,
7
+ _renderMenu : function ( ul , items ) {
8
+ var that = this ,
9
+ currentCategory = "" ;
10
+ function sortBy ( a , b ) {
11
+ if ( a . category . toLowerCase ( ) < b . category . toLowerCase ( ) ) {
12
+ return - 1 ;
13
+ } else if ( a . category . toLowerCase ( ) > b . category . toLowerCase ( ) ) {
14
+ return 1 ;
15
+ } else if ( a . value . toLowerCase ( ) < b . value . toLowerCase ( ) ) {
16
+ return - 1 ;
17
+ } else if ( a . value . toLowerCase ( ) > b . value . toLowerCase ( ) ) {
18
+ return 1 ;
19
+ } else {
20
+ return 0 ;
21
+ }
22
+ }
23
+ $ . each ( items . sort ( sortBy ) , function ( index , item ) {
24
+ var li ;
25
+ if ( item . category != currentCategory ) {
26
+ ul . append ( "<li class='ui-autocomplete-category'>" + item . category + "</li>" ) ;
27
+ currentCategory = item . category ;
28
+ }
29
+ li = that . _renderItemData ( ul , item ) ;
30
+ if ( item . category ) {
31
+ li . attr ( "aria-label" , item . category + " : " + item . label ) ;
32
+ }
33
+ } ) ;
34
+ }
35
+ } ) ;
36
+ $ ( "#query" ) . catcomplete ( {
3
37
response : function ( e , ui ) {
4
38
if ( ! ui . content . length ) { $ ( '#search' ) . addClass ( 'not-found' ) }
5
39
else { $ ( '#search' ) . removeClass ( 'not-found' ) }
You can’t perform that action at this time.
0 commit comments