Skip to content

Commit

Permalink
Add click-to-load functionality for historic YouTube videos.
Browse files Browse the repository at this point in the history
see e.g. /schedule/2014/176-a-brief-guide-to-dog-behaviour-and-human-interaction

Fixes #1298.
  • Loading branch information
lukegb committed Jan 28, 2024
1 parent 7e84dcb commit cbb8a51
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
40 changes: 34 additions & 6 deletions css/_video.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,40 @@
height: 0;
margin-bottom: 15px;
padding-bottom: (math.div(100%, 16) * 9);

iframe,
.content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}

.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.youtube-wait-for-click {
&:not(.youtube-wait-for-click-has-js) {
display: none;
}
}

.youtube-wait-for-click-content {
background-color: #1e1e1e;
color: #c8c8c8;
text-align: center;

display: flex;
flex-direction: column;
justify-content: center;

a {
color: #c8c8c8;
}

.youtube-wait-for-click-button {
background-color: #1e1e1e;
color: #c8c8c8;
border: 2px solid #c8c8c8;
margin: 0 auto;
}
}
10 changes: 10 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@ $(() => {

$('#user_content_form #type').on('change', displayWorkshopFieldsIfRequired);
displayWorkshopFieldsIfRequired();
});

$(() => {
document.querySelectorAll('.youtube-wait-for-click').forEach((parentEl) => {
parentEl.classList.add('youtube-wait-for-click-has-js');
parentEl.querySelector('.youtube-wait-for-click-button').addEventListener('click', () => {
parentEl.replaceChildren(parentEl.querySelector('template').content.cloneNode(true));
return false;
});
});
});
14 changes: 11 additions & 3 deletions templates/schedule/historic/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ <h3>Video</h3>
mozallowfullscreen="true" allowfullscreen></iframe>
<p>View this video <a href="{{ event.video.archiveorg }}">on the Internet Archive</a>.</p>
{% elif event.video.youtube %}
<iframe src="{{event.video.youtube|replace('youtube.com/watch?v=', 'youtube.com/embed/')}}"
width="100%" height="500px" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<div class="youtube-wait-for-click video-container">
<template>
<iframe src="{{event.video.youtube|replace('youtube.com/watch?v=', 'youtube.com/embed/')}}"
width="100%" height="500px" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</template>
<div class="youtube-wait-for-click-content content">
<p>This video is hosted on YouTube. To load the video, you'll need to agree to YouTube's <a href="https://www.youtube.com/t/privacy">privacy policy</a>.</p>
<button class="youtube-wait-for-click-button">Continue</button>
</div>
</div>
<p>View this video <a href="{{ event.video.youtube }}">on YouTube</a>.</p>
{% endif %}
</div>
Expand Down

0 comments on commit cbb8a51

Please sign in to comment.