diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:42 +0300 |
commit | e4bf776a8829e5186a0f63603c0be627b891d80e (patch) | |
tree | 537fe714bd336bfee9f30b101a5072950a04a62a /app/assets/javascripts/pages | |
parent | 1635eacd2a9293cd04d21e82def6e2c14ed01242 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/pages')
-rw-r--r-- | app/assets/javascripts/pages/search/show/highlight_blob_search_result.js | 15 | ||||
-rw-r--r-- | app/assets/javascripts/pages/search/show/search.js | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js b/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js new file mode 100644 index 00000000000..e17c87735b4 --- /dev/null +++ b/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js @@ -0,0 +1,15 @@ +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); + } + }); + }); +}; diff --git a/app/assets/javascripts/pages/search/show/search.js b/app/assets/javascripts/pages/search/show/search.js index dff9d855b67..4050f2f13f1 100644 --- a/app/assets/javascripts/pages/search/show/search.js +++ b/app/assets/javascripts/pages/search/show/search.js @@ -5,9 +5,11 @@ import Api from '~/api'; import { __ } from '~/locale'; import Project from '~/pages/projects/project'; import refreshCounts from './refresh_counts'; +import setHighlightClass from './highlight_blob_search_result'; export default class Search { constructor() { + setHighlightClass(); const $groupDropdown = $('.js-search-group-dropdown'); const $projectDropdown = $('.js-search-project-dropdown'); |