Skip to content

Commit

Permalink
Use one lightbox wrapper for all galleries on page.
Browse files Browse the repository at this point in the history
Faster init with multiple galleries on page.
  • Loading branch information
kashtanoff committed Sep 29, 2015
1 parent d433785 commit 51eb32b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions jquery.lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@

init: function (items) {
plugin.items = items;
plugin.selector = "lightbox-"+Math.random().toString().replace('.','');
var id = 'lightbox-' + Math.floor((Math.random() * 100000) + 1);
if (!plugin.lightbox) {
$('body').append(
'<div id="'+id+'" class="lightbox" style="display:none;">'+
'<a href="#" class="lightbox__close lightbox__button"></a>' +
'<a href="#" class="lightbox__nav lightbox__nav--prev lightbox__button"></a>' +
'<a href="#" class="lightbox__nav lightbox__nav--next lightbox__button"></a>' +
'<div href="#" class="lightbox__caption"><p></p></div>' +
'</div>'
);

plugin.lightbox = $("#"+id);
plugin.lightbox = $('body').find('.bodyGlobalLightbox');

if(plugin.lightbox.length === 0){
$('body').append(
'<div id="'+id+'" class="lightbox bodyGlobalLightbox" style="display:none;">'+
'<a href="#" class="lightbox__close lightbox__button"></a>' +
'<a href="#" class="lightbox__nav lightbox__nav--prev lightbox__button"></a>' +
'<a href="#" class="lightbox__nav lightbox__nav--next lightbox__button"></a>' +
'<div href="#" class="lightbox__caption"><p></p></div>' +
'</div>'
);

plugin.lightbox = $("#"+id);
}

plugin.caption = $('.lightbox__caption', plugin.lightbox);
}

Expand Down

0 comments on commit 51eb32b

Please sign in to comment.