Skip to content

Commit

Permalink
Add link to /search/?q= in search preview
Browse files Browse the repository at this point in the history
  • Loading branch information
meel-hd committed Oct 3, 2024
1 parent 772f9ff commit e896acd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions weblate/static/editor/tools/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(document).ready(() => {
if (!results || results.length === 0) {
$searchPreview.text(gettext("No results found"));
} else {
showResults(results, response.count);
showResults(results, response.count, searchQuery);
}
},
});
Expand Down Expand Up @@ -91,15 +91,19 @@ $(document).ready(() => {
* Handles the search results and displays them in the preview element.
* @param {any} results fetched search results
* @param {number} count The number of search results
* @param {string} searchQuery The user typed search
* @returns void
*/
function showResults(results, count) {
function showResults(results, count, searchQuery) {
// Show the number of results
if (count > 0) {
const t = ngettext("%s matching string", "%s matching strings", count);
$searchPreview.append(
`<h4 id="results-num">${interpolate(t, [count])}</h4>`,
const t = interpolate(
ngettext("%s matching string", "%s matching strings", count),
[count],
);
const searchUrl = `/search/?q=${encodeURI(searchQuery)}`;
const resultsNumber = `<a href="${searchUrl}" target="_blank" rel="noopener noreferrer" id="results-num">${t}</a>`;
$searchPreview.append(resultsNumber);
} else {
$("#results-num").remove();
}
Expand Down
2 changes: 1 addition & 1 deletion weblate/static/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2164,5 +2164,5 @@ tbody.warning {
font-size: 16px;
font-weight: bold;
color: #1fa385;
text-align: end;
margin: 10px;
}

0 comments on commit e896acd

Please sign in to comment.