Skip to content

Commit 597a636

Browse files
committed
Fix single source for video providers
1 parent 17ae3e6 commit 597a636

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

scripts/h5peditor-av.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,11 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
318318
var defaultQualityName = H5PEditor.t('core', 'videoQualityDefaultLabel', { ':index': index + 1 });
319319
var qualityName = (file.metadata && file.metadata.qualityName) ? file.metadata.qualityName : defaultQualityName;
320320

321-
// Check if source is YouTube
322-
var youtubeRegex = C.providers.filter(function (provider) {
323-
return provider.name === 'YouTube';
324-
})[0].regexp;
325-
var isYoutube = file.path && file.path.match(youtubeRegex);
321+
// Check if source is provider (Vimeo, YouTube, Panopto)
322+
const isProvider = file.path && C.findProvider(file.path);
326323

327324
// Only allow single source if YouTube
328-
if (isYoutube) {
325+
if (isProvider) {
329326
// Remove all other files except this one
330327
that.$files.children().each(function (i) {
331328
if (i !== that.updateIndex) {
@@ -339,7 +336,7 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
339336
// This is now the first and only file
340337
index = 0;
341338
}
342-
this.$add.toggleClass('hidden', !!isYoutube);
339+
this.$add.toggleClass('hidden', isProvider);
343340

344341
// If updating remove and recreate element
345342
if (that.updateIndex !== undefined) {
@@ -349,7 +346,7 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
349346
}
350347

351348
// Create file with customizable quality if enabled and not youtube
352-
if (this.field.enableCustomQualityLabel === true && !isYoutube) {
349+
if (this.field.enableCustomQualityLabel === true && !isProvider) {
353350
fileHtml = '<li class="h5p-av-row">' +
354351
'<div class="h5p-thumbnail">' +
355352
'<div class="h5p-type" title="' + file.mime + '">' + file.mime.split('/')[1] + '</div>' +
@@ -468,12 +465,10 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
468465
}
469466
else {
470467
// Try to find a provider
471-
for (i = 0; i < C.providers.length; i++) {
472-
if (C.providers[i].regexp.test(url)) {
473-
mime = C.providers[i].name;
474-
aspectRatio = C.providers[i].aspectRatio;
475-
break;
476-
}
468+
const provider = C.findProvider(url);
469+
if (provider) {
470+
mime = provider.name;
471+
aspectRatio = provider.aspectRatio;
477472
}
478473
}
479474

@@ -691,6 +686,20 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
691686
}
692687
];
693688

689+
/**
690+
* Find & return an external provider based on the URL
691+
*
692+
* @param {string} url
693+
* @returns {Object}
694+
*/
695+
C.findProvider = function (url) {
696+
for (i = 0; i < C.providers.length; i++) {
697+
if (C.providers[i].regexp.test(url)) {
698+
return C.providers[i];
699+
}
700+
}
701+
};
702+
694703
// Avoid ID attribute collisions
695704
let idCounter = 0;
696705

0 commit comments

Comments
 (0)