Skip to content

Commit a014742

Browse files
authored
Merge pull request #31 from victordieggo/dev
Bug fixes and improvements
2 parents 5fe8676 + 105a75c commit a014742

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

lightbox/lightbox.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
=======================================================
33
Lightbox.js
4-
Version: 0.0.5
4+
Version: 0.0.6
55
Author: Victor Diego <victordieggo@gmail.com>
66
License: MIT
77
=======================================================
@@ -18,6 +18,10 @@ License: MIT
1818
-------------------------------------------------------
1919
*/
2020

21+
.remove-scroll {
22+
overflow: hidden;
23+
}
24+
2125
.lightbox-hide {
2226
top: -9999px;
2327
left: -9999px;
@@ -46,6 +50,7 @@ License: MIT
4650
}
4751

4852
.lightbox-image {
53+
max-height: 100vh;
4954
vertical-align: middle;
5055
}
5156

lightbox/lightbox.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/* =====================================================================
22
* Lightbox.js
3-
* Version: 0.0.5
3+
* Version: 0.0.6
44
* Author: Victor Diego <victordieggo@gmail.com>
55
* License: MIT
66
* ================================================================== */
7-
/*global document, setTimeout*/
87

98
(function () {
109

1110
'use strict';
1211

13-
var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger;
12+
var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger, currentTrigger;
1413

1514
body = document.body;
1615

@@ -23,6 +22,10 @@
2322
scaleOut: 'deleteBox .3s'
2423
};
2524

25+
function toggleScroll() {
26+
body.classList.toggle('remove-scroll');
27+
}
28+
2629
function sortContent(content) {
2730
var image, video, href = content.getAttribute('href');
2831

@@ -94,6 +97,7 @@
9497
container = content.cloneNode(false);
9598
container.className = 'lightbox-container';
9699
container.style.animation = animation.fadeIn;
100+
container.onclick = function() {};
97101
container.appendChild(wrapper);
98102

99103
if (element.getAttribute('data-lightbox') === 'gallery') {
@@ -111,7 +115,7 @@
111115
}
112116

113117
body.appendChild(container);
114-
body.style.overflow = 'hidden';
118+
toggleScroll();
115119
}
116120

117121
function galleryNavigation(position) {
@@ -140,23 +144,24 @@
140144
wrapper.style.animation = [animation.scaleOut, animation.fadeOut];
141145
setTimeout(function () {
142146
if (body.contains(container)) {
143-
body.removeAttribute('style');
144147
body.removeChild(container);
145-
currentItem.focus();
148+
currentTrigger.focus();
146149
currentItem.classList.remove('current-lightbox-item');
150+
toggleScroll();
147151
}
148152
}, 200);
149153
}
150154

151155
Array.prototype.forEach.call(trigger, function (element) {
152156
element.addEventListener('click', function (event) {
153157
event.preventDefault();
154-
buildLightbox(this);
158+
buildLightbox(element);
159+
currentTrigger = element;
155160
});
156161
});
157162

158-
Array.prototype.forEach.call(['click', 'keyup'], function (event) {
159-
body.addEventListener(event, function (event) {
163+
['click', 'keyup'].forEach( function (eventType) {
164+
body.addEventListener(eventType, function (event) {
160165
if (body.contains(container)) {
161166
var target = event.target,
162167
key = event.keyCode,

lightbox/lightbox.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lightbox/lightbox.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)