-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat: two samples of integrating keyman videos onto help.keyman.com #1713
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
feat: two samples of integrating keyman videos onto help.keyman.com #1713
Conversation
mcdurdin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of not embedding the video until a img preview is clicked; we'll need to tweak the code slightly to get it to work across multiple thumbnails
(This may not be relevant with the requested change, but as a side note, the getElementById() call result was not checked -- if a page did not have a matching element, it would return null, causing an error on t.addEventListener line.)
cdn/dev/js/videoloader.js
Outdated
| let t = document.getElementById("keymanThumbnails"); | ||
| t.addEventListener("click", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to use querySelectorAll instead of getElementById, and match on any element that has the appropriate data-video attribute, so we can have multiple thumbnails in the same document. That means then we need to add an event listener for each element found, in a loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll look into this.
…into keyman-videos-website
…into keyman-videos-website
mcdurdin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. A few minor style changes requested!
developer/videos/index.md
Outdated
|
|
||
| * [Character Map + Touch Layout Editor integration improvements](https://www.youtube.com/watch?v=qoLpuah72kw) (2:15) | ||
|
|
||
| <img id="keymanThumbnails" data-video="https://www.youtube.com/embed/qoLpuah72kw" src="https://img.youtube.com/vi/qoLpuah72kw/maxresdefault.jpg" width="600px"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idshould not be repeated across multiple elements -- perhaps useclassinstead.- Instead of
keymanThumbnailscan we usevideo-thumbnail?
| <img id="keymanThumbnails" data-video="https://www.youtube.com/embed/qoLpuah72kw" src="https://img.youtube.com/vi/qoLpuah72kw/maxresdefault.jpg" width="600px"> | |
| <img class="video-thumbnail" data-video="https://www.youtube.com/embed/qoLpuah72kw" src="https://img.youtube.com/vi/qoLpuah72kw/maxresdefault.jpg" width="600px"> |
cdn/dev/js/videoloader.js
Outdated
| const thumbnailsList = document.querySelectorAll("#keymanThumbnails"); | ||
|
|
||
| window.addEventListener('DOMContentLoaded', () => { | ||
| thumbnailsList.forEach(each => { | ||
| each.addEventListener('click', () => { | ||
|
|
||
| if(each.hasAttribute('data-video')) { | ||
| let videoId = each.getAttribute('data-video') | ||
| each.outerHTML = "<iframe width='600' height='315' src='" + videoId + "' allowfullscreen></iframe>"; | ||
| } | ||
| }) | ||
| }) | ||
| }) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an IIFE to prevent pollution of global namespace:
| const thumbnailsList = document.querySelectorAll("#keymanThumbnails"); | |
| window.addEventListener('DOMContentLoaded', () => { | |
| thumbnailsList.forEach(each => { | |
| each.addEventListener('click', () => { | |
| if(each.hasAttribute('data-video')) { | |
| let videoId = each.getAttribute('data-video') | |
| each.outerHTML = "<iframe width='600' height='315' src='" + videoId + "' allowfullscreen></iframe>"; | |
| } | |
| }) | |
| }) | |
| }) | |
| (function() { | |
| const thumbnailsList = document.querySelectorAll(".video-thumbnail"); | |
| window.addEventListener('DOMContentLoaded', () => { | |
| thumbnailsList.forEach(thumbnail => { | |
| thumbnail.addEventListener('click', () => { | |
| if(thumbnail.hasAttribute('data-video')) { | |
| let videoId = thumbnail.getAttribute('data-video') | |
| thumbnail.outerHTML = "<iframe width='600' height='315' src='" + videoId + "' allowfullscreen></iframe>"; | |
| } | |
| }) | |
| }) | |
| }) | |
| })(); |
- I've also renamed the variable
eachtothumbnailto better represent what it is. - I renamed the selector from
#keymanThumbnailsto.video-thumbnail(a class rather than an id, and singular rather than plural, and 'video' instead of 'keyman' to clarify what it is for, and finally, using kebab-case instead of camelCase 😁)
|
Thanks @mcdurdin. I'm taking notes, this is so unfamiliar to me. 😅 |
mcdurdin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
follow: #1712
video sample:
video.mp4
<iframe>tag or use js onclick to set the<iframe>?-- updated on 09-Dec-2024
Fixes: #1712