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

Closes #3891 Vimeo remote video is not supported as a Text on Media background #3981

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2599c46
feat: this file controls and initializes the video player
BaoNguyen09 Jan 8, 2025
898761a
feat: add vimeo player control js file to Text on Media libraries
BaoNguyen09 Jan 8, 2025
d023af4
docs: add new comments
BaoNguyen09 Jan 8, 2025
50db019
feat: handle vimeo video media in media bg
BaoNguyen09 Jan 8, 2025
45e1b8c
fix: use correct dataset name for vimeo id and get the correct ratio
BaoNguyen09 Jan 8, 2025
162ac16
fix: ensure vimeo api is loaded before proceeding
BaoNguyen09 Jan 8, 2025
0fb6509
Merge branch 'main' into 3891-vimeo-remote-video-is-not-supported-as-…
BaoNguyen09 Jan 14, 2025
da1e6ce
fix: change the video div tag name to distinguish with youtube video
BaoNguyen09 Jan 15, 2025
8bfc41f
Merge remote-tracking branch 'origin/3891-vimeo-remote-video-is-not-s…
BaoNguyen09 Jan 15, 2025
c018f41
fix: shorten the number of characters in the line to pass check on gi…
BaoNguyen09 Jan 15, 2025
302c02a
style: make the vimeo video fits into designated space
BaoNguyen09 Jan 15, 2025
375173d
fix: make the play/pause button works by using resolving promise corr…
BaoNguyen09 Jan 16, 2025
166fa78
fix: remove second iframe tag and correct the styling
BaoNguyen09 Jan 17, 2025
3ccb639
Revert "fix: remove second iframe tag and correct the styling"
BaoNguyen09 Jan 17, 2025
231bf13
fix: remove all control buttons in the embedded video
BaoNguyen09 Jan 17, 2025
eb225ee
fix: correctly target the iframe to apply style correctly
BaoNguyen09 Jan 17, 2025
89315ab
fix: modify the vimeo id to avoid the second iframe generated
BaoNguyen09 Jan 17, 2025
b9cb641
improve: provide more information when pause/play button is clicked f…
BaoNguyen09 Jan 17, 2025
2de6430
fix some minor bugs and refactor the code, ensuring consistent style
BaoNguyen09 Jan 17, 2025
2a2e3f3
Merge branch 'main' into 3891-vimeo-remote-video-is-not-supported-as-…
BaoNguyen09 Jan 17, 2025
aa776d6
fix: ProboCi/Script/Run ESlint tests
BaoNguyen09 Jan 21, 2025
be9cc7d
fix: fix: ProboCi/Script/Run ESlint tests (2)
BaoNguyen09 Jan 21, 2025
ad1940e
fix: ProboCi/Script/Run ESlint tests (3)
BaoNguyen09 Jan 21, 2025
6927d6a
fix: ProboCi/Script/Run ESlint tests (4)
BaoNguyen09 Jan 21, 2025
e2823a9
fix: ProboCi/Script/Run ESlint tests (5)
BaoNguyen09 Jan 21, 2025
41cc2c9
Update modules/custom/az_paragraphs/az_paragraphs_text_media/js/az_pa…
BaoNguyen09 Jan 23, 2025
9ee9d96
Update modules/custom/az_paragraphs/az_paragraphs_text_media/js/az_pa…
BaoNguyen09 Jan 23, 2025
8d21eac
Update modules/custom/az_paragraphs/az_paragraphs_text_media/js/az_pa…
BaoNguyen09 Jan 23, 2025
731eb2d
Update modules/custom/az_paragraphs/az_paragraphs_text_media/js/az_pa…
BaoNguyen09 Jan 23, 2025
451c927
Update modules/custom/az_paragraphs/az_paragraphs_text_media/js/az_pa…
BaoNguyen09 Jan 23, 2025
2461ba6
Merge branch 'main' into 3891-vimeo-remote-video-is-not-supported-as-…
BaoNguyen09 Jan 23, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ az_paragraphs_text_media.youtube:
dependencies:
- core/jquery
- core/drupalSettings

