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

16 lines
488 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();
2021-11-11 11:23:49 +05:30
const blobs = contentBody.querySelectorAll('.js-blob-result');
2020-04-22 19:07:51 +05:30
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);
}
});
});
};