Skip to content

Commit

Permalink
Merge pull request #3738 from mlibrary/HELIO-4802/auto_headings_for_Y…
Browse files Browse the repository at this point in the history
…T_embeds

HELIO-4802 - auto-headings for YouTube video embeds
  • Loading branch information
sethaj authored Jan 28, 2025
2 parents 9e2c659 + 6fff15c commit 434bbe1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/services/embed_code_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def maybe_add_figcaption(node, file_set_presenter)
end

def heading_node(heading_tag_for_node, file_set_presenter)
# this whole "auto-heading" deal only applies to Able Player embeds (so, audio or video)
return nil unless file_set_presenter.audio? || file_set_presenter.video?
# this whole "auto-heading" deal only applies to media player embeds (so, audio, video or YouTube videos)
return nil unless file_set_presenter.audio? || file_set_presenter.video? || file_set_presenter.able_player_youtube_video? || file_set_presenter.youtube_player_video?
# https://uit.stanford.edu/accessibility/concepts/screen-reader-only-content
"<#{heading_tag_for_node} style=\"clip: rect(1px, 1px, 1px, 1px); clip-path: inset(50%); height: 1px; width: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute;\">Media player: #{file_set_presenter.embed_code_title}</#{heading_tag_for_node}>"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
data-able-player
data-skin="2020"
data-youtube-id="<%=@presenter.youtube_id%>"
data-heading-level="0" <%# see HELIO-4718, HELIO-4802 %>
data-allow-fullscreen=<%= params[:fs] == '1' ? "true" : "false" %>
data-youtube-nocookie="true" <%# removes "watch later as..." button %>
<%= raw file_set.closed_captions.present? ? 'data-transcript-div="video-transcript-container" data-lyrics-mode' : 'data-include-transcript="false"' %>>
Expand Down
Binary file modified spec/fixtures/fake_epub_with_embeds.epub
Binary file not shown.
4 changes: 3 additions & 1 deletion spec/services/embed_code_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@

ordered_members = [cover, epub, image_under_all_headings,
audio_top_level, audio_under_h1, audio_under_h2, audio_under_h3, audio_under_h4, audio_under_h5, audio_under_h6,
video_top_level, video_under_h1, video_under_h2, video_under_h3, video_under_h4, video_under_h5, video_under_h6]
video_top_level, video_under_h1, video_under_h2, video_under_h3, video_under_h4, video_under_h5, video_under_h6,
youtube_video] # we'll just test the YouTube video FileSet above as part of this `embeds_heading_testing.xhtml` chapter, embedded under a h2 to receive an automatic h2
monograph.ordered_members = ordered_members
monograph.save!
ordered_members.each { |item| item.save! }
Expand Down Expand Up @@ -585,6 +586,7 @@

expect(enhanced_file).to include("<h1 style=#{inline_sr_only_style}>Media player: #{video_top_level.title.first}</h1>")
expect(enhanced_file).to include("<h2 style=#{inline_sr_only_style}>Media player: #{video_under_h1.title.first}</h2>")
expect(enhanced_file).to include("<h2 style=#{inline_sr_only_style}>Media player: #{youtube_video.title.first}</h2>")
expect(enhanced_file).to include("<h3 style=#{inline_sr_only_style}>Media player: #{video_under_h2.title.first}</h3>")
expect(enhanced_file).to include("<h4 style=#{inline_sr_only_style}>Media player: #{video_under_h3.title.first}</h4>")
expect(enhanced_file).to include("<h5 style=#{inline_sr_only_style}>Media player: #{video_under_h4.title.first}</h5>")
Expand Down

0 comments on commit 434bbe1

Please sign in to comment.