Skip to content

Commit

Permalink
Merge pull request #27 from kashtanoff/feature/speed-fix
Browse files Browse the repository at this point in the history
Use one lightbox wrapper for all galleries on page.
  • Loading branch information
duncanmcdougall committed Oct 2, 2015
2 parents d433785 + 51eb32b commit 67e9b83
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 67e9b83

Please sign in to comment.