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

16 lines
519 B
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
export default () => {
const highlightLineClass = 'hll';
const contentBody = document.getElementById('content-body');
const searchTerm = contentBody.querySelector('.js-search-input').value.toLowerCase();
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);
}
});
});
};