2
0
Fork 0

Merge pull request #1315 from dpalou/MOBILE-2412

MOBILE-2412 vimeo: Fix params and width/height in vimeo videos
main
Juan Leyva 2018-05-18 12:16:01 +02:00 committed by GitHub
commit f602bafec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 7 deletions

View File

@ -436,18 +436,40 @@ export class CoreFormatTextDirective implements OnChanges {
if (iframe.src && canTreatVimeo) {
// Check if it's a Vimeo video. If it is, use the wsplayer script instead to make restricted videos work.
const matches = iframe.src.match(/https?:\/\/player\.vimeo\.com\/video\/([^\/]*)/);
const matches = iframe.src.match(/https?:\/\/player\.vimeo\.com\/video\/([0-9]+)/);
if (matches && matches[1]) {
let newUrl = this.textUtils.concatenatePaths(site.getURL(), '/media/player/vimeo/wsplayer.php?video=') +
const newUrl = this.textUtils.concatenatePaths(site.getURL(), '/media/player/vimeo/wsplayer.php?video=') +
matches[1] + '&token=' + site.getToken();
// Width and height are mandatory, we need to calculate them.
let width, height;
if (iframe.width) {
newUrl = newUrl + '&width=' + iframe.width;
width = iframe.width;
} else {
width = this.getElementWidth(iframe);
if (!width) {
width = window.innerWidth;
}
if (iframe.height) {
newUrl = newUrl + '&height=' + iframe.height;
}
iframe.src = newUrl;
if (iframe.height) {
height = iframe.height;
} else {
height = this.getElementHeight(iframe);
if (!height) {
height = width;
}
}
// Always include the width and height in the URL.
iframe.src = newUrl + '&width=' + width + '&height=' + height;
if (!iframe.width) {
iframe.width = width;
}
if (!iframe.height) {
iframe.height = height;
}
}
}
}