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

16 lines
515 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');
blobs.forEach(blob => {
const lines = blob.querySelectorAll('.line');
lines.forEach(line => {
if (line.textContent.toLowerCase().includes(searchTerm)) {
line.classList.add(highlightLineClass);
}
});
});
};