From 05978221ca74984d26e1766a01a63dfb43644442 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 18 May 2018 09:32:25 +0200 Subject: [PATCH] MOBILE-2412 vimeo: Fix params and width/height in vimeo videos --- src/directives/format-text.ts | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index d024f1440..f4144e731 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -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; - } - if (iframe.height) { - newUrl = newUrl + '&height=' + iframe.height; + width = iframe.width; + } else { + width = this.getElementWidth(iframe); + if (!width) { + width = window.innerWidth; + } } - 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; + } } } }