@tomasvn/glightbox 0.0.0-stage → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.eslintrc.json +94 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- package/.github/stale.yml +21 -0
- package/.github/workflows/greetings.yml +13 -0
- package/.lando.yml +10 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +31 -0
- package/CHANGELOG.md +247 -0
- package/CONTRIBUTING.md +29 -0
- package/LICENSE.md +21 -0
- package/README.md +710 -2
- package/bower.json +29 -0
- package/development/jscompiler.js +84 -0
- package/development/notifications.js +15 -0
- package/development/package.js +116 -0
- package/development/postcss.js +63 -0
- package/development/watcher.js +105 -0
- package/dist/css/glightbox.css +939 -0
- package/dist/css/glightbox.min.css +1 -0
- package/dist/js/glightbox.js +3087 -0
- package/dist/js/glightbox.min.js +1 -0
- package/index.d.ts +570 -0
- package/package.json +55 -4
- package/src/js/.jshintrc +6 -0
- package/src/js/core/drag.js +219 -0
- package/src/js/core/keyboard-navigation.js +98 -0
- package/src/js/core/slide-parser.js +231 -0
- package/src/js/core/slide.js +245 -0
- package/src/js/core/touch-events.js +378 -0
- package/src/js/core/touch-navigation.js +287 -0
- package/src/js/core/zoom.js +156 -0
- package/src/js/glightbox.js +1341 -0
- package/src/js/slides/iframe.js +24 -0
- package/src/js/slides/image.js +56 -0
- package/src/js/slides/inline.js +71 -0
- package/src/js/slides/video.js +105 -0
- package/src/js/utils/helpers.js +541 -0
- package/src/postcss/glightbox.css +723 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch Navigation
|
|
3
|
+
* Allow navigation using touch events
|
|
4
|
+
*
|
|
5
|
+
* @param {object} instance
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import TouchEvents from './touch-events.js';
|
|
9
|
+
import { addEvent, addClass, removeClass, hasClass, closest, whichTransitionEvent, cssTransform, windowSize } from '../utils/helpers.js';
|
|
10
|
+
|
|
11
|
+
function resetSlideMove(slide) {
|
|
12
|
+
const transitionEnd = whichTransitionEvent();
|
|
13
|
+
const windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
14
|
+
|
|
15
|
+
let media = hasClass(slide, 'gslide-media') ? slide : slide.querySelector('.gslide-media');
|
|
16
|
+
let container = closest(media, '.ginner-container');
|
|
17
|
+
let desc = slide.querySelector('.gslide-description');
|
|
18
|
+
|
|
19
|
+
if (windowWidth > 769) {
|
|
20
|
+
media = container;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addClass(media, 'greset');
|
|
24
|
+
cssTransform(media, 'translate3d(0, 0, 0)');
|
|
25
|
+
addEvent(transitionEnd, {
|
|
26
|
+
onElement: media,
|
|
27
|
+
once: true,
|
|
28
|
+
withCallback: (event, target) => {
|
|
29
|
+
removeClass(media, 'greset');
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
media.style.opacity = '';
|
|
34
|
+
if (desc) {
|
|
35
|
+
desc.style.opacity = '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default function touchNavigation(instance) {
|
|
40
|
+
if (instance.events.hasOwnProperty('touch')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let winSize = windowSize();
|
|
45
|
+
let winWidth = winSize.width;
|
|
46
|
+
let winHeight = winSize.height;
|
|
47
|
+
let process = false;
|
|
48
|
+
let currentSlide = null;
|
|
49
|
+
let media = null;
|
|
50
|
+
let mediaImage = null;
|
|
51
|
+
let doingMove = false;
|
|
52
|
+
let initScale = 1;
|
|
53
|
+
let maxScale = 4.5;
|
|
54
|
+
let currentScale = 1;
|
|
55
|
+
let doingZoom = false;
|
|
56
|
+
let imageZoomed = false;
|
|
57
|
+
let zoomedPosX = null;
|
|
58
|
+
let zoomedPosY = null;
|
|
59
|
+
let lastZoomedPosX = null;
|
|
60
|
+
let lastZoomedPosY = null;
|
|
61
|
+
let hDistance;
|
|
62
|
+
let vDistance;
|
|
63
|
+
let hDistancePercent = 0;
|
|
64
|
+
let vDistancePercent = 0;
|
|
65
|
+
let vSwipe = false;
|
|
66
|
+
let hSwipe = false;
|
|
67
|
+
let startCoords = {};
|
|
68
|
+
let endCoords = {};
|
|
69
|
+
let xDown = 0;
|
|
70
|
+
let yDown = 0;
|
|
71
|
+
let isInlined;
|
|
72
|
+
|
|
73
|
+
const sliderWrapper = document.getElementById('glightbox-slider');
|
|
74
|
+
const overlay = document.querySelector('.goverlay');
|
|
75
|
+
|
|
76
|
+
const touchInstance = new TouchEvents(sliderWrapper, {
|
|
77
|
+
touchStart: (e) => {
|
|
78
|
+
process = true;
|
|
79
|
+
|
|
80
|
+
// TODO: More tests for inline content slides
|
|
81
|
+
if (hasClass(e.targetTouches[0].target, 'ginner-container') || closest(e.targetTouches[0].target, '.gslide-desc') || e.targetTouches[0].target.nodeName.toLowerCase() == 'a') {
|
|
82
|
+
process = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (closest(e.targetTouches[0].target, '.gslide-inline') && !hasClass(e.targetTouches[0].target.parentNode, 'gslide-inline')) {
|
|
86
|
+
process = false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (process) {
|
|
90
|
+
endCoords = e.targetTouches[0];
|
|
91
|
+
startCoords.pageX = e.targetTouches[0].pageX;
|
|
92
|
+
startCoords.pageY = e.targetTouches[0].pageY;
|
|
93
|
+
xDown = e.targetTouches[0].clientX;
|
|
94
|
+
yDown = e.targetTouches[0].clientY;
|
|
95
|
+
|
|
96
|
+
currentSlide = instance.activeSlide;
|
|
97
|
+
media = currentSlide.querySelector('.gslide-media');
|
|
98
|
+
isInlined = currentSlide.querySelector('.gslide-inline');
|
|
99
|
+
|
|
100
|
+
mediaImage = null;
|
|
101
|
+
if (hasClass(media, 'gslide-image')) {
|
|
102
|
+
mediaImage = media.querySelector('img');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
106
|
+
|
|
107
|
+
if (windowWidth > 769) {
|
|
108
|
+
media = currentSlide.querySelector('.ginner-container');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
removeClass(overlay, 'greset');
|
|
112
|
+
|
|
113
|
+
if (e.pageX > 20 && e.pageX < window.innerWidth - 20) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
touchMove: (e) => {
|
|
120
|
+
if (!process) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
endCoords = e.targetTouches[0];
|
|
124
|
+
|
|
125
|
+
if (doingZoom || imageZoomed) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (isInlined && isInlined.offsetHeight > winHeight) {
|
|
129
|
+
// Allow scroll without moving the slide
|
|
130
|
+
const moved = startCoords.pageX - endCoords.pageX;
|
|
131
|
+
if (Math.abs(moved) <= 13) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
doingMove = true;
|
|
137
|
+
let xUp = e.targetTouches[0].clientX;
|
|
138
|
+
let yUp = e.targetTouches[0].clientY;
|
|
139
|
+
let xDiff = xDown - xUp;
|
|
140
|
+
let yDiff = yDown - yUp;
|
|
141
|
+
|
|
142
|
+
if (Math.abs(xDiff) > Math.abs(yDiff)) {
|
|
143
|
+
vSwipe = false;
|
|
144
|
+
hSwipe = true;
|
|
145
|
+
} else {
|
|
146
|
+
hSwipe = false;
|
|
147
|
+
vSwipe = true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
hDistance = endCoords.pageX - startCoords.pageX;
|
|
151
|
+
hDistancePercent = (hDistance * 100) / winWidth;
|
|
152
|
+
|
|
153
|
+
vDistance = endCoords.pageY - startCoords.pageY;
|
|
154
|
+
vDistancePercent = (vDistance * 100) / winHeight;
|
|
155
|
+
|
|
156
|
+
let opacity;
|
|
157
|
+
if (vSwipe && mediaImage) {
|
|
158
|
+
opacity = 1 - Math.abs(vDistance) / winHeight;
|
|
159
|
+
overlay.style.opacity = opacity;
|
|
160
|
+
|
|
161
|
+
if (instance.settings.touchFollowAxis) {
|
|
162
|
+
hDistancePercent = 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (hSwipe) {
|
|
166
|
+
opacity = 1 - Math.abs(hDistance) / winWidth;
|
|
167
|
+
media.style.opacity = opacity;
|
|
168
|
+
|
|
169
|
+
if (instance.settings.touchFollowAxis) {
|
|
170
|
+
vDistancePercent = 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!mediaImage) {
|
|
175
|
+
return cssTransform(media, `translate3d(${hDistancePercent}%, 0, 0)`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
cssTransform(media, `translate3d(${hDistancePercent}%, ${vDistancePercent}%, 0)`);
|
|
179
|
+
},
|
|
180
|
+
touchEnd: () => {
|
|
181
|
+
if (!process) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
doingMove = false;
|
|
185
|
+
if (imageZoomed || doingZoom) {
|
|
186
|
+
lastZoomedPosX = zoomedPosX;
|
|
187
|
+
lastZoomedPosY = zoomedPosY;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const v = Math.abs(parseInt(vDistancePercent));
|
|
191
|
+
const h = Math.abs(parseInt(hDistancePercent));
|
|
192
|
+
|
|
193
|
+
if (v > 29 && mediaImage) {
|
|
194
|
+
instance.close();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (v < 29 && h < 25) {
|
|
198
|
+
addClass(overlay, 'greset');
|
|
199
|
+
overlay.style.opacity = 1;
|
|
200
|
+
return resetSlideMove(media);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
multipointEnd: () => {
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
doingZoom = false;
|
|
206
|
+
}, 50);
|
|
207
|
+
},
|
|
208
|
+
multipointStart: () => {
|
|
209
|
+
doingZoom = true;
|
|
210
|
+
initScale = currentScale ? currentScale : 1;
|
|
211
|
+
},
|
|
212
|
+
pinch: (evt) => {
|
|
213
|
+
if (!mediaImage || doingMove) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
doingZoom = true;
|
|
218
|
+
mediaImage.scaleX = mediaImage.scaleY = initScale * evt.zoom;
|
|
219
|
+
|
|
220
|
+
let scale = initScale * evt.zoom;
|
|
221
|
+
imageZoomed = true;
|
|
222
|
+
|
|
223
|
+
if (scale <= 1) {
|
|
224
|
+
imageZoomed = false;
|
|
225
|
+
scale = 1;
|
|
226
|
+
lastZoomedPosY = null;
|
|
227
|
+
lastZoomedPosX = null;
|
|
228
|
+
zoomedPosX = null;
|
|
229
|
+
zoomedPosY = null;
|
|
230
|
+
mediaImage.setAttribute('style', '');
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (scale > maxScale) {
|
|
234
|
+
// max scale zoom
|
|
235
|
+
scale = maxScale;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
mediaImage.style.transform = `scale3d(${scale}, ${scale}, 1)`;
|
|
239
|
+
currentScale = scale;
|
|
240
|
+
},
|
|
241
|
+
pressMove: (e) => {
|
|
242
|
+
if (imageZoomed && !doingZoom) {
|
|
243
|
+
var mhDistance = endCoords.pageX - startCoords.pageX;
|
|
244
|
+
var mvDistance = endCoords.pageY - startCoords.pageY;
|
|
245
|
+
|
|
246
|
+
if (lastZoomedPosX) {
|
|
247
|
+
mhDistance = mhDistance + lastZoomedPosX;
|
|
248
|
+
}
|
|
249
|
+
if (lastZoomedPosY) {
|
|
250
|
+
mvDistance = mvDistance + lastZoomedPosY;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
zoomedPosX = mhDistance;
|
|
254
|
+
zoomedPosY = mvDistance;
|
|
255
|
+
|
|
256
|
+
let style = `translate3d(${mhDistance}px, ${mvDistance}px, 0)`;
|
|
257
|
+
if (currentScale) {
|
|
258
|
+
style += ` scale3d(${currentScale}, ${currentScale}, 1)`;
|
|
259
|
+
}
|
|
260
|
+
cssTransform(mediaImage, style);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
swipe: (evt) => {
|
|
264
|
+
if (imageZoomed) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (doingZoom) {
|
|
268
|
+
doingZoom = false;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (evt.direction == 'Left') {
|
|
272
|
+
if (instance.index == instance.elements.length - 1) {
|
|
273
|
+
return resetSlideMove(media);
|
|
274
|
+
}
|
|
275
|
+
instance.nextSlide();
|
|
276
|
+
}
|
|
277
|
+
if (evt.direction == 'Right') {
|
|
278
|
+
if (instance.index == 0) {
|
|
279
|
+
return resetSlideMove(media);
|
|
280
|
+
}
|
|
281
|
+
instance.prevSlide();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
instance.events['touch'] = touchInstance;
|
|
287
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZoomImages
|
|
3
|
+
* Allow imaes to zoom and drag
|
|
4
|
+
* for desktops
|
|
5
|
+
*
|
|
6
|
+
* @param {node} img node
|
|
7
|
+
* @param {node} slide container
|
|
8
|
+
* @param {function} function to trigger on close
|
|
9
|
+
*/
|
|
10
|
+
export default class ZoomImages {
|
|
11
|
+
constructor(el, slide, onclose = null) {
|
|
12
|
+
this.img = el;
|
|
13
|
+
this.slide = slide;
|
|
14
|
+
this.onclose = onclose;
|
|
15
|
+
|
|
16
|
+
if (this.img.setZoomEvents) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this.active = false;
|
|
21
|
+
this.zoomedIn = false;
|
|
22
|
+
this.dragging = false;
|
|
23
|
+
this.currentX = null;
|
|
24
|
+
this.currentY = null;
|
|
25
|
+
this.initialX = null;
|
|
26
|
+
this.initialY = null;
|
|
27
|
+
this.xOffset = 0;
|
|
28
|
+
this.yOffset = 0;
|
|
29
|
+
|
|
30
|
+
this.img.addEventListener('mousedown', (e) => this.dragStart(e), false);
|
|
31
|
+
this.img.addEventListener('mouseup', (e) => this.dragEnd(e), false);
|
|
32
|
+
this.img.addEventListener('mousemove', (e) => this.drag(e), false);
|
|
33
|
+
|
|
34
|
+
this.img.addEventListener(
|
|
35
|
+
'click',
|
|
36
|
+
(e) => {
|
|
37
|
+
if (this.slide.classList.contains('dragging-nav')) {
|
|
38
|
+
this.zoomOut();
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!this.zoomedIn) {
|
|
43
|
+
return this.zoomIn();
|
|
44
|
+
}
|
|
45
|
+
if (this.zoomedIn && !this.dragging) {
|
|
46
|
+
this.zoomOut();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
false
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
this.img.setZoomEvents = true;
|
|
53
|
+
}
|
|
54
|
+
zoomIn() {
|
|
55
|
+
let winWidth = this.widowWidth();
|
|
56
|
+
|
|
57
|
+
if (this.zoomedIn || winWidth <= 768) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const img = this.img;
|
|
62
|
+
img.setAttribute('data-style', img.getAttribute('style'));
|
|
63
|
+
img.style.maxWidth = img.naturalWidth + 'px';
|
|
64
|
+
img.style.maxHeight = img.naturalHeight + 'px';
|
|
65
|
+
|
|
66
|
+
if (img.naturalWidth > winWidth) {
|
|
67
|
+
let centerX = winWidth / 2 - img.naturalWidth / 2;
|
|
68
|
+
this.setTranslate(this.img.parentNode, centerX, 0);
|
|
69
|
+
}
|
|
70
|
+
this.slide.classList.add('zoomed');
|
|
71
|
+
this.zoomedIn = true;
|
|
72
|
+
}
|
|
73
|
+
zoomOut() {
|
|
74
|
+
this.img.parentNode.setAttribute('style', '');
|
|
75
|
+
this.img.setAttribute('style', this.img.getAttribute('data-style'));
|
|
76
|
+
this.slide.classList.remove('zoomed');
|
|
77
|
+
this.zoomedIn = false;
|
|
78
|
+
this.currentX = null;
|
|
79
|
+
this.currentY = null;
|
|
80
|
+
this.initialX = null;
|
|
81
|
+
this.initialY = null;
|
|
82
|
+
this.xOffset = 0;
|
|
83
|
+
this.yOffset = 0;
|
|
84
|
+
|
|
85
|
+
if (this.onclose && typeof this.onclose == 'function') {
|
|
86
|
+
this.onclose();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
dragStart(e) {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
if (!this.zoomedIn) {
|
|
92
|
+
this.active = false;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (e.type === 'touchstart') {
|
|
96
|
+
this.initialX = e.touches[0].clientX - this.xOffset;
|
|
97
|
+
this.initialY = e.touches[0].clientY - this.yOffset;
|
|
98
|
+
} else {
|
|
99
|
+
this.initialX = e.clientX - this.xOffset;
|
|
100
|
+
this.initialY = e.clientY - this.yOffset;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (e.target === this.img) {
|
|
104
|
+
this.active = true;
|
|
105
|
+
this.img.classList.add('dragging');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
dragEnd(e) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
this.initialX = this.currentX;
|
|
111
|
+
this.initialY = this.currentY;
|
|
112
|
+
this.active = false;
|
|
113
|
+
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
this.dragging = false;
|
|
116
|
+
this.img.isDragging = false;
|
|
117
|
+
this.img.classList.remove('dragging');
|
|
118
|
+
}, 100);
|
|
119
|
+
}
|
|
120
|
+
drag(e) {
|
|
121
|
+
if (this.active) {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
|
|
124
|
+
if (e.type === 'touchmove') {
|
|
125
|
+
this.currentX = e.touches[0].clientX - this.initialX;
|
|
126
|
+
this.currentY = e.touches[0].clientY - this.initialY;
|
|
127
|
+
} else {
|
|
128
|
+
this.currentX = e.clientX - this.initialX;
|
|
129
|
+
this.currentY = e.clientY - this.initialY;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.xOffset = this.currentX;
|
|
133
|
+
this.yOffset = this.currentY;
|
|
134
|
+
|
|
135
|
+
this.img.isDragging = true;
|
|
136
|
+
this.dragging = true;
|
|
137
|
+
|
|
138
|
+
this.setTranslate(this.img, this.currentX, this.currentY);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
onMove(e) {
|
|
142
|
+
if (!this.zoomedIn) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let xOffset = e.clientX - this.img.naturalWidth / 2;
|
|
146
|
+
let yOffset = e.clientY - this.img.naturalHeight / 2;
|
|
147
|
+
|
|
148
|
+
this.setTranslate(this.img, xOffset, yOffset);
|
|
149
|
+
}
|
|
150
|
+
setTranslate(node, xPos, yPos) {
|
|
151
|
+
node.style.transform = 'translate3d(' + xPos + 'px, ' + yPos + 'px, 0)';
|
|
152
|
+
}
|
|
153
|
+
widowWidth() {
|
|
154
|
+
return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
155
|
+
}
|
|
156
|
+
}
|