Skip to content

Commit 9c465f8

Browse files
authored
Merge pull request #15 from designjockey/next-fix
Lightbox: Fixes bug where next/previous icon would show and hide the image (introduced in 3.1.0)
2 parents b220836 + 08a1e17 commit 9c465f8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Diff for: lightbox.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var bgColor,
66
opacity,
77
$blocking = $('<div class="js-blocking" id="lightbox-blocking"></div>'),
88
$body = $(document.body),
9-
$template = $(`
9+
template = `
1010
<div class="js-lightbox-wrap" id="lightbox-wrap">
1111
<div class="js-lightbox-inner-wrap" id="lightbox-inner-wrap">
1212
<div class="js-img-wrap" id="lightbox-img-wrap">
@@ -32,7 +32,7 @@ var bgColor,
3232
</div>
3333
</div>
3434
</div>
35-
`),
35+
`,
3636
images = [],
3737
active = false,
3838
loading = false,
@@ -44,7 +44,7 @@ var bgColor,
4444
var LightboxImage = function(src, id) {
4545
this.src = src;
4646
this.id = id;
47-
this.$view = $template.hide();
47+
this.$view = $(template).hide();
4848

4949
var self = this;
5050

@@ -76,6 +76,8 @@ var LightboxImage = function(src, id) {
7676
self.$view.css('top', top);
7777
self.$view.find('.js-img-wrap').height($loadedImg.height());
7878
}
79+
80+
_setCloseIconColor(self.$view, bgColor);
7981
};
8082

8183
this.render = function() {
@@ -173,11 +175,16 @@ function bind() {
173175
});
174176
}
175177

176-
function _setCloseIconColor(bgColor) {
178+
function _setCloseIconColor($context, bgColor) {
177179
var tinyBgColor = tinycolor(bgColor);
178180
var closeIconColor = tinyBgColor.isLight() ? '#000' : '#FFF';
181+
var $svg = $context.find('.js-close svg');
179182

180-
$template.find('.js-close svg').attr('fill', closeIconColor);
183+
if($svg.attr('fill')) {
184+
return;
185+
}
186+
187+
$svg.attr('fill', closeIconColor);
181188
}
182189

183190
function init(options) {
@@ -192,8 +199,6 @@ function init(options) {
192199
bgColor = config.bgColor;
193200
opacity = config.opacity;
194201

195-
_setCloseIconColor(bgColor);
196-
197202
$context.find('.js-lightbox').each(function(i, el) {
198203
var $img = $(el);
199204
$img.data('img-id', i).addClass('lightbox-link');

0 commit comments

Comments
 (0)