From 9a3e3b23e6a69cda7195e69fdc6c9562c9ff25d5 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 22 Oct 2019 11:57:01 +0200 Subject: [PATCH] MOBILE-3198 filter: Support start time in mediaplugin filter --- .../filter/mediaplugin/providers/handler.ts | 17 +++++++++++--- src/providers/utils/url.ts | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/addon/filter/mediaplugin/providers/handler.ts b/src/addon/filter/mediaplugin/providers/handler.ts index 405ba0672..ddbcfc652 100644 --- a/src/addon/filter/mediaplugin/providers/handler.ts +++ b/src/addon/filter/mediaplugin/providers/handler.ts @@ -17,6 +17,7 @@ import { Injectable } from '@angular/core'; import { CoreFilterDefaultHandler } from '@core/filter/providers/default-filter'; import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@core/filter/providers/filter'; import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreUrlUtilsProvider } from '@providers/utils/url'; /** * Handler to support the Multimedia filter. @@ -26,7 +27,8 @@ export class AddonFilterMediaPluginHandler extends CoreFilterDefaultHandler { name = 'AddonFilterMediaPluginHandler'; filterName = 'mediaplugin'; - constructor(private textUtils: CoreTextUtilsProvider) { + constructor(private textUtils: CoreTextUtilsProvider, + private urlUtils: CoreUrlUtilsProvider) { super(); } @@ -74,9 +76,18 @@ export class AddonFilterMediaPluginHandler extends CoreFilterDefaultHandler { return; } - const iframe = document.createElement('iframe'); + const iframe = document.createElement('iframe'), + params: any = {}; + + if (youtubeData.listId !== null) { + params.list = youtubeData.listId; + } + if (youtubeData.start !== null) { + params.start = youtubeData.start; + } + iframe.id = video.id; - iframe.src = 'https://www.youtube.com/embed/' + youtubeData.videoId; // Don't apply other params to align with Moodle web. + iframe.src = this.urlUtils.addParamsToUrl('https://www.youtube.com/embed/' + youtubeData.videoId, params); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowfullscreen', '1'); iframe.width = '100%'; diff --git a/src/providers/utils/url.ts b/src/providers/utils/url.ts index 295d54ae7..2aa7e8ff5 100644 --- a/src/providers/utils/url.ts +++ b/src/providers/utils/url.ts @@ -44,6 +44,29 @@ export class CoreUrlUtilsProvider { return url; } + /** + * Add params to a URL. + * + * @param url URL to add the params to. + * @param params Object with the params to add. + * @return URL with params. + */ + addParamsToUrl(url: string, params: {[key: string]: any}): string { + let separator = url.indexOf('?') != -1 ? '&' : '?'; + + for (const key in params) { + const value = params[key]; + + // Ignore objects. + if (typeof value != 'object') { + url += separator + key + '=' + value; + separator = '&'; + } + } + + return url; + } + /** * Given a URL and a text, return an HTML link. *