mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 20:41:17 +01:00
feat: parse quick search tpl even if no results
allows showing "no results found" in theme
This commit is contained in:
@@ -570,6 +570,7 @@ app.cacheBuster = null;
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.enableTopicSearch = function (options) {
|
app.enableTopicSearch = function (options) {
|
||||||
|
console.log('enableTopicSearch', options, new Error('a').stack);
|
||||||
var quickSearchResults = options.resultEl;
|
var quickSearchResults = options.resultEl;
|
||||||
var inputEl = options.inputEl;
|
var inputEl = options.inputEl;
|
||||||
var template = options.template || 'partials/quick-search-results';
|
var template = options.template || 'partials/quick-search-results';
|
||||||
@@ -595,16 +596,16 @@ app.cacheBuster = null;
|
|||||||
};
|
};
|
||||||
$(window).trigger('action:search.quick', { data: data });
|
$(window).trigger('action:search.quick', { data: data });
|
||||||
search.api(data, function (data) {
|
search.api(data, function (data) {
|
||||||
if (!data.matchCount) {
|
|
||||||
quickSearchResults.html('').addClass('hidden');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data.posts.forEach(function (p) {
|
data.posts.forEach(function (p) {
|
||||||
p.snippet = utils.escapeHTML($(p.content).text().slice(0, 80) + '...');
|
p.snippet = utils.escapeHTML($(p.content).text().slice(0, 80) + '...');
|
||||||
});
|
});
|
||||||
app.parseAndTranslate(template, data, function (html) {
|
app.parseAndTranslate(template, data, function (html) {
|
||||||
html.find('.timeago').timeago();
|
if (html.length) {
|
||||||
quickSearchResults.html(html).removeClass('hidden').show();
|
html.find('.timeago').timeago();
|
||||||
|
quickSearchResults.html(html).removeClass('hidden').show();
|
||||||
|
} else {
|
||||||
|
quickSearchResults.html('').addClass('hidden');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user