Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add locked-media-poster #1721

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))
}
}