|
36 | 36 | categories[suggestion._tags[0]].push(suggestion) |
37 | 37 | }); |
38 | 38 |
|
39 | | -categories=$.map(Object.keys(categories).sort(),function(categoryName){ |
40 | | -varitems=categories[categoryName]; |
41 | | -items[0].isCategoryHeader=true; |
42 | | -items[0].categoryName=capitalize(categoryName); |
| 39 | +varcategoriesWithSubCategories={} |
| 40 | +$.each(categories,function(categoryName,suggestions){ |
| 41 | +varsubCategories={} |
| 42 | +suggestions.forEach(function(suggestion){ |
| 43 | +varhighlight=suggestion._highlightResult||{}; |
| 44 | +vartitle=(highlight.title||{}).value |
| 45 | +title=title||suggestion.title |
| 46 | +title=title||categoryName |
| 47 | +subCategories[title]=subCategories[title]||[] |
| 48 | +subCategories[title].push(suggestion) |
| 49 | +}); |
| 50 | +categoriesWithSubCategories[categoryName]=subCategories; |
| 51 | +}); |
| 52 | + |
| 53 | +varsuggestionsSorted=[] |
| 54 | +Object.keys(categoriesWithSubCategories).sort().forEach(function(categoryName){ |
| 55 | +varsubCategories=categoriesWithSubCategories[categoryName]; |
| 56 | +varfirstInCategory=true; |
| 57 | +Object.keys(subCategories).sort().forEach(function(subCategoryName){ |
| 58 | +varitems=subCategories[subCategoryName]; |
| 59 | +items[0].isSubCategoryHeader=true; |
| 60 | +items[0].subCategoryName=capitalize(subCategoryName); |
| 61 | + |
| 62 | +if(firstInCategory){ |
| 63 | +items[0].isCategoryHeader=true; |
| 64 | +items[0].categoryName=capitalize(categoryName); |
| 65 | +firstInCategory=false; |
| 66 | +} |
43 | 67 |
|
44 | | -returnitems; |
| 68 | +suggestionsSorted=suggestionsSorted.concat(items); |
| 69 | +}); |
45 | 70 | }); |
46 | | -callback(categories); |
| 71 | + |
| 72 | +callback(suggestionsSorted); |
47 | 73 | }); |
48 | 74 | }, |
49 | 75 | name: 'a', |
|
54 | 80 | if(suggestion.isCategoryHeader){ |
55 | 81 | html.push('<div class="suggestion-category">'+suggestion.categoryName+'</div>'); |
56 | 82 | } |
| 83 | +if(suggestion.isSubCategoryHeader){ |
| 84 | +html.push('<div class="suggestion-subcategory">'+suggestion.subCategoryName+'</div>'); |
| 85 | +}else{ |
| 86 | +html.push('<div class="suggestion-empty-subcategory"> </div>'); |
| 87 | +} |
57 | 88 |
|
58 | 89 | varhighlight=suggestion._highlightResult||{}; |
59 | 90 | varsnippet=suggestion._snippetResult||{}; |
60 | | -vartitle=highlight.title.value; |
61 | 91 | vartext=''; |
62 | 92 | for(vari=0;i<ATTRIBUTES.length;i++){ |
63 | 93 | if(highlight[ATTRIBUTES[i]]!==undefined){ |
64 | 94 | text=highlight[ATTRIBUTES[i]].value; |
65 | | -text=(snippet[ATTRIBUTES[i]]||{}).value||text; |
| 95 | +varsnippet=(snippet[ATTRIBUTES[i]]||{}).value |
| 96 | +if(snippet){ |
| 97 | +if(snippet.charAt(0)===snippet.charAt(0).toLowerCase()){ |
| 98 | +snippet="… "+snippet; |
| 99 | +} |
| 100 | +if(['.','!','?'].indexOf(snippet.charAt(snippet.length-1))===-1){ |
| 101 | +snippet=snippet+" …"; |
| 102 | +} |
| 103 | +} |
| 104 | +text=snippet||text; |
66 | 105 | break; |
67 | 106 | } |
68 | 107 | } |
69 | 108 |
|
70 | 109 | html.push(' <div class="suggestion-content">'); |
71 | | -html.push(' <div class="suggestion-title">'+title+'</div>'); |
72 | 110 | html.push(' <div class="suggestion-text">'+text+'</div>'); |
73 | 111 | html.push(' </div>'); |
74 | 112 | returnhtml.join(' '); |
|
0 commit comments