Skip to content

Commit

Permalink
Fixed issue with nav and multiple galleries
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcdougall committed Jan 17, 2016
1 parent 8cf3612 commit 18efa27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
1 change: 1 addition & 0 deletions demo/groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h2>Group 2 - No Nav</h2>
<h2>Group 3</h2>
<ul class="gallery gallery3">
<li><a href="http://lorempixel.com/500/500/sports/1/"><img src="http://lorempixel.com/150/150/sports/1/" alt="Image"></a></li>
<li><a href="http://lorempixel.com/500/500/sports/2/"><img src="http://lorempixel.com/150/150/sports/2/" alt="Image"></a></li>
</ul>
<footer>
<p>Lightbox Plugin and photos by <a href="http://www.twitter.com/duncanmcdougall">Duncan McDougall</a></p>
Expand Down
45 changes: 20 additions & 25 deletions jquery.lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,23 @@
current: null,
locked: false,
caption: null,

init: function (items) {
plugin.items = items;
var id = 'lightbox-' + Math.floor((Math.random() * 100000) + 1);
if (!plugin.lightbox) {
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);
}
$('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.caption = $('.lightbox__caption', plugin.lightbox);

if (plugin.items.length > 1 && opts.nav) {
$('.lightbox__nav', plugin.lightbox).show();
Expand All @@ -65,7 +60,7 @@
},

loadImage: function () {
if(opts.blur) {
if (opts.blur) {
$("body").addClass("blurred");
}
$("img", plugin.lightbox).remove();
Expand All @@ -84,10 +79,10 @@

setCaption: function () {
var caption = $(plugin.current).data('caption');
if(!!caption && caption.length > 0) {
if (!!caption && caption.length > 0) {
plugin.caption.fadeIn();
$('p', plugin.caption).text(caption);
}else{
} else {
plugin.caption.hide();
}
},
Expand All @@ -111,9 +106,9 @@
}

plugin.image.width(iWidth).height(iHeight).css({
'top': ($(window).height() - plugin.image.outerHeight()) / 2 + 'px',
'left': ($(window).width() - plugin.image.outerWidth()) / 2 + 'px'
}).show();
'top': ($(window).height() - plugin.image.outerHeight()) / 2 + 'px',
'left': ($(window).width() - plugin.image.outerWidth()) / 2 + 'px'
}).show();
plugin.locked = false;
},

Expand Down Expand Up @@ -147,7 +142,7 @@

bindEvents: function () {
$(plugin.items).click(function (e) {
if(!plugin.lightbox.is(":visible") && ($(window).width() < opts.minSize || $(window).height() < opts.minSize)) {
if (!plugin.lightbox.is(":visible") && ($(window).width() < opts.minSize || $(window).height() < opts.minSize)) {
$(this).attr("target", "_blank");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion jquery.lightbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18efa27

Please sign in to comment.