@@ -318,14 +318,11 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
318
318
var defaultQualityName = H5PEditor . t ( 'core' , 'videoQualityDefaultLabel' , { ':index' : index + 1 } ) ;
319
319
var qualityName = ( file . metadata && file . metadata . qualityName ) ? file . metadata . qualityName : defaultQualityName ;
320
320
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 ) ;
326
323
327
324
// Only allow single source if YouTube
328
- if ( isYoutube ) {
325
+ if ( isProvider ) {
329
326
// Remove all other files except this one
330
327
that . $files . children ( ) . each ( function ( i ) {
331
328
if ( i !== that . updateIndex ) {
@@ -339,7 +336,7 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
339
336
// This is now the first and only file
340
337
index = 0 ;
341
338
}
342
- this . $add . toggleClass ( 'hidden' , ! ! isYoutube ) ;
339
+ this . $add . toggleClass ( 'hidden' , isProvider ) ;
343
340
344
341
// If updating remove and recreate element
345
342
if ( that . updateIndex !== undefined ) {
@@ -349,7 +346,7 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
349
346
}
350
347
351
348
// Create file with customizable quality if enabled and not youtube
352
- if ( this . field . enableCustomQualityLabel === true && ! isYoutube ) {
349
+ if ( this . field . enableCustomQualityLabel === true && ! isProvider ) {
353
350
fileHtml = '<li class="h5p-av-row">' +
354
351
'<div class="h5p-thumbnail">' +
355
352
'<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 ($)
468
465
}
469
466
else {
470
467
// 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 ;
477
472
}
478
473
}
479
474
@@ -691,6 +686,20 @@ H5PEditor.widgets.video = H5PEditor.widgets.audio = H5PEditor.AV = (function ($)
691
686
}
692
687
] ;
693
688
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
+
694
703
// Avoid ID attribute collisions
695
704
let idCounter = 0 ;
696
705
0 commit comments