docsearch.js
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -0,1 +1,11 @@ | ||
<a name="2.0.4"></a> | ||
## [2.0.4](https://github.com/algolia/docsearch/compare/v2.0.3...v2.0.4) (2016-06-21) | ||
### Features | ||
* **DOM:** split simple and collumns template ([2a3b7eb](https://github.com/algolia/docsearch/commit/2a3b7eb)) | ||
<a name="2.0.3"></a> | ||
@@ -2,0 +12,0 @@ ## [2.0.3](https://github.com/algolia/docsearch/compare/v2.0.2...v2.0.3) (2016-06-20) |
@@ -263,13 +263,15 @@ 'use strict'; | ||
var subcategory = _utilsJs2['default'].getHighlightedValue(hit, 'lvl1') || category; | ||
var isSubcategoryDuplicate = subcategory == category; | ||
var displayTitle = _utilsJs2['default'].compact([_utilsJs2['default'].getHighlightedValue(hit, 'lvl2') || subcategory, _utilsJs2['default'].getHighlightedValue(hit, 'lvl3'), _utilsJs2['default'].getHighlightedValue(hit, 'lvl4'), _utilsJs2['default'].getHighlightedValue(hit, 'lvl5'), _utilsJs2['default'].getHighlightedValue(hit, 'lvl6')]).join('<span class="aa-suggestion-title-separator"> › </span>'); | ||
var isDisplayTitleDuplicate = displayTitle == subcategory; | ||
var text = _utilsJs2['default'].getSnippetedValue(hit, 'content'); | ||
var isTextOrSubcatoryNonEmpty = subcategory && subcategory != "" || displayTitle && displayTitle != ""; | ||
var isLvl2 = displayTitle && displayTitle != '' && displayTitle != subcategory; | ||
var isLvl1 = !isLvl2 && subcategory && subcategory != '' && subcategory != category; | ||
var isLvl0 = !isLvl1 && !isLvl2; | ||
return { | ||
isLvl0: isLvl0, | ||
isLvl1: isLvl1, | ||
isLvl2: isLvl2, | ||
isCategoryHeader: hit.isCategoryHeader, | ||
isSubCategoryHeader: hit.isSubCategoryHeader, | ||
isSubcategoryDuplicate: isSubcategoryDuplicate, | ||
isDisplayTitleDuplicate: isDisplayTitleDuplicate, | ||
isTextOrSubcatoryNonEmpty: isTextOrSubcatoryNonEmpty, | ||
@@ -310,6 +312,6 @@ category: category, | ||
value: function getSuggestionTemplate(isSimpleLayout) { | ||
var template = _hoganJs2['default'].compile(_templatesJs2['default'].suggestion); | ||
var stringTemplate = isSimpleLayout ? _templatesJs2['default'].suggestionSimple : _templatesJs2['default'].suggestion; | ||
var template = _hoganJs2['default'].compile(stringTemplate); | ||
return function (suggestion) { | ||
isSimpleLayout = isSimpleLayout || false; | ||
return template.render(_extends({ isSimpleLayout: isSimpleLayout }, suggestion)); | ||
return template.render(suggestion); | ||
}; | ||
@@ -316,0 +318,0 @@ } |
@@ -11,3 +11,4 @@ 'use strict'; | ||
var templates = { | ||
suggestion: '\n <div class="' + suggestionPrefix + '\n {{#isCategoryHeader}}' + suggestionPrefix + '__main{{/isCategoryHeader}}\n {{#isSubCategoryHeader}}' + suggestionPrefix + '__secondary{{/isSubCategoryHeader}}\n {{#isSimpleLayout}}suggestion-layout-simple{{/isSimpleLayout}}\n ">\n \n <div class="' + suggestionPrefix + '--category-header">\n <span class="' + suggestionPrefix + '--category-header-lvl0">{{{category}}}</span>\n {{#isSimpleLayout}}\n <span class="' + suggestionPrefix + '--category-header-lvl1">{{{subcategory}}}</span>\n {{/isSimpleLayout}}\n </div>\n <div class="' + suggestionPrefix + '--wrapper">\n <div class="' + suggestionPrefix + '--subcategory-column {{#isSubcategoryDuplicate}}' + suggestionPrefix + '--duplicate-content{{/isSubcategoryDuplicate}}">\n <span class="' + suggestionPrefix + '--subcategory-column-text">{{{subcategory}}}</span>\n </div>\n {{#isTextOrSubcatoryNonEmpty}}\n <div class="' + suggestionPrefix + '--content">\n <div class="' + suggestionPrefix + '--subcategory-inline {{#isSubcategoryDuplicate}}' + suggestionPrefix + '--duplicate-content{{/isSubcategoryDuplicate}}">{{{subcategory}}}</div>\n <div class="' + suggestionPrefix + '--title {{#isDisplayTitleDuplicate}}' + suggestionPrefix + '--duplicate-content{{/isDisplayTitleDuplicate}}">{{{title}}}</div>\n {{#text}}<div class="' + suggestionPrefix + '--text">{{{text}}}</div>{{/text}}\n </div>\n {{/isTextOrSubcatoryNonEmpty}}\n </div>\n </div>\n ', | ||
suggestion: '\n <div class="' + suggestionPrefix + '\n {{#isCategoryHeader}}' + suggestionPrefix + '__main{{/isCategoryHeader}}\n {{#isSubCategoryHeader}}' + suggestionPrefix + '__secondary{{/isSubCategoryHeader}}\n ">\n \n <div class="' + suggestionPrefix + '--category-header">\n <span class="' + suggestionPrefix + '--category-header-lvl0">{{{category}}}</span>\n </div>\n <div class="' + suggestionPrefix + '--wrapper">\n <div class="' + suggestionPrefix + '--subcategory-column">\n <span class="' + suggestionPrefix + '--subcategory-column-text">{{{subcategory}}}</span>\n </div>\n {{#isTextOrSubcatoryNonEmpty}}\n <div class="' + suggestionPrefix + '--content">\n <div class="' + suggestionPrefix + '--subcategory-inline">{{{subcategory}}}</div>\n <div class="' + suggestionPrefix + '--title">{{{title}}}</div>\n {{#text}}<div class="' + suggestionPrefix + '--text">{{{text}}}</div>{{/text}}\n </div>\n {{/isTextOrSubcatoryNonEmpty}}\n </div>\n </div>\n ', | ||
suggestionSimple: '\n <div class="' + suggestionPrefix + '\n {{#isCategoryHeader}}' + suggestionPrefix + '__main{{/isCategoryHeader}}\n {{#isSubCategoryHeader}}' + suggestionPrefix + '__secondary{{/isSubCategoryHeader}}\n suggestion-layout-simple\n ">\n \n <div class="' + suggestionPrefix + '--category-header">\n {{^isLvl0}}\n <span class="' + suggestionPrefix + '--category-header-lvl0 ' + suggestionPrefix + '--category-header-item">{{{category}}}</span>\n {{/isLvl0}}\n {{^isLvl1}}\n <span class="' + suggestionPrefix + '--category-header-lvl1 ' + suggestionPrefix + '--category-header-item">\n {{{subcategory}}}\n </span>\n {{/isLvl1}}\n \n <div class="' + suggestionPrefix + '--title ' + suggestionPrefix + '--category-header-item">\n {{#isLvl2}}\n {{{title}}}\n {{/isLvl2}}\n {{#isLvl1}}\n {{{subcategory}}}\n {{/isLvl1}}\n {{#isLvl0}}\n {{{category}}}\n {{/isLvl0}}\n </div>\n </div>\n <div class="' + suggestionPrefix + '--wrapper">\n {{#text}}\n <div class="' + suggestionPrefix + '--content">\n <div class="' + suggestionPrefix + '--text">{{{text}}}</div>\n </div>\n {{/text}}\n </div>\n </div>\n ', | ||
footer: '\n <div class="' + footerPrefix + '">\n Search by <a class="' + footerPrefix + '--logo" href="https://www.algolia.com/docsearch">Algolia</a>\n </div>\n ', | ||
@@ -14,0 +15,0 @@ empty: '\n <div class="' + suggestionPrefix + '">\n <div class="' + suggestionPrefix + '--wrapper">\n <div class="' + suggestionPrefix + '--content ' + suggestionPrefix + '--no-result">\n <div class="' + suggestionPrefix + '--title">\n <div class="' + suggestionPrefix + '--text">\n No results found for query <b>{{{query}}}</b>\n </div>\n </div>\n </div>\n </div>\n </div>\n ', |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports['default'] = '2.0.3'; | ||
exports['default'] = '2.0.4'; | ||
module.exports = exports['default']; |
{ | ||
"name": "docsearch.js", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Add an autocomplete dropdown to your documentation", | ||
@@ -5,0 +5,0 @@ "main": "dist/npm/index.js", |
@@ -192,3 +192,2 @@ import Hogan from 'hogan.js'; | ||
let subcategory = utils.getHighlightedValue(hit, 'lvl1') || category; | ||
let isSubcategoryDuplicate = subcategory == category; | ||
let displayTitle = utils.compact([ | ||
@@ -201,11 +200,14 @@ utils.getHighlightedValue(hit, 'lvl2') || subcategory, | ||
]).join('<span class="aa-suggestion-title-separator"> › </span>'); | ||
let isDisplayTitleDuplicate = displayTitle == subcategory; | ||
let text = utils.getSnippetedValue(hit, 'content'); | ||
let isTextOrSubcatoryNonEmpty = (subcategory && subcategory != "") || (displayTitle && displayTitle != ""); | ||
let isLvl2 = displayTitle && displayTitle != '' && displayTitle != subcategory; | ||
let isLvl1 = !isLvl2 && (subcategory && subcategory != '' && subcategory != category); | ||
let isLvl0 = !isLvl1 && !isLvl2; | ||
return { | ||
isLvl0: isLvl0, | ||
isLvl1: isLvl1, | ||
isLvl2: isLvl2, | ||
isCategoryHeader: hit.isCategoryHeader, | ||
isSubCategoryHeader: hit.isSubCategoryHeader, | ||
isSubcategoryDuplicate: isSubcategoryDuplicate, | ||
isDisplayTitleDuplicate: isDisplayTitleDuplicate, | ||
isTextOrSubcatoryNonEmpty: isTextOrSubcatoryNonEmpty, | ||
@@ -243,6 +245,6 @@ category: category, | ||
static getSuggestionTemplate(isSimpleLayout) { | ||
const template = Hogan.compile(templates.suggestion); | ||
var stringTemplate = isSimpleLayout ? templates.suggestionSimple : templates.suggestion | ||
const template = Hogan.compile(stringTemplate); | ||
return (suggestion) => { | ||
isSimpleLayout = isSimpleLayout || false; | ||
return template.render({isSimpleLayout, ...suggestion}); | ||
return template.render(suggestion); | ||
}; | ||
@@ -249,0 +251,0 @@ } |
@@ -10,3 +10,2 @@ let prefix = 'algolia-docsearch'; | ||
{{#isSubCategoryHeader}}${suggestionPrefix}__secondary{{/isSubCategoryHeader}} | ||
{{#isSimpleLayout}}suggestion-layout-simple{{/isSimpleLayout}} | ||
"> | ||
@@ -16,8 +15,5 @@ | ||
<span class="${suggestionPrefix}--category-header-lvl0">{{{category}}}</span> | ||
{{#isSimpleLayout}} | ||
<span class="${suggestionPrefix}--category-header-lvl1">{{{subcategory}}}</span> | ||
{{/isSimpleLayout}} | ||
</div> | ||
<div class="${suggestionPrefix}--wrapper"> | ||
<div class="${suggestionPrefix}--subcategory-column {{#isSubcategoryDuplicate}}${suggestionPrefix}--duplicate-content{{/isSubcategoryDuplicate}}"> | ||
<div class="${suggestionPrefix}--subcategory-column"> | ||
<span class="${suggestionPrefix}--subcategory-column-text">{{{subcategory}}}</span> | ||
@@ -27,4 +23,4 @@ </div> | ||
<div class="${suggestionPrefix}--content"> | ||
<div class="${suggestionPrefix}--subcategory-inline {{#isSubcategoryDuplicate}}${suggestionPrefix}--duplicate-content{{/isSubcategoryDuplicate}}">{{{subcategory}}}</div> | ||
<div class="${suggestionPrefix}--title {{#isDisplayTitleDuplicate}}${suggestionPrefix}--duplicate-content{{/isDisplayTitleDuplicate}}">{{{title}}}</div> | ||
<div class="${suggestionPrefix}--subcategory-inline">{{{subcategory}}}</div> | ||
<div class="${suggestionPrefix}--title">{{{title}}}</div> | ||
{{#text}}<div class="${suggestionPrefix}--text">{{{text}}}</div>{{/text}} | ||
@@ -36,2 +32,40 @@ </div> | ||
`, | ||
suggestionSimple: ` | ||
<div class="${suggestionPrefix} | ||
{{#isCategoryHeader}}${suggestionPrefix}__main{{/isCategoryHeader}} | ||
{{#isSubCategoryHeader}}${suggestionPrefix}__secondary{{/isSubCategoryHeader}} | ||
suggestion-layout-simple | ||
"> | ||
<div class="${suggestionPrefix}--category-header"> | ||
{{^isLvl0}} | ||
<span class="${suggestionPrefix}--category-header-lvl0 ${suggestionPrefix}--category-header-item">{{{category}}}</span> | ||
{{/isLvl0}} | ||
{{^isLvl1}} | ||
<span class="${suggestionPrefix}--category-header-lvl1 ${suggestionPrefix}--category-header-item"> | ||
{{{subcategory}}} | ||
</span> | ||
{{/isLvl1}} | ||
<div class="${suggestionPrefix}--title ${suggestionPrefix}--category-header-item"> | ||
{{#isLvl2}} | ||
{{{title}}} | ||
{{/isLvl2}} | ||
{{#isLvl1}} | ||
{{{subcategory}}} | ||
{{/isLvl1}} | ||
{{#isLvl0}} | ||
{{{category}}} | ||
{{/isLvl0}} | ||
</div> | ||
</div> | ||
<div class="${suggestionPrefix}--wrapper"> | ||
{{#text}} | ||
<div class="${suggestionPrefix}--content"> | ||
<div class="${suggestionPrefix}--text">{{{text}}}</div> | ||
</div> | ||
{{/text}} | ||
</div> | ||
</div> | ||
`, | ||
footer: ` | ||
@@ -38,0 +72,0 @@ <div class="${footerPrefix}"> |
@@ -1,1 +0,1 @@ | ||
export default '2.0.3'; | ||
export default '2.0.4'; |
@@ -987,3 +987,3 @@ /* eslint-env mocha */ | ||
expect(render.calledOnce).toBe(true); | ||
expect(render.args[0][0]).toEqual({'isSimpleLayout': false, 'foo': 'bar'}); | ||
expect(render.args[0][0]).toEqual({'foo': 'bar'}); | ||
}); | ||
@@ -990,0 +990,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
5726013
209
13734