Skip to content

Commit 7eea8d0

Browse files
authored
Merge pull request #2668 from sciencehistory/fix_js_bug_in_oh_toc_page
Fix js bug in oh toc page
2 parents 6b0afbb + d65bbd7 commit 7eea8d0

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

app/components/oral_history/ohms_index_component.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,29 @@
4848
</div>
4949

5050
<% if index_point.synopsis.present? %>
51-
<p>
51+
<p class="highlight-matches">
5252
<%= index_point.synopsis %>
5353
</p>
5454
<% end %>
5555

5656

5757
<% if index_point.partial_transcript.present? %>
58-
<p class="attribute">
58+
<p class="attribute highlight-matches">
5959
<span class="attribute-label">Begins with</span>
6060
<%= format_partial_transcript(index_point.partial_transcript) %>
6161
</p>
6262
<% end %>
6363

6464
<% if index_point.all_keywords_and_subjects.present? %>
65-
<p class="attribute keywords">
65+
<p class="attribute keywords highlight-matches">
6666
<span class="attribute-label">Keywords</span>
6767
<% index_point.all_keywords_and_subjects.each_with_index do |keyword, index| %> <span class="oh-keyword"><%= keyword %></span> <% if index < index_point.all_keywords_and_subjects.length - 1 %><span class="keyword-seperator ml-1 mr-1"></span><% end %>
6868
<%- end -%>
6969
</p>
7070
<% end %>
7171

7272
<% if index_point.hyperlinks.present? %>
73-
<div class="attribute ohms-hyperlinks">
73+
<div class="attribute ohms-hyperlinks highlight-matches">
7474
<h4 class="attribute-label">Related <%= "URL".pluralize(index_point.hyperlinks.count) %></h4>
7575
<ul class="list-unstyled">
7676
<% index_point.hyperlinks.each do |hyperlink| %>

app/frontend/javascript/audio/ohms_search.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,33 +168,26 @@ Search.searchTranscript = function(query) {
168168
// Highlights hits in index results.
169169
Search.searchIndex = function(query) {
170170
var _self = this;
171-
172171
var reStr = new RegExp(_self.regexpStrForSearch(query), "gi");
173-
174-
return $(".ohms-index-point").map(function() {
172+
var returnValue = $(".ohms-index-point").map(function() {
175173
var section = $(this);
176-
177174
var targetId = section.attr("id");
178175
if (! targetId) { throw "can't record ohms search without finding a dom id " + section.get(0) }
179-
180-
var replacementMade = false;
181-
var original = section.html();
182-
var replacedContent = original.replace(reStr, function(str) {
183-
replacementMade = true;
184-
return _self.wrapInHighlight(str);
185-
});
186-
187-
if (replacementMade) {
188-
// there was a hit, so, highlight and include result
189-
190-
section.html(replacedContent);
191-
176+
if (section.html().match(reStr) != null) {
177+
// there was a hit. highlight and include result.
178+
section.find('.highlight-matches').each(function() {
179+
this.innerHTML = this.innerHTML.replace(reStr, function(str) {
180+
return _self.wrapInHighlight(str);
181+
});
182+
});
192183
return {
193184
tabId: 'ohIndexTab',
194-
targetId: targetId
185+
targetId: targetId // the id of the accordion card for this match:
195186
};
196187
}
197-
}).get() // plain array not jQuery object
188+
189+
}).get(); // plain array not jQuery object
190+
return returnValue;
198191
};
199192

200193
// Clears all search results state, restores to initial condition with no search

spec/system/oral_history_with_audio_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@
410410
click_on "Search"
411411
end
412412

413+
expect(page).to have_selector("*[data-trigger='linkClipboardCopy']")
414+
page.find("*[data-trigger='linkClipboardCopy']").click
415+
expect(page).to have_content("Copied to clipboard")
416+
413417
# ToC tab should be selected as it is first tab with results from search
414418
expect(page).to have_selector("#ohTocTab[aria-selected='true']")
415419
expect(page).to have_content(%r{Table of Contents — 1 / 7}i)

0 commit comments

Comments
 (0)