|
1 | 1 | /* =====================================================================
|
2 | 2 | * Lightbox.js
|
3 |
| - * Version: 0.0.5 |
| 3 | + * Version: 0.0.6 |
4 | 4 | * Author: Victor Diego <victordieggo@gmail.com>
|
5 | 5 | * License: MIT
|
6 | 6 | * ================================================================== */
|
7 |
| -/*global document, setTimeout*/ |
8 | 7 |
|
9 | 8 | (function () {
|
10 | 9 |
|
11 | 10 | 'use strict';
|
12 | 11 |
|
13 |
| - var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger; |
| 12 | + var animation, body, btnClose, btnNav, currentItem, container, content, wrapper, trigger, currentTrigger; |
14 | 13 |
|
15 | 14 | body = document.body;
|
16 | 15 |
|
|
23 | 22 | scaleOut: 'deleteBox .3s'
|
24 | 23 | };
|
25 | 24 |
|
| 25 | + function toggleScroll() { |
| 26 | + body.classList.toggle('remove-scroll'); |
| 27 | + } |
| 28 | + |
26 | 29 | function sortContent(content) {
|
27 | 30 | var image, video, href = content.getAttribute('href');
|
28 | 31 |
|
|
94 | 97 | container = content.cloneNode(false);
|
95 | 98 | container.className = 'lightbox-container';
|
96 | 99 | container.style.animation = animation.fadeIn;
|
| 100 | + container.onclick = function() {}; |
97 | 101 | container.appendChild(wrapper);
|
98 | 102 |
|
99 | 103 | if (element.getAttribute('data-lightbox') === 'gallery') {
|
|
111 | 115 | }
|
112 | 116 |
|
113 | 117 | body.appendChild(container);
|
114 |
| - body.style.overflow = 'hidden'; |
| 118 | + toggleScroll(); |
115 | 119 | }
|
116 | 120 |
|
117 | 121 | function galleryNavigation(position) {
|
|
140 | 144 | wrapper.style.animation = [animation.scaleOut, animation.fadeOut];
|
141 | 145 | setTimeout(function () {
|
142 | 146 | if (body.contains(container)) {
|
143 |
| - body.removeAttribute('style'); |
144 | 147 | body.removeChild(container);
|
145 |
| - currentItem.focus(); |
| 148 | + currentTrigger.focus(); |
146 | 149 | currentItem.classList.remove('current-lightbox-item');
|
| 150 | + toggleScroll(); |
147 | 151 | }
|
148 | 152 | }, 200);
|
149 | 153 | }
|
150 | 154 |
|
151 | 155 | Array.prototype.forEach.call(trigger, function (element) {
|
152 | 156 | element.addEventListener('click', function (event) {
|
153 | 157 | event.preventDefault();
|
154 |
| - buildLightbox(this); |
| 158 | + buildLightbox(element); |
| 159 | + currentTrigger = element; |
155 | 160 | });
|
156 | 161 | });
|
157 | 162 |
|
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) { |
160 | 165 | if (body.contains(container)) {
|
161 | 166 | var target = event.target,
|
162 | 167 | key = event.keyCode,
|
|
0 commit comments