@@ -256,26 +256,33 @@ var Lightbox = (function ($) {
256
256
if ( ! type && this . _getYoutubeId ( src ) ) type = 'youtube' ;
257
257
if ( ! type && this . _getVimeoId ( src ) ) type = 'vimeo' ;
258
258
if ( ! type && this . _getInstagramId ( src ) ) type = 'instagram' ;
259
- if ( ! type && this . _isAudio ( src ) ) type = 'audio' ;
260
- if ( ! type && this . _isVideo ( src ) ) type = 'video' ;
261
- if ( ! type || [ 'image' , 'youtube' , 'vimeo' , 'instagram' , 'video' , 'url' , 'audio' ] . indexOf ( type ) < 0 ) type = 'url' ;
259
+ if ( type == 'audio' || type == 'video' || ! type && this . _isMedia ( src ) ) type = 'media' ;
260
+ if ( ! type || [ 'image' , 'youtube' , 'vimeo' , 'instagram' , 'media' , 'url' ] . indexOf ( type ) < 0 ) type = 'url' ;
262
261
263
262
return type ;
264
263
}
264
+ } , {
265
+ key : '_getRemoteContentType' ,
266
+ value : function _getRemoteContentType ( src ) {
267
+ var response = $ . ajax ( {
268
+ type : 'HEAD' ,
269
+ url : src ,
270
+ async : false
271
+ } ) ;
272
+ console . log ( response ) ;
273
+ var contentType = response . getResponseHeader ( 'Content-Type' ) ;
274
+ console . log ( contentType ) ;
275
+ return contentType ;
276
+ }
265
277
} , {
266
278
key : '_isImage' ,
267
279
value : function _isImage ( string ) {
268
280
return string && string . match ( / ( ^ d a t a : i m a g e \/ .* , ) | ( \. ( j p ( e | g | e g ) | g i f | p n g | b m p | w e b p | s v g ) ( ( \? | # ) .* ) ? $ ) / i) ;
269
281
}
270
282
} , {
271
- key : '_isAudio' ,
272
- value : function _isAudio ( string ) {
273
- return string && string . match ( / ( ^ d a t a : a u d i o \/ .* , ) | ( \. ( m p 3 | o g g ) ( ( \? | # ) .* ) ? $ ) / i) ;
274
- }
275
- } , {
276
- key : '_isVideo' ,
277
- value : function _isVideo ( string ) {
278
- return string && string . match ( / ( ^ d a t a : a u d i o \/ .* , ) | ( \. ( m p 4 | o g g ) ( ( \? | # ) .* ) ? $ ) / i) ;
283
+ key : '_isMedia' ,
284
+ value : function _isMedia ( string ) {
285
+ return string && string . match ( / ( \. ( m p 3 | m p 4 | o g g | w e b m | w a v ) ( ( \? | # ) .* ) ? $ ) / i) ;
279
286
}
280
287
} , {
281
288
key : '_containerToUse' ,
@@ -310,7 +317,7 @@ var Lightbox = (function ($) {
310
317
var currentRemote = this . _$element . attr ( 'data-remote' ) || this . _$element . attr ( 'href' ) ;
311
318
var currentType = this . _detectRemoteType ( currentRemote , this . _$element . attr ( 'data-type' ) || false ) ;
312
319
313
- if ( [ 'image' , 'youtube' , 'vimeo' , 'instagram' , 'video ' , 'url' , 'audio '] . indexOf ( currentType ) < 0 ) return this . _error ( this . _config . strings . type ) ;
320
+ if ( [ 'image' , 'youtube' , 'vimeo' , 'instagram' , 'media ' , 'url' ] . indexOf ( currentType ) < 0 ) return this . _error ( this . _config . strings . type ) ;
314
321
315
322
switch ( currentType ) {
316
323
case 'image' :
@@ -326,11 +333,8 @@ var Lightbox = (function ($) {
326
333
case 'instagram' :
327
334
this . _showInstagramVideo ( this . _getInstagramId ( currentRemote ) , $toUse ) ;
328
335
break ;
329
- case 'video' :
330
- this . _showHtml5Video ( currentRemote , $toUse ) ;
331
- break ;
332
- case 'audio' :
333
- this . _showHtml5Audio ( currentRemote , $toUse ) ;
336
+ case 'media' :
337
+ this . _showHtml5Media ( currentRemote , $toUse ) ;
334
338
break ;
335
339
default :
336
340
// url
@@ -463,25 +467,23 @@ var Lightbox = (function ($) {
463
467
return this ;
464
468
}
465
469
} , {
466
- key : '_showHtml5Video' ,
467
- value : function _showHtml5Video ( url , $containerForElement ) {
468
- // should be used for videos only. for remote content use loadRemoteContent (data-type=url)
469
- var width = this . _$element . data ( 'width' ) || 560 ;
470
- var height = this . _$element . data ( 'height' ) || width / ( 560 / 315 ) ;
471
- $containerForElement . html ( '<div class="embed-responsive embed-responsive-16by9"><video width="' + width + '" height="' + height + '" src="' + url + '" preload="auto" autoplay controls class="embed-responsive-item"></video></div>' ) ;
472
- this . _resize ( width , height ) ;
473
- this . _config . onContentLoaded . call ( this ) ;
474
- if ( this . _$modalArrows ) this . _$modalArrows . css ( 'display' , 'none' ) ; //hide the arrows when showing video
475
- this . _toggleLoading ( false ) ;
476
- return this ;
477
- }
478
- } , {
479
- key : '_showHtml5Audio' ,
480
- value : function _showHtml5Audio ( url , $containerForElement ) {
470
+ key : '_showHtml5Media' ,
471
+ value : function _showHtml5Media ( url , $containerForElement ) {
481
472
// should be used for videos only. for remote content use loadRemoteContent (data-type=url)
473
+ var contentType = this . _getRemoteContentType ( url ) ;
474
+ console . log ( contentType ) ;
475
+ if ( ! contentType ) {
476
+ return this . _error ( this . _config . strings . type ) ;
477
+ }
478
+ var mediaType = '' ;
479
+ if ( contentType . indexOf ( 'audio' ) > 0 ) {
480
+ mediaType = 'audio' ;
481
+ } else {
482
+ mediaType = 'video' ;
483
+ }
482
484
var width = this . _$element . data ( 'width' ) || 560 ;
483
485
var height = this . _$element . data ( 'height' ) || width / ( 560 / 315 ) ;
484
- $containerForElement . html ( '<div class="embed-responsive embed-responsive-16by9"><audio width=" ' + width + '" height ="' + height + '" src ="' + url + '" preload="auto" autoplay controls class="embed-responsive-item"></audio ></div>' ) ;
486
+ $containerForElement . html ( '<div class="embed-responsive embed-responsive-16by9"><' + mediaType + ' width ="' + width + '" height ="' + height + '" preload="auto" autoplay controls class="embed-responsive-item"><source src="' + url + '" type="' + contentType + '">' + this . _config . strings . type + '</' + mediaType + ' ></div>') ;
485
487
this . _resize ( width , height ) ;
486
488
this . _config . onContentLoaded . call ( this ) ;
487
489
if ( this . _$modalArrows ) this . _$modalArrows . css ( 'display' , 'none' ) ; //hide the arrows when showing video
0 commit comments