diff --git a/resources/javascript/searchbar.js b/resources/javascript/searchbar.js index 2a74e439f2..f006328964 100644 --- a/resources/javascript/searchbar.js +++ b/resources/javascript/searchbar.js @@ -36,14 +36,40 @@ categories[suggestion._tags[0]].push(suggestion) }); - categories = $.map(Object.keys(categories).sort(), function(categoryName) { - var items = categories[categoryName]; - items[0].isCategoryHeader = true; - items[0].categoryName = capitalize(categoryName); + var categoriesWithSubCategories = {} + $.each(categories, function(categoryName, suggestions) { + var subCategories = {} + suggestions.forEach(function(suggestion) { + var highlight = suggestion._highlightResult || {}; + var title = (highlight.title || {}).value + title = title || suggestion.title + title = title || categoryName + subCategories[title] = subCategories[title] || [] + subCategories[title].push(suggestion) + }); + categoriesWithSubCategories[categoryName] = subCategories; + }); + + var suggestionsSorted = [] + Object.keys(categoriesWithSubCategories).sort().forEach(function(categoryName) { + var subCategories = categoriesWithSubCategories[categoryName]; + var firstInCategory = true; + Object.keys(subCategories).sort().forEach(function(subCategoryName) { + var items = subCategories[subCategoryName]; + items[0].isSubCategoryHeader = true; + items[0].subCategoryName = capitalize(subCategoryName); + + if(firstInCategory) { + items[0].isCategoryHeader = true; + items[0].categoryName = capitalize(categoryName); + firstInCategory = false; + } - return items; + suggestionsSorted = suggestionsSorted.concat(items); + }); }); - callback(categories); + + callback(suggestionsSorted); }); }, name: 'a', @@ -54,21 +80,33 @@ if(suggestion.isCategoryHeader) { html.push('
' + suggestion.categoryName + '
'); } + if(suggestion.isSubCategoryHeader) { + html.push('
' + suggestion.subCategoryName + '
'); + } else { + html.push('
 
'); + } var highlight = suggestion._highlightResult || {}; var snippet = suggestion._snippetResult || {}; - var title = highlight.title.value; var text = ''; for(var i = 0 ; i < ATTRIBUTES.length ; i++) { if(highlight[ATTRIBUTES[i]] !== undefined) { text = highlight[ATTRIBUTES[i]].value; - text = (snippet[ATTRIBUTES[i]] || {}).value || text; + var snippet = (snippet[ATTRIBUTES[i]] || {}).value + if(snippet) { + if(snippet.charAt(0) === snippet.charAt(0).toLowerCase()) { + snippet = "… " + snippet; + } + if(['.', '!', '?'].indexOf(snippet.charAt(snippet.length - 1)) === -1) { + snippet = snippet + " …"; + } + } + text = snippet || text; break; } } html.push('
'); - html.push('
' + title + '
'); html.push('
' + text + '
'); html.push('
'); return html.join(' '); diff --git a/resources/stylesheets/base.css b/resources/stylesheets/base.css index 67d6c7e95f..f352625622 100644 --- a/resources/stylesheets/base.css +++ b/resources/stylesheets/base.css @@ -232,11 +232,11 @@ div#pop-up-arrow { } .algolia-autocomplete .aa-dropdown-menu { - width: 500px; + width: 550px; background-color: #fff; border: 1px solid #404040; margin-top: 2px; - margin-left: -319px; + margin-left: -369px; padding: 1px; } @@ -246,8 +246,9 @@ div#pop-up-arrow { } .algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor { - background-color: #B2D7FF; + background-color: #EEEEEE; } + .algolia-autocomplete .aa-dropdown-menu .aa-suggestion em { font-weight: bold; font-style: normal; @@ -263,14 +264,30 @@ div#pop-up-arrow { cursor: default; } -.aa-suggestion .suggestion-content div { +.aa-suggestion > div:not(.suggestion-category) { display: table-cell; - padding: 5px 7px; + padding: 5px; } -.aa-suggestion .suggestion-content div:first-child { +.aa-suggestion.aa-cursor .suggestion-empty-subcategory, .aa-suggestion.aa-cursor .suggestion-subcategory { + background-color: white; +} + +.aa-suggestion .suggestion-empty-subcategory, .aa-suggestion .suggestion-subcategory { border-right: 2px solid #DE3423; - width: 180px; + width: 150px; + font-weight: 500; + z-index: 1000; + text-align: right; +} + +.aa-suggestion .suggestion-content { + width: 376px; + border-top: 1px #999 solid; +} + +.aa-suggestion .suggestion-category ~ .suggestion-content { + border-top: none; } .aa-dropdown-menu .branding-footer {