mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
dont search empty string, get 20 tags instead of 10
This commit is contained in:
@@ -14,6 +14,11 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = 0;
|
||||
}
|
||||
|
||||
if (!$('#tag-search').val().length) {
|
||||
return;
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(function() {
|
||||
socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function(err, results) {
|
||||
if (err) {
|
||||
|
||||
@@ -521,6 +521,12 @@ SocketTopics.search = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketTopics.searchAndLoadTags = function(socket, data, callback) {
|
||||
if (!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
if (!data.query || !data.query.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
topics.searchTags(data, function(err, tags) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -222,14 +222,15 @@ module.exports = function(Topics) {
|
||||
return callback(null, tags);
|
||||
}
|
||||
data.query = data.query.toLowerCase();
|
||||
|
||||
var matches = [];
|
||||
for(var i=0; i<tags.length; ++i) {
|
||||
if (tags[i].toLowerCase().indexOf(data.query) === 0) {
|
||||
if (tags[i].toLowerCase().startsWith(data.query)) {
|
||||
matches.push(tags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
matches = matches.slice(0, 10).sort(function(a, b) {
|
||||
matches = matches.slice(0, 20).sort(function(a, b) {
|
||||
return a > b;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user