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

Vimeo fix #1900

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Used named patterns instead of numbers
djamg committed Oct 10, 2023
commit eab1da08262571df60aa732e4b3bb4b94f1a9a0e
17 changes: 11 additions & 6 deletions funnel/assets/js/utils/embedvideo.js
Original file line number Diff line number Diff line change
@@ -8,18 +8,21 @@ const Video = {
*/
getVideoTypeAndId(url) {
const regexMatch = url.match(
/(http:|https:|)\/\/(player.|www.)?(y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?(\?h=([^&]+))?/
/(http:|https:|)\/\/(player.|www.)?(?<service>y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?(?<videoId>[A-Za-z0-9._%-]*)(&\S+)?(\?h=(?<paramId>[^&]+))?/
);
let type = '';
if (regexMatch && regexMatch.length > 5) {
if (regexMatch[3].indexOf('youtu') > -1 || regexMatch[3].indexOf('y2u') > -1) {
if (
regexMatch.groups.service.indexOf('youtu') > -1 ||
regexMatch.groups.service.indexOf('y2u') > -1
) {
type = 'youtube';
} else if (regexMatch[3].indexOf('vimeo') > -1) {
} else if (regexMatch.groups.service.indexOf('vimeo') > -1) {
type = 'vimeo';
return {
type,
videoId: regexMatch[6],
paramId: regexMatch[9],
videoId: regexMatch.groups.videoId,
paramId: regexMatch.groups.paramId,
};
}
return {
@@ -38,7 +41,9 @@ const Video = {
if (type === 'youtube') {
videoEmbedUrl = `<iframe src='//www.youtube.com/embed/${videoId}' frameborder='0' allowfullscreen></iframe>`;
} else if (type === 'vimeo') {
videoEmbedUrl = `<iframe src='https://player.vimeo.com/video/${videoId}?h=${paramId}' frameborder='0' allowfullscreen></iframe>`;
videoEmbedUrl = `<iframe src='https://player.vimeo.com/video/${videoId}${
paramId ? `?h=${paramId}` : ''
}' frameborder='0' allowfullscreen></iframe>`;
}
if (videoEmbedUrl) {
videoWrapper.innerHTML = videoEmbedUrl;