az_paragraphs_text_media.vimeo:
js:
js/az_paragraphs_az_text_media_vimeo.js: {}
dependencies:
- core/jquery
- core/drupalSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
(($, Drupal) => {
Drupal.behaviors.az_vimeo_video_bg = {
attach(context, settings) {
if (window.screen && window.screen.width > 768) {
// @see https://developer.vimeo.com/player/sdk/basics
// Defaults
const defaults = {
vimeoId: '',
width: $(window).width(),
ratio: 16 / 9,
autoplay: true,
background: true,
loop: true,
playButtonClass: 'az-video-play',
pauseButtonClass: 'az-video-pause',
minimumSupportedWidth: 600,
};
const { bgVideos } = settings.azFieldsMedia;
const bgVideoParagraphs = document.getElementsByClassName(
'az-js-vimeo-video-background',
);
// Load Vimeo API
const tag = document.createElement('script');
tag.src = 'https://player.vimeo.com/api/player.js';
document.head.appendChild(tag);

// Methods
// Ensure Vimeo API is loaded before proceeding
tag.onload = () => {
$.each(bgVideoParagraphs, (index) => {
const thisContainer = bgVideoParagraphs[index];
const parentParagraph = thisContainer.parentNode;
const vimeoId = thisContainer.dataset.vimeoId2;
bgVideos[vimeoId] = $.extend({}, defaults, thisContainer);
const options = bgVideos[vimeoId];
const videoPlayer =
thisContainer.getElementsByClassName('az-video-player')[0];
const VimeoPlayer = window.Vimeo;

// Initialize Vimeo Player
thisContainer.player = new VimeoPlayer.Player(videoPlayer, {
id: vimeoId,
width: options.width,
height: Math.ceil(options.width / options.ratio),
autoplay: options.autoplay,
background: options.background,
muted: options.mute,
loop: options.loop,
});

// Event Listeners
thisContainer.player.on('play', () => {
parentParagraph.classList.add('az-video-playing');
parentParagraph.classList.remove('az-video-paused');
});

thisContainer.player.on('pause', () => {
parentParagraph.classList.add('az-video-paused');
parentParagraph.classList.remove('az-video-playing');
});

thisContainer.player.on('ended', () => {
if (options.repeat) {
thisContainer.player.setCurrentTime(0).then(() => {
thisContainer.player.play();
});
}
});

// Play Button
const playButton =
bgVideoParagraphs[index].getElementsByClassName(
'az-video-play',
)[0];
playButton.addEventListener('click', (event) => {
event.preventDefault();
bgVideoParagraphs[index].player
.play()
.then(() => {
// the video is playing
})
.catch((error) => {
switch (error.name) {
case 'PasswordError':
window.alert('the video is password-protected');
break;
case 'PrivacyError':
window.alert('the video is private');
break;
default:
console.log(`Some errors occurred: ${error.name}`);
break;
}
});
});

// Pause Button
const pauseButton =
bgVideoParagraphs[index].getElementsByClassName(
'az-video-pause',
)[0];
pauseButton.addEventListener('click', (event) => {
event.preventDefault();
bgVideoParagraphs[index].player
.pause()
.then(() => {
// the video is paused
})
.catch((error) => {
switch (error.name) {
case 'PasswordError':
window.alert('the video is password-protected');
break;
case 'PrivacyError':
window.alert('the video is private');
break;
default:
window.alert(`Some errors occurred: ${error.name}`);
break;
}
});
});
});
};

// Resize Logic
const setDimensions = (container) => {
const parentParagraph = container.parentNode;
let parentHeight = parentParagraph.offsetHeight;
parentHeight = `${parentHeight.toString()}px`;
container.style.height = parentHeight;
const { style } = container.dataset;
if (style === 'bottom') {
container.style.top = 0;
}
const thisPlayer =
container.getElementsByClassName('az-video-player')[0].firstChild;
if (thisPlayer === null) {
return;
}
thisPlayer.style.zIndex = -100;
const vimeoId = container.dataset.vimeoId2;
const width = container.offsetWidth;
const height = container.offsetHeight;
const { ratio } = bgVideos[vimeoId];
const pWidth = Math.ceil(height * ratio); // get new player width
const pHeight = Math.ceil(width / ratio); // get new player height
let widthMinuspWidthdividedbyTwo = (width - pWidth) / 2;
widthMinuspWidthdividedbyTwo = `${widthMinuspWidthdividedbyTwo.toString()}px`;
let pHeightRatio = (height - pHeight) / 2;
pHeightRatio = `${pHeightRatio.toString()}px`;
// when screen aspect ratio differs from video,
// video must center and underlay one dimension.
if (width / ratio < height) {
// if new video height < window height (gap underneath)
thisPlayer.width = pWidth;
thisPlayer.height = height;
thisPlayer.style.left = widthMinuspWidthdividedbyTwo;
thisPlayer.style.top = 0;
// player width is greater, offset left; reset top
} else {
// new video width < window width (gap to right)
// get new player height
thisPlayer.height = pHeight;
thisPlayer.width = width;
thisPlayer.style.top = pHeightRatio;
thisPlayer.style.left = 0;
}
};

// Resize handler updates width, height and offset
// of player after resize/init.
const resize = () => {
$.each(bgVideoParagraphs, (index) => {
setDimensions(bgVideoParagraphs[index]);
});
};

// Event Handlers
$(window).on('load', () => {
resize();
});
$(window).on('resize.bgVideo', () => {
resize();
});
}
},
};
})(jQuery, Drupal, drupalSettings);
Loading
Loading