v1.18.x
Barış Soner Uşaklı 6 years ago
parent dff86b1ac9
commit d880a7ade0

@ -138,7 +138,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
if (!searchQuery) { if (!searchQuery) {
return; return;
} }
searchQuery = utils.escapeHTML(searchQuery);
var regexStr = searchQuery.replace(/^"/, '').replace(/"$/, '').trim().split(' ').join('|'); var regexStr = searchQuery.replace(/^"/, '').replace(/"$/, '').trim().split(' ').join('|');
var regex = new RegExp('(' + regexStr + ')', 'gi'); var regex = new RegExp('(' + regexStr + ')', 'gi');
@ -151,11 +151,15 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
nested.push($('<div />').append($(this))); 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) { nested.forEach(function (nestedEl, i) {
result.html(result.html().replace('<!-- ' + i + ' -->', nested[i].html())); result.html(result.html().replace('<!-- ' + i + ' -->', function () {
} return nestedEl.html();
}));
});
}); });
$('.search-result-text').find('img:not(.not-responsive)').addClass('img-responsive'); $('.search-result-text').find('img:not(.not-responsive)').addClass('img-responsive');

@ -7,24 +7,14 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
}; };
Search.query = function (data, callback) { Search.query = function (data, callback) {
var term = data.term;
// Detect if a tid was specified // Detect if a tid was specified
var topicSearch = term.match(/^in:topic-([\d]+) /); var topicSearch = data.term.match(/^in:topic-([\d]+) /);
if (!topicSearch) { if (!topicSearch) {
term = term.replace(/^[ ?#]*/, '');
try {
term = encodeURIComponent(term);
} catch (e) {
return app.alertError('[[error:invalid-search-term]]');
}
ajaxify.go('search?' + createQueryString(data)); ajaxify.go('search?' + createQueryString(data));
callback(); callback();
} else { } else {
var cleanedTerm = term.replace(topicSearch[0], ''); var cleanedTerm = data.term.replace(topicSearch[0], '');
var tid = topicSearch[1]; var tid = topicSearch[1];
if (cleanedTerm.length > 0) { if (cleanedTerm.length > 0) {
@ -36,8 +26,15 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
function createQueryString(data) { function createQueryString(data) {
var searchIn = data.in || 'titlesposts'; var searchIn = data.in || 'titlesposts';
var postedBy = data.by || ''; var postedBy = data.by || '';
var term = data.term.replace(/^[ ?#]*/, '');
try {
term = encodeURIComponent(term);
} catch (e) {
return app.alertError('[[error:invalid-search-term]]');
}
var query = { var query = {
term: data.term, term: term,
in: searchIn, in: searchIn,
}; };

Loading…
Cancel
Save