Skip to content

Commit

Permalink
Merge pull request #31 from victordieggo/dev
Browse files Browse the repository at this point in the history
Bug fixes and improvements
  • Loading branch information
victordieggo committed Feb 17, 2018
2 parents 5fe8676 + 105a75c commit a014742
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lightbox/lightbox.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
=======================================================
Lightbox.js
Version: 0.0.5
Version: 0.0.6
Author: Victor Diego <victordieggo@gmail.com>
License: MIT
=======================================================
Expand All @@ -18,6 +18,10 @@ License: MIT
-------------------------------------------------------
*/

.remove-scroll {
overflow: hidden;
}

.lightbox-hide {
top: -9999px;
left: -9999px;
Expand Down Expand Up @@ -46,6 +50,7 @@ License: MIT
}

.lightbox-image {
max-height: 100vh;
vertical-align: middle;
}

Expand Down
23 changes: 14 additions & 9 deletions lightbox/lightbox.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* =====================================================================
* Lightbox.js
* Version: 0.0.5
* Version: 0.0.6
* Author: Victor Diego <victordieggo@gmail.com>
* License: MIT
* ================================================================== */
/*global document, setTimeout*/

(function () {

'use strict';

var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger;
var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger, currentTrigger;

body = document.body;

Expand All @@ -23,6 +22,10 @@
scaleOut: 'deleteBox .3s'
};

function toggleScroll() {
body.classList.toggle('remove-scroll');
}

function sortContent(content) {
var image, video, href = content.getAttribute('href');

Expand Down Expand Up @@ -94,6 +97,7 @@
container = content.cloneNode(false);
container.className = 'lightbox-container';
container.style.animation = animation.fadeIn;
container.onclick = function() {};
container.appendChild(wrapper);

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

body.appendChild(container);
body.style.overflow = 'hidden';
toggleScroll();
}

function galleryNavigation(position) {
Expand Down Expand Up @@ -140,23 +144,24 @@
wrapper.style.animation = [animation.scaleOut, animation.fadeOut];
setTimeout(function () {
if (body.contains(container)) {
body.removeAttribute('style');
body.removeChild(container);
currentItem.focus();
currentTrigger.focus();
currentItem.classList.remove('current-lightbox-item');
toggleScroll();
}
}, 200);
}

Array.prototype.forEach.call(trigger, function (element) {
element.addEventListener('click', function (event) {
event.preventDefault();
buildLightbox(this);
buildLightbox(element);
currentTrigger = element;
});
});

Array.prototype.forEach.call(['click', 'keyup'], function (event) {
body.addEventListener(event, function (event) {
['click', 'keyup'].forEach( function (eventType) {
body.addEventListener(eventType, function (event) {
if (body.contains(container)) {
var target = event.target,
key = event.keyCode,
Expand Down
2 changes: 1 addition & 1 deletion lightbox/lightbox.min.css

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

2 changes: 1 addition & 1 deletion lightbox/lightbox.min.js

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

0 comments on commit a014742

Please sign in to comment.