Skip to content

Commit

Permalink
feat(shs-5693): add drupal befaviours to video with caption js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mari Nez committed Nov 25, 2024
1 parent bbe6a41 commit e69bbcf
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
// This causes issues when there is a video in a figure because the video no longer
// fills the entire space of the container.
// This JS sets a width of 100% to figures that contain videos.
const videos = document.querySelectorAll('.field-media-oembed-video');
(function (Drupal) {
Drupal.behaviors.videoWithCaptionBehavior = {
attach(context) {
const videos = context.querySelectorAll('.field-media-oembed-video');

if (videos && videos.length > 0) {
for (let i = 0; i < videos.length; i++) {
const video = videos[i];
if (video.parentNode && video.parentNode.parentNode && video.parentNode.parentNode.nodeName === 'FIGURE') {
const figure = video.parentNode.parentNode;
if (videos && videos.length > 0) {
for (let i = 0; i < videos.length; i++) {
const video = videos[i];
if (video.parentNode && video.parentNode.parentNode && video.parentNode.parentNode.nodeName === 'FIGURE') {
const figure = video.parentNode.parentNode;

if (figure.classList.contains('caption')) {
figure.style.width = '100%';
if (figure.classList.contains('caption')) {
figure.style.width = '100%';
}
}
}
}
}
}
}
},
};
}(Drupal));

0 comments on commit e69bbcf

Please sign in to comment.