debian-mirror-gitlab/app/assets/javascripts/search/highlight_blob_search_result.js

16 lines
485 B
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
export default (search = '') => {
2020-04-22 19:07:51 +05:30
const highlightLineClass = 'hll';
const contentBody = document.getElementById('content-body');
2021-03-11 19:13:27 +05:30
const searchTerm = search.toLowerCase();
2020-04-22 19:07:51 +05:30
const blobs = contentBody.querySelectorAll('.blob-result');
2021-03-08 18:12:59 +05:30
blobs.forEach((blob) => {
2020-04-22 19:07:51 +05:30
const lines = blob.querySelectorAll('.line');
2021-03-08 18:12:59 +05:30
lines.forEach((line) => {
2020-04-22 19:07:51 +05:30
if (line.textContent.toLowerCase().includes(searchTerm)) {
line.classList.add(highlightLineClass);
}
});
});
};