Skip to content

Commit

Permalink
Add locked-media-poster
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 10, 2023
1 parent 5edbaa6 commit a75a1fa
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/assets/images/locked-media-poster.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/media.scss
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@
width: 100%;
}
}

.locked-media {
width: 100vw;
max-height: calc(100vh - 98px);
img {
height: 100%;
}
}
}

.authLinkWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
</div>
</aside>
<div class='sul-embed-body sul-embed-media' id='sul-embed-body'>
<div data-controller="locked-media-poster" data-action="auth-success@window->locked-media-poster#hide auth-denied@window->locked-media-poster#show" tabindex="-1" role="presentation" style="display: none">
<picture class="locked-media">
<%= image_tag 'locked-media-poster.svg', loading: 'lazy' %>
</picture>
</div>

<%= render Embed::MediaTagComponent.with_collection(resources_with_primary_file,
include_transcripts:,
druid:,
Expand Down
18 changes: 18 additions & 0 deletions app/javascript/src/controllers/locked_media_poster_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
// Display the lock if the video tag doesn't have a poster
show() {
if (!this.hasPoster())
this.element.style.display = 'flex'
}

hide() {
this.element.style.display = 'none'
}

hasPoster() {
const tags = document.querySelectorAll('video,audio')
return [...tags].some((tag) => tag.getAttribute('poster'))
}
}

0 comments on commit a75a1fa

Please sign in to comment.