Skip to content

Commit

Permalink
Merge pull request #25 from victordieggo/dev
Browse files Browse the repository at this point in the history
Refactored event listeners
  • Loading branch information
victordieggo committed Sep 5, 2017
2 parents d9d8f36 + b204e07 commit 32927d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
42 changes: 15 additions & 27 deletions lightbox/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,36 +160,24 @@
});
});

body.addEventListener('click', function (event) {
if (body.contains(container)) {
var target = event.target;
if (target === container || target === screenCover || target === btnClose) {
closeLightbox();
}
if (target === btnNav.next) {
galleryNavigation('next');
}
if (target === btnNav.previous) {
galleryNavigation('previous');
}
}
});

body.addEventListener('keyup', function (event) {
if (body.contains(container)) {
var key = event.keyCode;
if (key === 27) {
closeLightbox();
}
if (container.classList.contains('lightbox-gallery')) {
if (key === 39) {
galleryNavigation('next');
Array.prototype.forEach.call(['click', 'keyup'], function (event) {
body.addEventListener(event, function (event) {
if (body.contains(container)) {
var target = event.target,
key = event.keyCode;
if ([container, screenCover, btnClose].indexOf(target) !== -1 || key === 27) {
closeLightbox();
}
if (key === 37) {
galleryNavigation('previous');
if (container.classList.contains('lightbox-gallery')) {
if (target === btnNav.next || key === 39) {
galleryNavigation('next');
}
if (target === btnNav.previous || key === 37) {
galleryNavigation('previous');
}
}
}
}
});
});

}());
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 32927d5

Please sign in to comment.