Skip to content

Commit

Permalink
closes #6771
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Sep 18, 2018
1 parent dff86b1 commit d880a7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
14 changes: 9 additions & 5 deletions public/src/client/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
if (!searchQuery) {
return;
}

searchQuery = utils.escapeHTML(searchQuery);
var regexStr = searchQuery.replace(/^"/, '').replace(/"$/, '').trim().split(' ').join('|');
var regex = new RegExp('(' + regexStr + ')', 'gi');

Expand All @@ -151,11 +151,15 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
nested.push($('<div />').append($(this)));
});

result.html(result.html().replace(regex, '<strong>$1</strong>'));
result.html(result.html().replace(regex, function (match, p1) {
return '<strong>' + p1 + '</strong>';
}));

for (var i = 0, ii = nested.length; i < ii; i += 1) {
result.html(result.html().replace('<!-- ' + i + ' -->', nested[i].html()));
}
nested.forEach(function (nestedEl, i) {
result.html(result.html().replace('<!-- ' + i + ' -->', function () {
return nestedEl.html();
}));
});
});

$('.search-result-text').find('img:not(.not-responsive)').addClass('img-responsive');
Expand Down
23 changes: 10 additions & 13 deletions public/src/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,14 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
};

Search.query = function (data, callback) {
var term = data.term;

// Detect if a tid was specified
var topicSearch = term.match(/^in:topic-([\d]+) /);
var topicSearch = data.term.match(/^in:topic-([\d]+) /);

if (!topicSearch) {
term = term.replace(/^[ ?#]*/, '');

try {
term = encodeURIComponent(term);
} catch (e) {
return app.alertError('[[error:invalid-search-term]]');
}

ajaxify.go('search?' + createQueryString(data));
callback();
} else {
var cleanedTerm = term.replace(topicSearch[0], '');
var cleanedTerm = data.term.replace(topicSearch[0], '');
var tid = topicSearch[1];

if (cleanedTerm.length > 0) {
Expand All @@ -36,8 +26,15 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
function createQueryString(data) {
var searchIn = data.in || 'titlesposts';
var postedBy = data.by || '';
var term = data.term.replace(/^[ ?#]*/, '');
try {
term = encodeURIComponent(term);
} catch (e) {
return app.alertError('[[error:invalid-search-term]]');
}

var query = {
term: data.term,
term: term,
in: searchIn,
};

Expand Down

0 comments on commit d880a7a

Please sign in to comment.