Vimeo ratio fixes
This commit is contained in:
parent
502d5977d7
commit
9c7e429b48
@ -419,16 +419,16 @@ const defaults = {
|
|||||||
title: false,
|
title: false,
|
||||||
speed: true,
|
speed: true,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
// These settings require a pro or premium account to work
|
// Whether the owner of the video has a Pro or Business account
|
||||||
sidedock: false,
|
// (which allows us to properly hide controls without CSS hacks, etc)
|
||||||
controls: false,
|
premium: false,
|
||||||
// Custom settings from Plyr
|
// Custom settings from Plyr
|
||||||
referrerPolicy: null, // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy
|
referrerPolicy: null, // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy
|
||||||
},
|
},
|
||||||
|
|
||||||
// YouTube plugin
|
// YouTube plugin
|
||||||
youtube: {
|
youtube: {
|
||||||
noCookie: false, // Whether to use an alternative version of YouTube without cookies
|
noCookie: true, // Whether to use an alternative version of YouTube without cookies
|
||||||
rel: 0, // No related vids
|
rel: 0, // No related vids
|
||||||
showinfo: 0, // Hide info
|
showinfo: 0, // Hide info
|
||||||
iv_load_policy: 3, // Hide annotations
|
iv_load_policy: 3, // Hide annotations
|
||||||
|
@ -229,16 +229,18 @@ class Listeners {
|
|||||||
|
|
||||||
// Delay the adding of classname until the focus has changed
|
// Delay the adding of classname until the focus has changed
|
||||||
// This event fires before the focusin event
|
// This event fires before the focusin event
|
||||||
this.focusTimer = setTimeout(() => {
|
if (event.type !== 'focusout') {
|
||||||
const focused = document.activeElement;
|
this.focusTimer = setTimeout(() => {
|
||||||
|
const focused = document.activeElement;
|
||||||
|
|
||||||
// Ignore if current focus element isn't inside the player
|
// Ignore if current focus element isn't inside the player
|
||||||
if (!elements.container.contains(focused)) {
|
if (!elements.container.contains(focused)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleClass(document.activeElement, player.config.classNames.tabFocus, true);
|
toggleClass(document.activeElement, player.config.classNames.tabFocus, true);
|
||||||
}, 10);
|
}, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global window & document listeners
|
// Global window & document listeners
|
||||||
@ -257,7 +259,7 @@ class Listeners {
|
|||||||
once.call(player, document.body, 'touchstart', this.firstTouch);
|
once.call(player, document.body, 'touchstart', this.firstTouch);
|
||||||
|
|
||||||
// Tab focus detection
|
// Tab focus detection
|
||||||
toggleListener.call(player, document.body, 'keydown focus blur', this.setTabFocus, toggle, false, true);
|
toggleListener.call(player, document.body, 'keydown focus blur focusout', this.setTabFocus, toggle, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container listeners
|
// Container listeners
|
||||||
@ -304,7 +306,7 @@ class Listeners {
|
|||||||
|
|
||||||
// Set a gutter for Vimeo
|
// Set a gutter for Vimeo
|
||||||
const setGutter = (ratio, padding, toggle) => {
|
const setGutter = (ratio, padding, toggle) => {
|
||||||
if (!player.isVimeo) {
|
if (!player.isVimeo || player.config.vimeo.premium) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +333,7 @@ class Listeners {
|
|||||||
|
|
||||||
const resized = () => {
|
const resized = () => {
|
||||||
clearTimeout(timers.resized);
|
clearTimeout(timers.resized);
|
||||||
|
|
||||||
timers.resized = setTimeout(setPlayerSize, 50);
|
timers.resized = setTimeout(setPlayerSize, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -354,7 +357,7 @@ class Listeners {
|
|||||||
// Set Vimeo gutter
|
// Set Vimeo gutter
|
||||||
setGutter(ratio, padding, isEnter);
|
setGutter(ratio, padding, isEnter);
|
||||||
|
|
||||||
// If not using native fullscreen, we need to check for resizes of viewport
|
// If not using the native browser fullscreen API, we need to check for resizes of viewport
|
||||||
if (!usingNative) {
|
if (!usingNative) {
|
||||||
if (isEnter) {
|
if (isEnter) {
|
||||||
on.call(player, window, 'resize', resized);
|
on.call(player, window, 'resize', resized);
|
||||||
|
@ -10,7 +10,6 @@ import { triggerEvent } from '../utils/events';
|
|||||||
import fetch from '../utils/fetch';
|
import fetch from '../utils/fetch';
|
||||||
import is from '../utils/is';
|
import is from '../utils/is';
|
||||||
import loadScript from '../utils/load-script';
|
import loadScript from '../utils/load-script';
|
||||||
import { extend } from '../utils/objects';
|
|
||||||
import { format, stripHTML } from '../utils/strings';
|
import { format, stripHTML } from '../utils/strings';
|
||||||
import { setAspectRatio } from '../utils/style';
|
import { setAspectRatio } from '../utils/style';
|
||||||
import { buildUrlParams } from '../utils/urls';
|
import { buildUrlParams } from '../utils/urls';
|
||||||
@ -71,21 +70,25 @@ const vimeo = {
|
|||||||
ready() {
|
ready() {
|
||||||
const player = this;
|
const player = this;
|
||||||
const config = player.config.vimeo;
|
const config = player.config.vimeo;
|
||||||
|
const { premium, referrerPolicy, ...frameParams } = config;
|
||||||
|
|
||||||
|
// If the owner has a pro or premium account then we can hide controls etc
|
||||||
|
if (premium) {
|
||||||
|
Object.assign(frameParams, {
|
||||||
|
controls: false,
|
||||||
|
sidedock: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get Vimeo params for the iframe
|
// Get Vimeo params for the iframe
|
||||||
const params = buildUrlParams(
|
const params = buildUrlParams({
|
||||||
extend(
|
loop: player.config.loop.active,
|
||||||
{},
|
autoplay: player.autoplay,
|
||||||
{
|
muted: player.muted,
|
||||||
loop: player.config.loop.active,
|
gesture: 'media',
|
||||||
autoplay: player.autoplay,
|
playsinline: !this.config.fullscreen.iosNative,
|
||||||
muted: player.muted,
|
...frameParams,
|
||||||
gesture: 'media',
|
});
|
||||||
playsinline: !this.config.fullscreen.iosNative,
|
|
||||||
},
|
|
||||||
config,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get the source URL or ID
|
// Get the source URL or ID
|
||||||
let source = player.media.getAttribute('src');
|
let source = player.media.getAttribute('src');
|
||||||
@ -101,20 +104,23 @@ const vimeo = {
|
|||||||
const src = format(player.config.urls.vimeo.iframe, id, params);
|
const src = format(player.config.urls.vimeo.iframe, id, params);
|
||||||
iframe.setAttribute('src', src);
|
iframe.setAttribute('src', src);
|
||||||
iframe.setAttribute('allowfullscreen', '');
|
iframe.setAttribute('allowfullscreen', '');
|
||||||
iframe.setAttribute('allowtransparency', '');
|
iframe.setAttribute('allow', 'autoplay,fullscreen,picture-in-picture');
|
||||||
iframe.setAttribute('allow', 'autoplay');
|
|
||||||
|
|
||||||
// Set the referrer policy if required
|
// Set the referrer policy if required
|
||||||
if (!is.empty(config.referrerPolicy)) {
|
if (!is.empty(referrerPolicy)) {
|
||||||
iframe.setAttribute('referrerPolicy', config.referrerPolicy);
|
iframe.setAttribute('referrerPolicy', referrerPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get poster, if already set
|
|
||||||
const { poster } = player;
|
|
||||||
// Inject the package
|
// Inject the package
|
||||||
const wrapper = createElement('div', { poster, class: player.config.classNames.embedContainer });
|
const { poster } = player;
|
||||||
wrapper.appendChild(iframe);
|
if (premium) {
|
||||||
player.media = replaceElement(wrapper, player.media);
|
iframe.setAttribute('poster', poster);
|
||||||
|
player.media = replaceElement(iframe, player.media);
|
||||||
|
} else {
|
||||||
|
const wrapper = createElement('div', { class: player.config.classNames.embedContainer, poster });
|
||||||
|
wrapper.appendChild(iframe);
|
||||||
|
player.media = replaceElement(wrapper, player.media);
|
||||||
|
}
|
||||||
|
|
||||||
// Get poster image
|
// Get poster image
|
||||||
fetch(format(player.config.urls.vimeo.api, id), 'json').then(response => {
|
fetch(format(player.config.urls.vimeo.api, id), 'json').then(response => {
|
||||||
|
@ -64,9 +64,10 @@ export function setAspectRatio(input) {
|
|||||||
wrapper.style.paddingBottom = `${padding}%`;
|
wrapper.style.paddingBottom = `${padding}%`;
|
||||||
|
|
||||||
// For Vimeo we have an extra <div> to hide the standard controls and UI
|
// For Vimeo we have an extra <div> to hide the standard controls and UI
|
||||||
if (this.isVimeo && this.supported.ui) {
|
if (this.isVimeo && !this.config.vimeo.premium && this.supported.ui) {
|
||||||
const height = 240;
|
const height = (100 / this.media.offsetWidth) * parseInt(window.getComputedStyle(this.media).paddingBottom, 10);
|
||||||
const offset = (height - padding) / (height / 50);
|
const offset = (height - padding) / (height / 50);
|
||||||
|
|
||||||
this.media.style.transform = `translateY(-${offset}%)`;
|
this.media.style.transform = `translateY(-${offset}%)`;
|
||||||
} else if (this.isHTML5) {
|
} else if (this.isHTML5) {
|
||||||
wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null);
|
wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null);
|
||||||
|
@ -71,8 +71,6 @@
|
|||||||
&.plyr--vimeo .plyr__video-wrapper {
|
&.plyr--vimeo .plyr__video-wrapper {
|
||||||
height: 0;
|
height: 0;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display correct icon
|
// Display correct icon
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user