Commit af890182 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Fix archive.org player height

parent 7fd35f2a
......@@ -10,6 +10,23 @@ const regex = {
};
export default regex;
export function getIframeDimensions(...args) {
// Since we can't tell the difference between video and audio embed players from the URL, lets use the width/height
// provided by archive.org's iframe HTML code.
const [large, , width, height] = args;
if (width && height) {
return {
width,
height,
};
}
return {
width: large ? 640 : 480,
height: large ? 360 : 270,
};
}
/**
* Configuration for HTML iframe's `sandbox` attribute
* @type {useSandbox: boolean, sandboxAttributes: string[]}
......
......@@ -64,13 +64,20 @@ function getIframeDimensions(large) {
* @param url
* @returns { boolean | { providerId: string, sandboxAttributes: string[], useSandbox: boolean, validUrl: string }}
*/
export function validateIframeUrl(url, large = true) {
export function validateIframeUrl(
url,
large = true,
width = null,
height = null
) {
if (!url) {
return {
validUrl: false,
};
}
console.log('wid', width, height);
const providersKeys = Object.keys(supportedProviders);
for (let pi = 0; pi < providersKeys.length; pi += 1) {
const providerName = providersKeys[pi];
......@@ -83,7 +90,9 @@ export function validateIframeUrl(url, large = true) {
provider,
'getIframeDimensions',
large,
url
url,
width,
height
);
if (iframeDimensions === null) {
iframeDimensions = getIframeDimensions(large);
......
......@@ -59,13 +59,20 @@ export default ({
transformTags: {
iframe: (tagName, attribs) => {
const srcAtty = attribs.src;
const widthAtty = attribs.width;
const heightAtty = attribs.height;
const {
validUrl,
useSandbox,
sandboxAttributes,
width,
height,
} = validateEmbbeddedPlayerIframeUrl(srcAtty, large);
} = validateEmbbeddedPlayerIframeUrl(
srcAtty,
large,
widthAtty,
heightAtty
);
if (validUrl !== false) {
const iframe = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment