mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: move quick search into search module
so it can be used directly
This commit is contained in:
@@ -479,7 +479,6 @@ app.cacheBuster = null;
|
|||||||
app.enableTopicSearch = function (options) {
|
app.enableTopicSearch = function (options) {
|
||||||
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 searchTimeoutId = 0;
|
var searchTimeoutId = 0;
|
||||||
var currentVal = inputEl.val();
|
var currentVal = inputEl.val();
|
||||||
inputEl.off('keyup').on('keyup', function () {
|
inputEl.off('keyup').on('keyup', function () {
|
||||||
@@ -496,24 +495,12 @@ app.cacheBuster = null;
|
|||||||
return quickSearchResults.addClass('hidden');
|
return quickSearchResults.addClass('hidden');
|
||||||
}
|
}
|
||||||
require(['search'], function (search) {
|
require(['search'], function (search) {
|
||||||
var data = {
|
search.quick({
|
||||||
term: inputEl.val(),
|
term: inputEl.val(),
|
||||||
in: 'titles',
|
in: 'titles',
|
||||||
searchOnly: 1,
|
}, {
|
||||||
};
|
template: options.template,
|
||||||
$(window).trigger('action:search.quick', { data: data });
|
resultEl: quickSearchResults,
|
||||||
search.api(data, function (data) {
|
|
||||||
data.posts.forEach(function (p) {
|
|
||||||
p.snippet = utils.escapeHTML($('<div>' + p.content + '</div>').text().slice(0, 80) + '...');
|
|
||||||
});
|
|
||||||
app.parseAndTranslate(template, data, function (html) {
|
|
||||||
if (html.length) {
|
|
||||||
html.find('.timeago').timeago();
|
|
||||||
quickSearchResults.html(html).removeClass('hidden').show();
|
|
||||||
} else {
|
|
||||||
quickSearchResults.html('').addClass('hidden');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|||||||
@@ -33,6 +33,28 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Search.quick = function (query, options, callback) {
|
||||||
|
callback = callback || function () {};
|
||||||
|
var template = options.template || 'partials/quick-search-results';
|
||||||
|
$(window).trigger('action:search.quick', { data: query });
|
||||||
|
query.searchOnly = 1;
|
||||||
|
Search.api(query, function (data) {
|
||||||
|
data.posts.forEach(function (p) {
|
||||||
|
p.snippet = utils.escapeHTML($('<div>' + p.content + '</div>').text().slice(0, 80) + '...');
|
||||||
|
});
|
||||||
|
app.parseAndTranslate(template, data, function (html) {
|
||||||
|
if (html.length) {
|
||||||
|
html.find('.timeago').timeago();
|
||||||
|
options.resultEl.html(html).removeClass('hidden').show();
|
||||||
|
} else {
|
||||||
|
options.resultEl.html('').addClass('hidden');
|
||||||
|
}
|
||||||
|
$(window).trigger('action:search.quick.complete', { });
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function createQueryString(data) {
|
function createQueryString(data) {
|
||||||
var searchIn = data.in || 'titlesposts';
|
var searchIn = data.in || 'titlesposts';
|
||||||
var postedBy = data.by || '';
|
var postedBy = data.by || '';
|
||||||
|
|||||||
Reference in New Issue
Block a user