Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

feature to also show inline content #266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions dist/ekko-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ var Lightbox = (function ($) {
if (!type && this._getYoutubeId(src)) type = 'youtube';
if (!type && this._getVimeoId(src)) type = 'vimeo';
if (!type && this._getInstagramId(src)) type = 'instagram';
if (!type && this._isInline(src)) type = 'inline';

if (!type || ['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(type) < 0) type = 'url';
if (!type || ['image', 'youtube', 'vimeo', 'instagram', 'video', 'url', 'inline'].indexOf(type) < 0) type = 'url';

return type;
}
Expand All @@ -266,6 +267,11 @@ var Lightbox = (function ($) {
value: function _isImage(string) {
return string && string.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i);
}
}, {
key: '_isInline',
value: function _isInline(string) {
return string && string.match(/^#.*$/i);
}
}, {
key: '_containerToUse',
value: function _containerToUse() {
Expand Down Expand Up @@ -299,7 +305,7 @@ var Lightbox = (function ($) {
var currentRemote = this._$element.attr('data-remote') || this._$element.attr('href');
var currentType = this._detectRemoteType(currentRemote, this._$element.attr('data-type') || false);

if (['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(currentType) < 0) return this._error(this._config.strings.type);
if (['image', 'youtube', 'vimeo', 'instagram', 'video', 'url', 'inline'].indexOf(currentType) < 0) return this._error(this._config.strings.type);

switch (currentType) {
case 'image':
Expand All @@ -318,6 +324,9 @@ var Lightbox = (function ($) {
case 'video':
this._showHtml5Video(currentRemote, $toUse);
break;
case 'inline':
this._showInlineContent(currentRemote, $toUse);
break;
default:
// url
this._loadRemoteContent(currentRemote, $toUse);
Expand Down Expand Up @@ -461,6 +470,21 @@ var Lightbox = (function ($) {
this._toggleLoading(false);
return this;
}
}, {
key: '_showInlineContent',
value: function _showInlineContent(id, $containerForElement) {
var width = this._$element.data('width') || 560;
var height = this._$element.data('height') || 560;

var disableExternalCheck = this._$element.data('disableExternalCheck') || false;
this._toggleLoading(false);

$containerForElement.html($(id).html());
this._config.onContentLoaded.call(this);

this._resize(width, height);
return this;
}
}, {
key: '_loadRemoteContent',
value: function _loadRemoteContent(url, $containerForElement) {
Expand Down
2 changes: 1 addition & 1 deletion dist/ekko-lightbox.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ekko-lightbox.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ekko-lightbox.min.js.map

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions ekko-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ const Lightbox = (($) => {
type = 'vimeo';
if(!type && this._getInstagramId(src))
type = 'instagram';
if (!type && this._isInline(src))
type = 'inline';

if(!type || ['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(type) < 0)
if(!type || ['image', 'youtube', 'vimeo', 'instagram', 'video', 'url', 'inline'].indexOf(type) < 0)
type = 'url';

return type;
Expand All @@ -269,6 +271,9 @@ const Lightbox = (($) => {
_isImage(string) {
return string && string.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i)
}
_isInline(string) {
return string && string.match(/^#.*$/i)
}

_containerToUse() {
// if currently showing an image, fade it out and remove
Expand Down Expand Up @@ -300,7 +305,7 @@ const Lightbox = (($) => {
let currentRemote = this._$element.attr('data-remote') || this._$element.attr('href')
let currentType = this._detectRemoteType(currentRemote, this._$element.attr('data-type') || false)

if(['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(currentType) < 0)
if(['image', 'youtube', 'vimeo', 'instagram', 'video', 'url', 'inline'].indexOf(currentType) < 0)
return this._error(this._config.strings.type)

switch(currentType) {
Expand All @@ -320,6 +325,9 @@ const Lightbox = (($) => {
case 'video':
this._showHtml5Video(currentRemote, $toUse);
break;
case 'inline':
this._showInlineContent(currentRemote, $toUse);
break;
default: // url
this._loadRemoteContent(currentRemote, $toUse);
break;
Expand Down Expand Up @@ -462,6 +470,20 @@ const Lightbox = (($) => {
return this;
}

_showInlineContent(id, $containerForElement) {
let width = this._$element.data('width') || 560;
let height = this._$element.data('height') || 560;

let disableExternalCheck = this._$element.data('disableExternalCheck') || false;
this._toggleLoading(false);

$containerForElement.html($(id).html());
this._config.onContentLoaded.call(this);

this._resize(width, height);
return this;
}

_loadRemoteContent(url, $containerForElement) {
let width = this._$element.data('width') || 560;
let height = this._$element.data('height') || 560;
Expand Down Expand Up @@ -658,4 +680,4 @@ const Lightbox = (($) => {

})(jQuery)

export default Lightbox
export default Lightbox