MOBILE-3198 filter: Support start time in mediaplugin filter

main
Dani Palou 2019-10-22 11:57:01 +02:00
parent 4c03c0174a
commit 9a3e3b23e6
2 changed files with 37 additions and 3 deletions

View File

@ -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%';

View File

@ -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.
*