Skip to content

Commit 8289ed5

Browse files
mervitashleydw
authored andcommitted
Change video and audio to media
1 parent 2ac4972 commit 8289ed5

File tree

5 files changed

+73
-69
lines changed

5 files changed

+73
-69
lines changed

dist/ekko-lightbox.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,33 @@ var Lightbox = (function ($) {
256256
if (!type && this._getYoutubeId(src)) type = 'youtube';
257257
if (!type && this._getVimeoId(src)) type = 'vimeo';
258258
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';
262261

263262
return type;
264263
}
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+
}
265277
}, {
266278
key: '_isImage',
267279
value: function _isImage(string) {
268280
return string && string.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i);
269281
}
270282
}, {
271-
key: '_isAudio',
272-
value: function _isAudio(string) {
273-
return string && string.match(/(^data:audio\/.*,)|(\.(mp3|ogg)((\?|#).*)?$)/i);
274-
}
275-
}, {
276-
key: '_isVideo',
277-
value: function _isVideo(string) {
278-
return string && string.match(/(^data:audio\/.*,)|(\.(mp4|ogg)((\?|#).*)?$)/i);
283+
key: '_isMedia',
284+
value: function _isMedia(string) {
285+
return string && string.match(/(\.(mp3|mp4|ogg|webm|wav)((\?|#).*)?$)/i);
279286
}
280287
}, {
281288
key: '_containerToUse',
@@ -310,7 +317,7 @@ var Lightbox = (function ($) {
310317
var currentRemote = this._$element.attr('data-remote') || this._$element.attr('href');
311318
var currentType = this._detectRemoteType(currentRemote, this._$element.attr('data-type') || false);
312319

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);
314321

315322
switch (currentType) {
316323
case 'image':
@@ -326,11 +333,8 @@ var Lightbox = (function ($) {
326333
case 'instagram':
327334
this._showInstagramVideo(this._getInstagramId(currentRemote), $toUse);
328335
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);
334338
break;
335339
default:
336340
// url
@@ -463,25 +467,23 @@ var Lightbox = (function ($) {
463467
return this;
464468
}
465469
}, {
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) {
481472
// 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+
}
482484
var width = this._$element.data('width') || 560;
483485
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>');
485487
this._resize(width, height);
486488
this._config.onContentLoaded.call(this);
487489
if (this._$modalArrows) this._$modalArrows.css('display', 'none'); //hide the arrows when showing video

dist/ekko-lightbox.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)