1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function (global, factory) {
|
9 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
10 | typeof define === 'function' && define.amd ? define(factory) :
|
11 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lightGallery = factory());
|
12 | }(this, (function () { 'use strict';
|
13 |
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var __assign = function() {
|
30 | __assign = Object.assign || function __assign(t) {
|
31 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
32 | s = arguments[i];
|
33 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
34 | }
|
35 | return t;
|
36 | };
|
37 | return __assign.apply(this, arguments);
|
38 | };
|
39 |
|
40 | function __spreadArrays() {
|
41 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
42 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
43 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
44 | r[k] = a[j];
|
45 | return r;
|
46 | }
|
47 |
|
48 | (function () {
|
49 | if (typeof window.CustomEvent === 'function')
|
50 | return false;
|
51 | function CustomEvent(event, params) {
|
52 | params = params || { bubbles: false, cancelable: false, detail: null };
|
53 | var evt = document.createEvent('CustomEvent');
|
54 | evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
55 | return evt;
|
56 | }
|
57 | window.CustomEvent = CustomEvent;
|
58 | })();
|
59 | (function () {
|
60 | if (!Element.prototype.matches) {
|
61 | Element.prototype.matches =
|
62 | Element.prototype.msMatchesSelector ||
|
63 | Element.prototype.webkitMatchesSelector;
|
64 | }
|
65 | })();
|
66 | var lgQuery = (function () {
|
67 | function lgQuery(selector) {
|
68 | this.cssVenderPrefixes = [
|
69 | 'TransitionDuration',
|
70 | 'TransitionTimingFunction',
|
71 | 'Transform',
|
72 | 'Transition',
|
73 | ];
|
74 | this.selector = this._getSelector(selector);
|
75 | this.firstElement = this._getFirstEl();
|
76 | return this;
|
77 | }
|
78 | lgQuery.generateUUID = function () {
|
79 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
80 | var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
81 | return v.toString(16);
|
82 | });
|
83 | };
|
84 | lgQuery.prototype._getSelector = function (selector, context) {
|
85 | if (context === void 0) { context = document; }
|
86 | if (typeof selector !== 'string') {
|
87 | return selector;
|
88 | }
|
89 | context = context || document;
|
90 | var fl = selector.substring(0, 1);
|
91 | if (fl === '#') {
|
92 | return context.querySelector(selector);
|
93 | }
|
94 | else {
|
95 | return context.querySelectorAll(selector);
|
96 | }
|
97 | };
|
98 | lgQuery.prototype._each = function (func) {
|
99 | if (!this.selector) {
|
100 | return this;
|
101 | }
|
102 | if (this.selector.length !== undefined) {
|
103 | [].forEach.call(this.selector, func);
|
104 | }
|
105 | else {
|
106 | func(this.selector, 0);
|
107 | }
|
108 | return this;
|
109 | };
|
110 | lgQuery.prototype._setCssVendorPrefix = function (el, cssProperty, value) {
|
111 |
|
112 | var property = cssProperty.replace(/-([a-z])/gi, function (s, group1) {
|
113 | return group1.toUpperCase();
|
114 | });
|
115 | if (this.cssVenderPrefixes.indexOf(property) !== -1) {
|
116 | el.style[property.charAt(0).toLowerCase() + property.slice(1)] = value;
|
117 | el.style['webkit' + property] = value;
|
118 | el.style['moz' + property] = value;
|
119 | el.style['ms' + property] = value;
|
120 | el.style['o' + property] = value;
|
121 | }
|
122 | else {
|
123 | el.style[property] = value;
|
124 | }
|
125 | };
|
126 | lgQuery.prototype._getFirstEl = function () {
|
127 | if (this.selector && this.selector.length !== undefined) {
|
128 | return this.selector[0];
|
129 | }
|
130 | else {
|
131 | return this.selector;
|
132 | }
|
133 | };
|
134 | lgQuery.prototype.isEventMatched = function (event, eventName) {
|
135 | var eventNamespace = eventName.split('.');
|
136 | return event
|
137 | .split('.')
|
138 | .filter(function (e) { return e; })
|
139 | .every(function (e) {
|
140 | return eventNamespace.indexOf(e) !== -1;
|
141 | });
|
142 | };
|
143 | lgQuery.prototype.attr = function (attr, value) {
|
144 | if (value === undefined) {
|
145 | if (!this.firstElement) {
|
146 | return '';
|
147 | }
|
148 | return this.firstElement.getAttribute(attr);
|
149 | }
|
150 | this._each(function (el) {
|
151 | el.setAttribute(attr, value);
|
152 | });
|
153 | return this;
|
154 | };
|
155 | lgQuery.prototype.find = function (selector) {
|
156 | return $LG(this._getSelector(selector, this.selector));
|
157 | };
|
158 | lgQuery.prototype.first = function () {
|
159 | if (this.selector && this.selector.length !== undefined) {
|
160 | return $LG(this.selector[0]);
|
161 | }
|
162 | else {
|
163 | return $LG(this.selector);
|
164 | }
|
165 | };
|
166 | lgQuery.prototype.eq = function (index) {
|
167 | return $LG(this.selector[index]);
|
168 | };
|
169 | lgQuery.prototype.parent = function () {
|
170 | return $LG(this.selector.parentElement);
|
171 | };
|
172 | lgQuery.prototype.get = function () {
|
173 | return this._getFirstEl();
|
174 | };
|
175 | lgQuery.prototype.removeAttr = function (attributes) {
|
176 | var attrs = attributes.split(' ');
|
177 | this._each(function (el) {
|
178 | attrs.forEach(function (attr) { return el.removeAttribute(attr); });
|
179 | });
|
180 | return this;
|
181 | };
|
182 | lgQuery.prototype.wrap = function (className) {
|
183 | if (!this.firstElement) {
|
184 | return this;
|
185 | }
|
186 | var wrapper = document.createElement('div');
|
187 | wrapper.className = className;
|
188 | this.firstElement.parentNode.insertBefore(wrapper, this.firstElement);
|
189 | this.firstElement.parentNode.removeChild(this.firstElement);
|
190 | wrapper.appendChild(this.firstElement);
|
191 | return this;
|
192 | };
|
193 | lgQuery.prototype.addClass = function (classNames) {
|
194 | if (classNames === void 0) { classNames = ''; }
|
195 | this._each(function (el) {
|
196 |
|
197 | classNames.split(' ').forEach(function (className) {
|
198 | el.classList.add(className);
|
199 | });
|
200 | });
|
201 | return this;
|
202 | };
|
203 | lgQuery.prototype.removeClass = function (classNames) {
|
204 | this._each(function (el) {
|
205 |
|
206 | classNames.split(' ').forEach(function (className) {
|
207 | el.classList.remove(className);
|
208 | });
|
209 | });
|
210 | return this;
|
211 | };
|
212 | lgQuery.prototype.hasClass = function (className) {
|
213 | if (!this.firstElement) {
|
214 | return false;
|
215 | }
|
216 | return this.firstElement.classList.contains(className);
|
217 | };
|
218 | lgQuery.prototype.hasAttribute = function (attribute) {
|
219 | if (!this.firstElement) {
|
220 | return false;
|
221 | }
|
222 | return this.firstElement.hasAttribute(attribute);
|
223 | };
|
224 | lgQuery.prototype.toggleClass = function (className) {
|
225 | if (!this.firstElement) {
|
226 | return this;
|
227 | }
|
228 | if (this.hasClass(className)) {
|
229 | this.removeClass(className);
|
230 | }
|
231 | else {
|
232 | this.addClass(className);
|
233 | }
|
234 | return this;
|
235 | };
|
236 | lgQuery.prototype.css = function (property, value) {
|
237 | var _this = this;
|
238 | this._each(function (el) {
|
239 | _this._setCssVendorPrefix(el, property, value);
|
240 | });
|
241 | return this;
|
242 | };
|
243 |
|
244 | lgQuery.prototype.on = function (events, listener) {
|
245 | var _this = this;
|
246 | if (!this.selector) {
|
247 | return this;
|
248 | }
|
249 | events.split(' ').forEach(function (event) {
|
250 | if (!Array.isArray(lgQuery.eventListeners[event])) {
|
251 | lgQuery.eventListeners[event] = [];
|
252 | }
|
253 | lgQuery.eventListeners[event].push(listener);
|
254 | _this.selector.addEventListener(event.split('.')[0], listener);
|
255 | });
|
256 | return this;
|
257 | };
|
258 |
|
259 | lgQuery.prototype.once = function (event, listener) {
|
260 | var _this = this;
|
261 | this.on(event, function () {
|
262 | _this.off(event);
|
263 | listener(event);
|
264 | });
|
265 | return this;
|
266 | };
|
267 | lgQuery.prototype.off = function (event) {
|
268 | var _this = this;
|
269 | if (!this.selector) {
|
270 | return this;
|
271 | }
|
272 | Object.keys(lgQuery.eventListeners).forEach(function (eventName) {
|
273 | if (_this.isEventMatched(event, eventName)) {
|
274 | lgQuery.eventListeners[eventName].forEach(function (listener) {
|
275 | _this.selector.removeEventListener(eventName.split('.')[0], listener);
|
276 | });
|
277 | lgQuery.eventListeners[eventName] = [];
|
278 | }
|
279 | });
|
280 | return this;
|
281 | };
|
282 | lgQuery.prototype.trigger = function (event, detail) {
|
283 | if (!this.firstElement) {
|
284 | return this;
|
285 | }
|
286 | var customEvent = new CustomEvent(event.split('.')[0], {
|
287 | detail: detail || null,
|
288 | });
|
289 | this.firstElement.dispatchEvent(customEvent);
|
290 | return this;
|
291 | };
|
292 |
|
293 | lgQuery.prototype.load = function (url) {
|
294 | var _this = this;
|
295 | fetch(url).then(function (res) {
|
296 | _this.selector.innerHTML = res;
|
297 | });
|
298 | return this;
|
299 | };
|
300 | lgQuery.prototype.html = function (html) {
|
301 | if (html === undefined) {
|
302 | if (!this.firstElement) {
|
303 | return '';
|
304 | }
|
305 | return this.firstElement.innerHTML;
|
306 | }
|
307 | this._each(function (el) {
|
308 | el.innerHTML = html;
|
309 | });
|
310 | return this;
|
311 | };
|
312 | lgQuery.prototype.append = function (html) {
|
313 | this._each(function (el) {
|
314 | if (typeof html === 'string') {
|
315 | el.insertAdjacentHTML('beforeend', html);
|
316 | }
|
317 | else {
|
318 | el.appendChild(html);
|
319 | }
|
320 | });
|
321 | return this;
|
322 | };
|
323 | lgQuery.prototype.prepend = function (html) {
|
324 | this._each(function (el) {
|
325 | el.insertAdjacentHTML('afterbegin', html);
|
326 | });
|
327 | return this;
|
328 | };
|
329 | lgQuery.prototype.remove = function () {
|
330 | this._each(function (el) {
|
331 | el.parentNode.removeChild(el);
|
332 | });
|
333 | return this;
|
334 | };
|
335 | lgQuery.prototype.empty = function () {
|
336 | this._each(function (el) {
|
337 | el.innerHTML = '';
|
338 | });
|
339 | return this;
|
340 | };
|
341 | lgQuery.prototype.scrollTop = function (scrollTop) {
|
342 | if (scrollTop !== undefined) {
|
343 | document.body.scrollTop = scrollTop;
|
344 | document.documentElement.scrollTop = scrollTop;
|
345 | return this;
|
346 | }
|
347 | else {
|
348 | return (window.pageYOffset ||
|
349 | document.documentElement.scrollTop ||
|
350 | document.body.scrollTop ||
|
351 | 0);
|
352 | }
|
353 | };
|
354 | lgQuery.prototype.scrollLeft = function (scrollLeft) {
|
355 | if (scrollLeft !== undefined) {
|
356 | document.body.scrollLeft = scrollLeft;
|
357 | document.documentElement.scrollLeft = scrollLeft;
|
358 | return this;
|
359 | }
|
360 | else {
|
361 | return (window.pageXOffset ||
|
362 | document.documentElement.scrollLeft ||
|
363 | document.body.scrollLeft ||
|
364 | 0);
|
365 | }
|
366 | };
|
367 | lgQuery.prototype.offset = function () {
|
368 | if (!this.firstElement) {
|
369 | return {
|
370 | left: 0,
|
371 | top: 0,
|
372 | };
|
373 | }
|
374 | var rect = this.firstElement.getBoundingClientRect();
|
375 | var bodyMarginLeft = $LG('body').style().marginLeft;
|
376 |
|
377 | return {
|
378 | left: rect.left - parseFloat(bodyMarginLeft) + this.scrollLeft(),
|
379 | top: rect.top + this.scrollTop(),
|
380 | };
|
381 | };
|
382 | lgQuery.prototype.style = function () {
|
383 | if (!this.firstElement) {
|
384 | return {};
|
385 | }
|
386 | return (this.firstElement.currentStyle ||
|
387 | window.getComputedStyle(this.firstElement));
|
388 | };
|
389 |
|
390 | lgQuery.prototype.width = function () {
|
391 | var style = this.style();
|
392 | return (this.firstElement.clientWidth -
|
393 | parseFloat(style.paddingLeft) -
|
394 | parseFloat(style.paddingRight));
|
395 | };
|
396 |
|
397 | lgQuery.prototype.height = function () {
|
398 | var style = this.style();
|
399 | return (this.firstElement.clientHeight -
|
400 | parseFloat(style.paddingTop) -
|
401 | parseFloat(style.paddingBottom));
|
402 | };
|
403 | lgQuery.eventListeners = {};
|
404 | return lgQuery;
|
405 | }());
|
406 | function $LG(selector) {
|
407 | return new lgQuery(selector);
|
408 | }
|
409 |
|
410 | var defaultDynamicOptions = [
|
411 | 'src',
|
412 | 'sources',
|
413 | 'subHtml',
|
414 | 'subHtmlUrl',
|
415 | 'html',
|
416 | 'video',
|
417 | 'poster',
|
418 | 'slideName',
|
419 | 'responsive',
|
420 | 'srcset',
|
421 | 'sizes',
|
422 | 'iframe',
|
423 | 'downloadUrl',
|
424 | 'download',
|
425 | 'width',
|
426 | 'facebookShareUrl',
|
427 | 'tweetText',
|
428 | 'iframeTitle',
|
429 | 'twitterShareUrl',
|
430 | 'pinterestShareUrl',
|
431 | 'pinterestText',
|
432 | 'fbHtml',
|
433 | 'disqusIdentifier',
|
434 | 'disqusUrl',
|
435 | ];
|
436 |
|
437 | function convertToData(attr) {
|
438 |
|
439 | if (attr === 'href') {
|
440 | return 'src';
|
441 | }
|
442 | attr = attr.replace('data-', '');
|
443 | attr = attr.charAt(0).toLowerCase() + attr.slice(1);
|
444 | attr = attr.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
445 | return attr;
|
446 | }
|
447 | var utils = {
|
448 | |
449 |
|
450 |
|
451 | getSize: function (el, container, spacing, defaultLgSize) {
|
452 | if (spacing === void 0) { spacing = 0; }
|
453 | var LGel = $LG(el);
|
454 | var lgSize = LGel.attr('data-lg-size') || defaultLgSize;
|
455 | if (!lgSize) {
|
456 | return;
|
457 | }
|
458 | var isResponsiveSizes = lgSize.split(',');
|
459 |
|
460 | if (isResponsiveSizes[1]) {
|
461 | var wWidth = window.innerWidth;
|
462 | for (var i = 0; i < isResponsiveSizes.length; i++) {
|
463 | var size_1 = isResponsiveSizes[i];
|
464 | var responsiveWidth = parseInt(size_1.split('-')[2], 10);
|
465 | if (responsiveWidth > wWidth) {
|
466 | lgSize = size_1;
|
467 | break;
|
468 | }
|
469 |
|
470 | if (i === isResponsiveSizes.length - 1) {
|
471 | lgSize = size_1;
|
472 | }
|
473 | }
|
474 | }
|
475 | var size = lgSize.split('-');
|
476 | var width = parseInt(size[0], 10);
|
477 | var height = parseInt(size[1], 10);
|
478 | var cWidth = container.width();
|
479 | var cHeight = container.height() - spacing;
|
480 | var maxWidth = Math.min(cWidth, width);
|
481 | var maxHeight = Math.min(cHeight, height);
|
482 | var ratio = Math.min(maxWidth / width, maxHeight / height);
|
483 | return { width: width * ratio, height: height * ratio };
|
484 | },
|
485 | |
486 |
|
487 |
|
488 |
|
489 |
|
490 | getTransform: function (el, container, top, bottom, imageSize) {
|
491 | if (!imageSize) {
|
492 | return;
|
493 | }
|
494 | var LGel = $LG(el).find('img').first();
|
495 | if (!LGel.get()) {
|
496 | return;
|
497 | }
|
498 | var containerRect = container.get().getBoundingClientRect();
|
499 | var wWidth = containerRect.width;
|
500 |
|
501 | var wHeight = container.height() - (top + bottom);
|
502 | var elWidth = LGel.width();
|
503 | var elHeight = LGel.height();
|
504 | var elStyle = LGel.style();
|
505 | var x = (wWidth - elWidth) / 2 -
|
506 | LGel.offset().left +
|
507 | (parseFloat(elStyle.paddingLeft) || 0) +
|
508 | (parseFloat(elStyle.borderLeft) || 0) +
|
509 | $LG(window).scrollLeft() +
|
510 | containerRect.left;
|
511 | var y = (wHeight - elHeight) / 2 -
|
512 | LGel.offset().top +
|
513 | (parseFloat(elStyle.paddingTop) || 0) +
|
514 | (parseFloat(elStyle.borderTop) || 0) +
|
515 | $LG(window).scrollTop() +
|
516 | top;
|
517 | var scX = elWidth / imageSize.width;
|
518 | var scY = elHeight / imageSize.height;
|
519 | var transform = 'translate3d(' +
|
520 | (x *= -1) +
|
521 | 'px, ' +
|
522 | (y *= -1) +
|
523 | 'px, 0) scale3d(' +
|
524 | scX +
|
525 | ', ' +
|
526 | scY +
|
527 | ', 1)';
|
528 | return transform;
|
529 | },
|
530 | getIframeMarkup: function (iframeWidth, iframeHeight, src, iframeTitle) {
|
531 | var title = iframeTitle ? 'title="' + iframeTitle + '"' : '';
|
532 | return "<div class=\"lg-video-cont lg-has-iframe\" style=\"width:" + iframeWidth + "; height: " + iframeHeight + "\">\n <iframe class=\"lg-object\" frameborder=\"0\" " + title + " src=\"" + src + "\" allowfullscreen=\"true\"></iframe>\n </div>";
|
533 | },
|
534 | getImgMarkup: function (index, src, altAttr, srcset, sizes, sources) {
|
535 | var srcsetAttr = srcset ? "srcset=\"" + srcset + "\"" : '';
|
536 | var sizesAttr = sizes ? "sizes=\"" + sizes + "\"" : '';
|
537 | var imgMarkup = "<img " + altAttr + " " + srcsetAttr + " " + sizesAttr + " class=\"lg-object lg-image\" data-index=\"" + index + "\" src=\"" + src + "\" />";
|
538 | var sourceTag = '';
|
539 | if (sources) {
|
540 | var sourceObj = typeof sources === 'string' ? JSON.parse(sources) : sources;
|
541 | sourceTag = sourceObj.map(function (source) {
|
542 | var attrs = '';
|
543 | Object.keys(source).forEach(function (key) {
|
544 |
|
545 | attrs += " " + key + "=\"" + source[key] + "\"";
|
546 | });
|
547 | return "<source " + attrs + "></source>";
|
548 | });
|
549 | }
|
550 | return "" + sourceTag + imgMarkup;
|
551 | },
|
552 |
|
553 | getResponsiveSrc: function (srcItms) {
|
554 | var rsWidth = [];
|
555 | var rsSrc = [];
|
556 | var src = '';
|
557 | for (var i = 0; i < srcItms.length; i++) {
|
558 | var _src = srcItms[i].split(' ');
|
559 |
|
560 | if (_src[0] === '') {
|
561 | _src.splice(0, 1);
|
562 | }
|
563 | rsSrc.push(_src[0]);
|
564 | rsWidth.push(_src[1]);
|
565 | }
|
566 | var wWidth = window.innerWidth;
|
567 | for (var j = 0; j < rsWidth.length; j++) {
|
568 | if (parseInt(rsWidth[j], 10) > wWidth) {
|
569 | src = rsSrc[j];
|
570 | break;
|
571 | }
|
572 | }
|
573 | return src;
|
574 | },
|
575 | isImageLoaded: function (img) {
|
576 | if (!img)
|
577 | return false;
|
578 |
|
579 |
|
580 |
|
581 | if (!img.complete) {
|
582 | return false;
|
583 | }
|
584 |
|
585 |
|
586 |
|
587 | if (img.naturalWidth === 0) {
|
588 | return false;
|
589 | }
|
590 |
|
591 | return true;
|
592 | },
|
593 | getVideoPosterMarkup: function (_poster, dummyImg, videoContStyle, _isVideo) {
|
594 | var videoClass = '';
|
595 | if (_isVideo && _isVideo.youtube) {
|
596 | videoClass = 'lg-has-youtube';
|
597 | }
|
598 | else if (_isVideo && _isVideo.vimeo) {
|
599 | videoClass = 'lg-has-vimeo';
|
600 | }
|
601 | else {
|
602 | videoClass = 'lg-has-html5';
|
603 | }
|
604 | return "<div class=\"lg-video-cont " + videoClass + "\" style=\"" + videoContStyle + "\">\n <div class=\"lg-video-play-button\">\n <svg\n viewBox=\"0 0 20 20\"\n preserveAspectRatio=\"xMidYMid\"\n focusable=\"false\"\n aria-labelledby=\"Play video\"\n role=\"img\"\n class=\"lg-video-play-icon\"\n >\n <title>Play video</title>\n <polygon class=\"lg-video-play-icon-inner\" points=\"1,0 20,10 1,20\"></polygon>\n </svg>\n <svg class=\"lg-video-play-icon-bg\" viewBox=\"0 0 50 50\" focusable=\"false\">\n <circle cx=\"50%\" cy=\"50%\" r=\"20\"></circle></svg>\n <svg class=\"lg-video-play-icon-circle\" viewBox=\"0 0 50 50\" focusable=\"false\">\n <circle cx=\"50%\" cy=\"50%\" r=\"20\"></circle>\n </svg>\n </div>\n " + (dummyImg || '') + "\n <img class=\"lg-object lg-video-poster\" src=\"" + _poster + "\" />\n </div>";
|
605 | },
|
606 | |
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | getDynamicOptions: function (items, extraProps, getCaptionFromTitleOrAlt, exThumbImage) {
|
614 | var dynamicElements = [];
|
615 | var availableDynamicOptions = __spreadArrays(defaultDynamicOptions, extraProps);
|
616 | [].forEach.call(items, function (item) {
|
617 | var dynamicEl = {};
|
618 | for (var i = 0; i < item.attributes.length; i++) {
|
619 | var attr = item.attributes[i];
|
620 | if (attr.specified) {
|
621 | var dynamicAttr = convertToData(attr.name);
|
622 | var label = '';
|
623 | if (availableDynamicOptions.indexOf(dynamicAttr) > -1) {
|
624 | label = dynamicAttr;
|
625 | }
|
626 | if (label) {
|
627 | dynamicEl[label] = attr.value;
|
628 | }
|
629 | }
|
630 | }
|
631 | var currentItem = $LG(item);
|
632 | var alt = currentItem.find('img').first().attr('alt');
|
633 | var title = currentItem.attr('title');
|
634 | var thumb = exThumbImage
|
635 | ? currentItem.attr(exThumbImage)
|
636 | : currentItem.find('img').first().attr('src');
|
637 | dynamicEl.thumb = thumb;
|
638 | if (getCaptionFromTitleOrAlt && !dynamicEl.subHtml) {
|
639 | dynamicEl.subHtml = title || alt || '';
|
640 | }
|
641 | dynamicEl.alt = alt || title || '';
|
642 | dynamicElements.push(dynamicEl);
|
643 | });
|
644 | return dynamicElements;
|
645 | },
|
646 | isMobile: function () {
|
647 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
648 | },
|
649 | };
|
650 |
|
651 | var lightGalleryCoreSettings = {
|
652 | mode: 'lg-slide',
|
653 | easing: 'ease',
|
654 | speed: 400,
|
655 | licenseKey: '0000-0000-000-0000',
|
656 | height: '100%',
|
657 | width: '100%',
|
658 | addClass: '',
|
659 | startClass: 'lg-start-zoom',
|
660 | backdropDuration: 300,
|
661 | container: document.body,
|
662 | startAnimationDuration: 400,
|
663 | zoomFromOrigin: true,
|
664 | hideBarsDelay: 0,
|
665 | showBarsAfter: 10000,
|
666 | slideDelay: 0,
|
667 | supportLegacyBrowser: true,
|
668 | allowMediaOverlap: false,
|
669 | videoMaxSize: '1280-720',
|
670 | defaultCaptionHeight: 0,
|
671 | ariaLabelledby: '',
|
672 | ariaDescribedby: '',
|
673 | closable: true,
|
674 | swipeToClose: true,
|
675 | closeOnTap: true,
|
676 | showCloseIcon: true,
|
677 | showMaximizeIcon: false,
|
678 | loop: true,
|
679 | escKey: true,
|
680 | keyPress: true,
|
681 | controls: true,
|
682 | slideEndAnimation: true,
|
683 | hideControlOnEnd: false,
|
684 | mousewheel: false,
|
685 | getCaptionFromTitleOrAlt: true,
|
686 | appendSubHtmlTo: '.lg-sub-html',
|
687 | subHtmlSelectorRelative: false,
|
688 | preload: 2,
|
689 | numberOfSlideItemsInDom: 10,
|
690 | showAfterLoad: true,
|
691 | selector: '',
|
692 | selectWithin: '',
|
693 | nextHtml: '',
|
694 | prevHtml: '',
|
695 | index: 0,
|
696 | iframeWidth: '100%',
|
697 | iframeHeight: '100%',
|
698 | download: true,
|
699 | counter: true,
|
700 | appendCounterTo: '.lg-toolbar',
|
701 | swipeThreshold: 50,
|
702 | enableSwipe: true,
|
703 | enableDrag: true,
|
704 | dynamic: false,
|
705 | dynamicEl: [],
|
706 | extraProps: [],
|
707 | exThumbImage: '',
|
708 | isMobile: undefined,
|
709 | mobileSettings: {
|
710 | controls: false,
|
711 | showCloseIcon: false,
|
712 | download: false,
|
713 | },
|
714 | plugins: [],
|
715 | };
|
716 |
|
717 | |
718 |
|
719 |
|
720 |
|
721 |
|
722 | var lGEvents = {
|
723 | afterAppendSlide: 'lgAfterAppendSlide',
|
724 | init: 'lgInit',
|
725 | hasVideo: 'lgHasVideo',
|
726 | containerResize: 'lgContainerResize',
|
727 | updateSlides: 'lgUpdateSlides',
|
728 | afterAppendSubHtml: 'lgAfterAppendSubHtml',
|
729 | beforeOpen: 'lgBeforeOpen',
|
730 | afterOpen: 'lgAfterOpen',
|
731 | slideItemLoad: 'lgSlideItemLoad',
|
732 | beforeSlide: 'lgBeforeSlide',
|
733 | afterSlide: 'lgAfterSlide',
|
734 | posterClick: 'lgPosterClick',
|
735 | dragStart: 'lgDragStart',
|
736 | dragMove: 'lgDragMove',
|
737 | dragEnd: 'lgDragEnd',
|
738 | beforeNextSlide: 'lgBeforeNextSlide',
|
739 | beforePrevSlide: 'lgBeforePrevSlide',
|
740 | beforeClose: 'lgBeforeClose',
|
741 | afterClose: 'lgAfterClose',
|
742 | rotateLeft: 'lgRotateLeft',
|
743 | rotateRight: 'lgRotateRight',
|
744 | flipHorizontal: 'lgFlipHorizontal',
|
745 | flipVertical: 'lgFlipVertical',
|
746 | };
|
747 |
|
748 |
|
749 |
|
750 |
|
751 | var lgId = 0;
|
752 | var LightGallery = (function () {
|
753 | function LightGallery(element, options) {
|
754 | this.lgOpened = false;
|
755 | this.index = 0;
|
756 |
|
757 | this.plugins = [];
|
758 |
|
759 | this.lGalleryOn = false;
|
760 |
|
761 | this.lgBusy = false;
|
762 | this.currentItemsInDom = [];
|
763 |
|
764 | this.prevScrollTop = 0;
|
765 | this.isDummyImageRemoved = false;
|
766 | this.dragOrSwipeEnabled = false;
|
767 | this.mediaContainerPosition = {
|
768 | top: 0,
|
769 | bottom: 0,
|
770 | };
|
771 | if (!element) {
|
772 | return this;
|
773 | }
|
774 | lgId++;
|
775 | this.lgId = lgId;
|
776 | this.el = element;
|
777 | this.LGel = $LG(element);
|
778 | this.generateSettings(options);
|
779 | this.buildModules();
|
780 |
|
781 | if (this.settings.dynamic &&
|
782 | this.settings.dynamicEl !== undefined &&
|
783 | !Array.isArray(this.settings.dynamicEl)) {
|
784 | throw 'When using dynamic mode, you must also define dynamicEl as an Array.';
|
785 | }
|
786 | this.galleryItems = this.getItems();
|
787 | this.normalizeSettings();
|
788 |
|
789 | this.init();
|
790 | this.validateLicense();
|
791 | return this;
|
792 | }
|
793 | LightGallery.prototype.generateSettings = function (options) {
|
794 |
|
795 | this.settings = __assign(__assign({}, lightGalleryCoreSettings), options);
|
796 | if (this.settings.isMobile &&
|
797 | typeof this.settings.isMobile === 'function'
|
798 | ? this.settings.isMobile()
|
799 | : utils.isMobile()) {
|
800 | var mobileSettings = __assign(__assign({}, this.settings.mobileSettings), this.settings.mobileSettings);
|
801 | this.settings = __assign(__assign({}, this.settings), mobileSettings);
|
802 | }
|
803 | };
|
804 | LightGallery.prototype.normalizeSettings = function () {
|
805 | if (this.settings.slideEndAnimation) {
|
806 | this.settings.hideControlOnEnd = false;
|
807 | }
|
808 | if (!this.settings.closable) {
|
809 | this.settings.swipeToClose = false;
|
810 | }
|
811 |
|
812 | this.zoomFromOrigin = this.settings.zoomFromOrigin;
|
813 |
|
814 |
|
815 | if (this.settings.dynamic) {
|
816 | this.zoomFromOrigin = false;
|
817 | }
|
818 | if (!this.settings.container) {
|
819 | this.settings.container = document.body;
|
820 | }
|
821 |
|
822 | this.settings.preload = Math.min(this.settings.preload, this.galleryItems.length);
|
823 | };
|
824 | LightGallery.prototype.init = function () {
|
825 | var _this = this;
|
826 | this.addSlideVideoInfo(this.galleryItems);
|
827 | this.buildStructure();
|
828 | this.LGel.trigger(lGEvents.init, {
|
829 | instance: this,
|
830 | });
|
831 | if (this.settings.keyPress) {
|
832 | this.keyPress();
|
833 | }
|
834 | setTimeout(function () {
|
835 | _this.enableDrag();
|
836 | _this.enableSwipe();
|
837 | _this.triggerPosterClick();
|
838 | }, 50);
|
839 | this.arrow();
|
840 | if (this.settings.mousewheel) {
|
841 | this.mousewheel();
|
842 | }
|
843 | if (!this.settings.dynamic) {
|
844 | this.openGalleryOnItemClick();
|
845 | }
|
846 | };
|
847 | LightGallery.prototype.openGalleryOnItemClick = function () {
|
848 | var _this = this;
|
849 | var _loop_1 = function (index) {
|
850 | var element = this_1.items[index];
|
851 | var $element = $LG(element);
|
852 |
|
853 |
|
854 | var uuid = lgQuery.generateUUID();
|
855 | $element
|
856 | .attr('data-lg-id', uuid)
|
857 | .on("click.lgcustom-item-" + uuid, function (e) {
|
858 | e.preventDefault();
|
859 | var currentItemIndex = _this.settings.index || index;
|
860 | _this.openGallery(currentItemIndex, element);
|
861 | });
|
862 | };
|
863 | var this_1 = this;
|
864 |
|
865 | for (var index = 0; index < this.items.length; index++) {
|
866 | _loop_1(index);
|
867 | }
|
868 | };
|
869 | |
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 | LightGallery.prototype.buildModules = function () {
|
876 | var _this = this;
|
877 | this.settings.plugins.forEach(function (plugin) {
|
878 | _this.plugins.push(new plugin(_this, $LG));
|
879 | });
|
880 | };
|
881 | LightGallery.prototype.validateLicense = function () {
|
882 | if (!this.settings.licenseKey) {
|
883 | console.error('Please provide a valid license key');
|
884 | }
|
885 | else if (this.settings.licenseKey === '0000-0000-000-0000') {
|
886 | console.warn("lightGallery: " + this.settings.licenseKey + " license key is not valid for production use");
|
887 | }
|
888 | };
|
889 | LightGallery.prototype.getSlideItem = function (index) {
|
890 | return $LG(this.getSlideItemId(index));
|
891 | };
|
892 | LightGallery.prototype.getSlideItemId = function (index) {
|
893 | return "#lg-item-" + this.lgId + "-" + index;
|
894 | };
|
895 | LightGallery.prototype.getIdName = function (id) {
|
896 | return id + "-" + this.lgId;
|
897 | };
|
898 | LightGallery.prototype.getElementById = function (id) {
|
899 | return $LG("#" + this.getIdName(id));
|
900 | };
|
901 | LightGallery.prototype.manageSingleSlideClassName = function () {
|
902 | if (this.galleryItems.length < 2) {
|
903 | this.outer.addClass('lg-single-item');
|
904 | }
|
905 | else {
|
906 | this.outer.removeClass('lg-single-item');
|
907 | }
|
908 | };
|
909 | LightGallery.prototype.buildStructure = function () {
|
910 | var _this = this;
|
911 | var container = this.$container && this.$container.get();
|
912 | if (container) {
|
913 | return;
|
914 | }
|
915 | var controls = '';
|
916 | var subHtmlCont = '';
|
917 |
|
918 | if (this.settings.controls) {
|
919 | controls = "<button type=\"button\" id=\"" + this.getIdName('lg-prev') + "\" aria-label=\"Previous slide\" class=\"lg-prev lg-icon\"> " + this.settings.prevHtml + " </button>\n <button type=\"button\" id=\"" + this.getIdName('lg-next') + "\" aria-label=\"Next slide\" class=\"lg-next lg-icon\"> " + this.settings.nextHtml + " </button>";
|
920 | }
|
921 | if (this.settings.appendSubHtmlTo !== '.lg-item') {
|
922 | subHtmlCont =
|
923 | '<div class="lg-sub-html" role="status" aria-live="polite"></div>';
|
924 | }
|
925 | var addClasses = '';
|
926 | if (this.settings.allowMediaOverlap) {
|
927 |
|
928 | addClasses += 'lg-media-overlap ';
|
929 | }
|
930 | var ariaLabelledby = this.settings.ariaLabelledby
|
931 | ? 'aria-labelledby="' + this.settings.ariaLabelledby + '"'
|
932 | : '';
|
933 | var ariaDescribedby = this.settings.ariaDescribedby
|
934 | ? 'aria-describedby="' + this.settings.ariaDescribedby + '"'
|
935 | : '';
|
936 | var containerClassName = "lg-container " + this.settings.addClass + " " + (document.body !== this.settings.container ? 'lg-inline' : '');
|
937 | var closeIcon = this.settings.closable && this.settings.showCloseIcon
|
938 | ? "<button type=\"button\" aria-label=\"Close gallery\" id=\"" + this.getIdName('lg-close') + "\" class=\"lg-close lg-icon\"></button>"
|
939 | : '';
|
940 | var maximizeIcon = this.settings.showMaximizeIcon
|
941 | ? "<button type=\"button\" aria-label=\"Toggle maximize\" id=\"" + this.getIdName('lg-maximize') + "\" class=\"lg-maximize lg-icon\"></button>"
|
942 | : '';
|
943 | var template = "\n <div class=\"" + containerClassName + "\" id=\"" + this.getIdName('lg-container') + "\" tabindex=\"-1\" aria-modal=\"true\" " + ariaLabelledby + " " + ariaDescribedby + " role=\"dialog\"\n >\n <div id=\"" + this.getIdName('lg-backdrop') + "\" class=\"lg-backdrop\"></div>\n\n <div id=\"" + this.getIdName('lg-outer') + "\" class=\"lg-outer lg-use-css3 lg-css3 lg-hide-items " + addClasses + " \">\n\n <div id=\"" + this.getIdName('lg-content') + "\" class=\"lg-content\">\n <div id=\"" + this.getIdName('lg-inner') + "\" class=\"lg-inner\">\n </div>\n " + controls + "\n </div>\n <div id=\"" + this.getIdName('lg-toolbar') + "\" class=\"lg-toolbar lg-group\">\n " + maximizeIcon + "\n " + closeIcon + "\n </div>\n " + (this.settings.appendSubHtmlTo === '.lg-outer'
|
944 | ? subHtmlCont
|
945 | : '') + "\n <div id=\"" + this.getIdName('lg-components') + "\" class=\"lg-components\">\n " + (this.settings.appendSubHtmlTo === '.lg-sub-html'
|
946 | ? subHtmlCont
|
947 | : '') + "\n </div>\n </div>\n </div>\n ";
|
948 | $LG(this.settings.container)
|
949 | .css('position', 'relative')
|
950 | .append(template);
|
951 | this.outer = this.getElementById('lg-outer');
|
952 | this.$lgComponents = this.getElementById('lg-components');
|
953 | this.$backdrop = this.getElementById('lg-backdrop');
|
954 | this.$container = this.getElementById('lg-container');
|
955 | this.$inner = this.getElementById('lg-inner');
|
956 | this.$content = this.getElementById('lg-content');
|
957 | this.$toolbar = this.getElementById('lg-toolbar');
|
958 | this.$backdrop.css('transition-duration', this.settings.backdropDuration + 'ms');
|
959 | var outerClassNames = this.settings.mode + " ";
|
960 | this.manageSingleSlideClassName();
|
961 | if (this.settings.enableDrag) {
|
962 | outerClassNames += 'lg-grab ';
|
963 | }
|
964 | if (this.settings.showAfterLoad) {
|
965 | outerClassNames += 'lg-show-after-load';
|
966 | }
|
967 | this.outer.addClass(outerClassNames);
|
968 | this.$inner.css('transition-timing-function', this.settings.easing);
|
969 | this.$inner.css('transition-duration', this.settings.speed + 'ms');
|
970 | if (this.settings.download) {
|
971 | this.$toolbar.append("<a id=\"" + this.getIdName('lg-download') + "\" target=\"_blank\" rel=\"noopener\" aria-label=\"Download\" download class=\"lg-download lg-icon\"></a>");
|
972 | }
|
973 | this.counter();
|
974 | $LG(window).on("resize.lg.global" + this.lgId + " orientationchange.lg.global" + this.lgId, function () {
|
975 | _this.refreshOnResize();
|
976 | });
|
977 | this.hideBars();
|
978 | this.manageCloseGallery();
|
979 | this.toggleMaximize();
|
980 | this.initModules();
|
981 | };
|
982 | LightGallery.prototype.refreshOnResize = function () {
|
983 | if (this.lgOpened) {
|
984 | var currentGalleryItem = this.galleryItems[this.index];
|
985 | var videoInfo = currentGalleryItem.__slideVideoInfo;
|
986 | this.mediaContainerPosition = this.getMediaContainerPosition();
|
987 | var _a = this.mediaContainerPosition, top_1 = _a.top, bottom = _a.bottom;
|
988 | this.currentImageSize = utils.getSize(this.items[this.index], this.outer, top_1 + bottom, videoInfo && this.settings.videoMaxSize);
|
989 | if (videoInfo) {
|
990 | this.resizeVideoSlide(this.index, this.currentImageSize);
|
991 | }
|
992 | if (this.zoomFromOrigin && !this.isDummyImageRemoved) {
|
993 | var imgStyle = this.getDummyImgStyles(this.currentImageSize);
|
994 | this.outer
|
995 | .find('.lg-current .lg-dummy-img')
|
996 | .first()
|
997 | .attr('style', imgStyle);
|
998 | }
|
999 | this.LGel.trigger(lGEvents.containerResize);
|
1000 | }
|
1001 | };
|
1002 | LightGallery.prototype.resizeVideoSlide = function (index, imageSize) {
|
1003 | var lgVideoStyle = this.getVideoContStyle(imageSize);
|
1004 | var currentSlide = this.getSlideItem(index);
|
1005 | currentSlide.find('.lg-video-cont').attr('style', lgVideoStyle);
|
1006 | };
|
1007 | |
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 | LightGallery.prototype.updateSlides = function (items, index) {
|
1050 | if (this.index > items.length - 1) {
|
1051 | this.index = items.length - 1;
|
1052 | }
|
1053 | if (items.length === 1) {
|
1054 | this.index = 0;
|
1055 | }
|
1056 | if (!items.length) {
|
1057 | this.closeGallery();
|
1058 | return;
|
1059 | }
|
1060 | var currentSrc = this.galleryItems[index].src;
|
1061 | this.galleryItems = items;
|
1062 | this.updateControls();
|
1063 | this.$inner.empty();
|
1064 | this.currentItemsInDom = [];
|
1065 | var _index = 0;
|
1066 |
|
1067 | this.galleryItems.some(function (galleryItem, itemIndex) {
|
1068 | if (galleryItem.src === currentSrc) {
|
1069 | _index = itemIndex;
|
1070 | return true;
|
1071 | }
|
1072 | return false;
|
1073 | });
|
1074 | this.currentItemsInDom = this.organizeSlideItems(_index, -1);
|
1075 | this.loadContent(_index, true);
|
1076 | this.getSlideItem(_index).addClass('lg-current');
|
1077 | this.index = _index;
|
1078 | this.updateCurrentCounter(_index);
|
1079 | this.LGel.trigger(lGEvents.updateSlides);
|
1080 | };
|
1081 |
|
1082 | LightGallery.prototype.getItems = function () {
|
1083 |
|
1084 | this.items = [];
|
1085 | if (!this.settings.dynamic) {
|
1086 | if (this.settings.selector === 'this') {
|
1087 | this.items.push(this.el);
|
1088 | }
|
1089 | else if (this.settings.selector) {
|
1090 | if (typeof this.settings.selector === 'string') {
|
1091 | if (this.settings.selectWithin) {
|
1092 | var selectWithin = $LG(this.settings.selectWithin);
|
1093 | this.items = selectWithin
|
1094 | .find(this.settings.selector)
|
1095 | .get();
|
1096 | }
|
1097 | else {
|
1098 | this.items = this.el.querySelectorAll(this.settings.selector);
|
1099 | }
|
1100 | }
|
1101 | else {
|
1102 | this.items = this.settings.selector;
|
1103 | }
|
1104 | }
|
1105 | else {
|
1106 | this.items = this.el.children;
|
1107 | }
|
1108 | return utils.getDynamicOptions(this.items, this.settings.extraProps, this.settings.getCaptionFromTitleOrAlt, this.settings.exThumbImage);
|
1109 | }
|
1110 | else {
|
1111 | return this.settings.dynamicEl || [];
|
1112 | }
|
1113 | };
|
1114 | |
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 | LightGallery.prototype.openGallery = function (index, element) {
|
1143 | var _this = this;
|
1144 | if (index === void 0) { index = this.settings.index; }
|
1145 |
|
1146 | if (this.lgOpened)
|
1147 | return;
|
1148 | this.lgOpened = true;
|
1149 | this.outer.get().focus();
|
1150 | this.outer.removeClass('lg-hide-items');
|
1151 |
|
1152 | this.$container.addClass('lg-show');
|
1153 | var itemsToBeInsertedToDom = this.getItemsToBeInsertedToDom(index, index);
|
1154 | this.currentItemsInDom = itemsToBeInsertedToDom;
|
1155 | var items = '';
|
1156 | itemsToBeInsertedToDom.forEach(function (item) {
|
1157 | items = items + ("<div id=\"" + item + "\" class=\"lg-item\"></div>");
|
1158 | });
|
1159 | this.$inner.append(items);
|
1160 | this.addHtml(index);
|
1161 | var transform = '';
|
1162 | this.mediaContainerPosition = this.getMediaContainerPosition();
|
1163 | var _a = this.mediaContainerPosition, top = _a.top, bottom = _a.bottom;
|
1164 | if (!this.settings.allowMediaOverlap) {
|
1165 | this.setMediaContainerPosition(top, bottom);
|
1166 | }
|
1167 | if (this.zoomFromOrigin && element) {
|
1168 | this.currentImageSize = utils.getSize(element, this.outer, top + bottom, this.galleryItems[index].__slideVideoInfo &&
|
1169 | this.settings.videoMaxSize);
|
1170 | transform = utils.getTransform(element, this.outer, top, bottom, this.currentImageSize);
|
1171 | }
|
1172 | if (!this.zoomFromOrigin || !transform) {
|
1173 | this.outer.addClass(this.settings.startClass);
|
1174 | this.getSlideItem(index).removeClass('lg-complete');
|
1175 | }
|
1176 | var timeout = this.settings.zoomFromOrigin
|
1177 | ? 100
|
1178 | : this.settings.backdropDuration;
|
1179 | setTimeout(function () {
|
1180 | _this.outer.addClass('lg-components-open');
|
1181 | }, timeout);
|
1182 | this.index = index;
|
1183 | this.LGel.trigger(lGEvents.beforeOpen);
|
1184 |
|
1185 | this.getSlideItem(index).addClass('lg-current');
|
1186 | this.lGalleryOn = false;
|
1187 |
|
1188 | this.prevScrollTop = $LG(window).scrollTop();
|
1189 | setTimeout(function () {
|
1190 |
|
1191 |
|
1192 | if (_this.zoomFromOrigin && transform) {
|
1193 | var currentSlide_1 = _this.getSlideItem(index);
|
1194 | currentSlide_1.css('transform', transform);
|
1195 | setTimeout(function () {
|
1196 | currentSlide_1
|
1197 | .addClass('lg-start-progress lg-start-end-progress')
|
1198 | .css('transition-duration', _this.settings.startAnimationDuration + 'ms');
|
1199 | _this.outer.addClass('lg-zoom-from-image');
|
1200 | });
|
1201 | setTimeout(function () {
|
1202 | currentSlide_1.css('transform', 'translate3d(0, 0, 0)');
|
1203 | }, 100);
|
1204 | }
|
1205 | setTimeout(function () {
|
1206 | _this.$backdrop.addClass('in');
|
1207 | _this.$container.addClass('lg-show-in');
|
1208 | }, 10);
|
1209 |
|
1210 | if (!_this.zoomFromOrigin || !transform) {
|
1211 | setTimeout(function () {
|
1212 | _this.outer.addClass('lg-visible');
|
1213 | }, _this.settings.backdropDuration);
|
1214 | }
|
1215 |
|
1216 | _this.slide(index, false, false, false);
|
1217 | _this.LGel.trigger(lGEvents.afterOpen);
|
1218 | });
|
1219 | if (document.body === this.settings.container) {
|
1220 | $LG('html').addClass('lg-on');
|
1221 | }
|
1222 | };
|
1223 | |
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 | LightGallery.prototype.getMediaContainerPosition = function () {
|
1230 | if (this.settings.allowMediaOverlap) {
|
1231 | return {
|
1232 | top: 0,
|
1233 | bottom: 0,
|
1234 | };
|
1235 | }
|
1236 | var top = this.$toolbar.get().clientHeight || 0;
|
1237 | var subHtml = this.outer.find('.lg-components .lg-sub-html').get();
|
1238 | var captionHeight = this.settings.defaultCaptionHeight ||
|
1239 | (subHtml && subHtml.clientHeight) ||
|
1240 | 0;
|
1241 | var thumbContainer = this.outer.find('.lg-thumb-outer').get();
|
1242 | var thumbHeight = thumbContainer ? thumbContainer.clientHeight : 0;
|
1243 | var bottom = thumbHeight + captionHeight;
|
1244 | return {
|
1245 | top: top,
|
1246 | bottom: bottom,
|
1247 | };
|
1248 | };
|
1249 | LightGallery.prototype.setMediaContainerPosition = function (top, bottom) {
|
1250 | if (top === void 0) { top = 0; }
|
1251 | if (bottom === void 0) { bottom = 0; }
|
1252 | this.$content.css('top', top + 'px').css('bottom', bottom + 'px');
|
1253 | };
|
1254 | LightGallery.prototype.hideBars = function () {
|
1255 | var _this = this;
|
1256 |
|
1257 | setTimeout(function () {
|
1258 | _this.outer.removeClass('lg-hide-items');
|
1259 | if (_this.settings.hideBarsDelay > 0) {
|
1260 | _this.outer.on('mousemove.lg click.lg touchstart.lg', function () {
|
1261 | _this.outer.removeClass('lg-hide-items');
|
1262 | clearTimeout(_this.hideBarTimeout);
|
1263 |
|
1264 | _this.hideBarTimeout = setTimeout(function () {
|
1265 | _this.outer.addClass('lg-hide-items');
|
1266 | }, _this.settings.hideBarsDelay);
|
1267 | });
|
1268 | _this.outer.trigger('mousemove.lg');
|
1269 | }
|
1270 | }, this.settings.showBarsAfter);
|
1271 | };
|
1272 | LightGallery.prototype.initPictureFill = function ($img) {
|
1273 | if (this.settings.supportLegacyBrowser) {
|
1274 | try {
|
1275 | picturefill({
|
1276 | elements: [$img.get()],
|
1277 | });
|
1278 | }
|
1279 | catch (e) {
|
1280 | console.warn('lightGallery :- If you want srcset or picture tag to be supported for older browser please include picturefil javascript library in your document.');
|
1281 | }
|
1282 | }
|
1283 | };
|
1284 | |
1285 |
|
1286 |
|
1287 |
|
1288 | LightGallery.prototype.counter = function () {
|
1289 | if (this.settings.counter) {
|
1290 | var counterHtml = "<div class=\"lg-counter\" role=\"status\" aria-live=\"polite\">\n <span id=\"" + this.getIdName('lg-counter-current') + "\" class=\"lg-counter-current\">" + (this.index + 1) + " </span> /\n <span id=\"" + this.getIdName('lg-counter-all') + "\" class=\"lg-counter-all\">" + this.galleryItems.length + " </span></div>";
|
1291 | this.outer.find(this.settings.appendCounterTo).append(counterHtml);
|
1292 | }
|
1293 | };
|
1294 | |
1295 |
|
1296 |
|
1297 |
|
1298 | LightGallery.prototype.addHtml = function (index) {
|
1299 | var subHtml;
|
1300 | var subHtmlUrl;
|
1301 | if (this.galleryItems[index].subHtmlUrl) {
|
1302 | subHtmlUrl = this.galleryItems[index].subHtmlUrl;
|
1303 | }
|
1304 | else {
|
1305 | subHtml = this.galleryItems[index].subHtml;
|
1306 | }
|
1307 | if (!subHtmlUrl) {
|
1308 | if (subHtml) {
|
1309 |
|
1310 |
|
1311 | var fL = subHtml.substring(0, 1);
|
1312 | if (fL === '.' || fL === '#') {
|
1313 | if (this.settings.subHtmlSelectorRelative &&
|
1314 | !this.settings.dynamic) {
|
1315 | subHtml = $LG(this.items)
|
1316 | .eq(index)
|
1317 | .find(subHtml)
|
1318 | .first()
|
1319 | .html();
|
1320 | }
|
1321 | else {
|
1322 | subHtml = $LG(subHtml).first().html();
|
1323 | }
|
1324 | }
|
1325 | }
|
1326 | else {
|
1327 | subHtml = '';
|
1328 | }
|
1329 | }
|
1330 | if (this.settings.appendSubHtmlTo !== '.lg-item') {
|
1331 | if (subHtmlUrl) {
|
1332 | this.outer.find('.lg-sub-html').load(subHtmlUrl);
|
1333 | }
|
1334 | else {
|
1335 | this.outer.find('.lg-sub-html').html(subHtml);
|
1336 | }
|
1337 | }
|
1338 | else {
|
1339 | var currentSlide = $LG(this.getSlideItemId(index));
|
1340 | if (subHtmlUrl) {
|
1341 | currentSlide.load(subHtmlUrl);
|
1342 | }
|
1343 | else {
|
1344 | currentSlide.append("<div class=\"lg-sub-html\">" + subHtml + "</div>");
|
1345 | }
|
1346 | }
|
1347 |
|
1348 | if (typeof subHtml !== 'undefined' && subHtml !== null) {
|
1349 | if (subHtml === '') {
|
1350 | this.outer
|
1351 | .find(this.settings.appendSubHtmlTo)
|
1352 | .addClass('lg-empty-html');
|
1353 | }
|
1354 | else {
|
1355 | this.outer
|
1356 | .find(this.settings.appendSubHtmlTo)
|
1357 | .removeClass('lg-empty-html');
|
1358 | }
|
1359 | }
|
1360 | this.LGel.trigger(lGEvents.afterAppendSubHtml, {
|
1361 | index: index,
|
1362 | });
|
1363 | };
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 | LightGallery.prototype.preload = function (index) {
|
1370 | for (var i = 1; i <= this.settings.preload; i++) {
|
1371 | if (i >= this.galleryItems.length - index) {
|
1372 | break;
|
1373 | }
|
1374 | this.loadContent(index + i, false);
|
1375 | }
|
1376 | for (var j = 1; j <= this.settings.preload; j++) {
|
1377 | if (index - j < 0) {
|
1378 | break;
|
1379 | }
|
1380 | this.loadContent(index - j, false);
|
1381 | }
|
1382 | };
|
1383 | LightGallery.prototype.getDummyImgStyles = function (imageSize) {
|
1384 | if (!imageSize)
|
1385 | return '';
|
1386 | return "width:" + imageSize.width + "px;\n margin-left: -" + imageSize.width / 2 + "px;\n margin-top: -" + imageSize.height / 2 + "px;\n height:" + imageSize.height + "px";
|
1387 | };
|
1388 | LightGallery.prototype.getVideoContStyle = function (imageSize) {
|
1389 | if (!imageSize)
|
1390 | return '';
|
1391 | return "width:" + imageSize.width + "px;\n height:" + imageSize.height + "px";
|
1392 | };
|
1393 | LightGallery.prototype.getDummyImageContent = function ($currentSlide, index, alt) {
|
1394 | var $currentItem;
|
1395 | if (!this.settings.dynamic) {
|
1396 | $currentItem = $LG(this.items).eq(index);
|
1397 | }
|
1398 | if ($currentItem) {
|
1399 | var _dummyImgSrc = void 0;
|
1400 | if (!this.settings.exThumbImage) {
|
1401 | _dummyImgSrc = $currentItem.find('img').first().attr('src');
|
1402 | }
|
1403 | else {
|
1404 | _dummyImgSrc = $currentItem.attr(this.settings.exThumbImage);
|
1405 | }
|
1406 | if (!_dummyImgSrc)
|
1407 | return '';
|
1408 | var imgStyle = this.getDummyImgStyles(this.currentImageSize);
|
1409 | var dummyImgContent = "<img " + alt + " style=\"" + imgStyle + "\" class=\"lg-dummy-img\" src=\"" + _dummyImgSrc + "\" />";
|
1410 | $currentSlide.addClass('lg-first-slide');
|
1411 | this.outer.addClass('lg-first-slide-loading');
|
1412 | return dummyImgContent;
|
1413 | }
|
1414 | return '';
|
1415 | };
|
1416 | LightGallery.prototype.setImgMarkup = function (src, $currentSlide, index) {
|
1417 | var currentGalleryItem = this.galleryItems[index];
|
1418 | var alt = currentGalleryItem.alt, srcset = currentGalleryItem.srcset, sizes = currentGalleryItem.sizes, sources = currentGalleryItem.sources;
|
1419 |
|
1420 |
|
1421 | var imgContent = '';
|
1422 | var altAttr = alt ? 'alt="' + alt + '"' : '';
|
1423 | if (!this.lGalleryOn && this.zoomFromOrigin && this.currentImageSize) {
|
1424 | imgContent = this.getDummyImageContent($currentSlide, index, altAttr);
|
1425 | }
|
1426 | else {
|
1427 | imgContent = utils.getImgMarkup(index, src, altAttr, srcset, sizes, sources);
|
1428 | }
|
1429 | var imgMarkup = "<picture class=\"lg-img-wrap\"> " + imgContent + "</picture>";
|
1430 | $currentSlide.prepend(imgMarkup);
|
1431 | };
|
1432 | LightGallery.prototype.onLgObjectLoad = function ($el, index, delay, speed, dummyImageLoaded) {
|
1433 | var _this = this;
|
1434 | if (dummyImageLoaded) {
|
1435 | this.LGel.trigger(lGEvents.slideItemLoad, {
|
1436 | index: index,
|
1437 | delay: delay || 0,
|
1438 | });
|
1439 | }
|
1440 | $el.find('.lg-object')
|
1441 | .first()
|
1442 | .on('load.lg', function () {
|
1443 | _this.handleLgObjectLoad($el, index, delay, speed, dummyImageLoaded);
|
1444 | });
|
1445 | setTimeout(function () {
|
1446 | $el.find('.lg-object')
|
1447 | .first()
|
1448 | .on('error.lg', function () {
|
1449 | $el.addClass('lg-complete lg-complete_');
|
1450 | $el.html('<span class="lg-error-msg">Oops... Failed to load content...</span>');
|
1451 | });
|
1452 | }, speed);
|
1453 | };
|
1454 | LightGallery.prototype.handleLgObjectLoad = function ($el, index, delay, speed, dummyImageLoaded) {
|
1455 | var _this = this;
|
1456 | setTimeout(function () {
|
1457 | $el.addClass('lg-complete lg-complete_');
|
1458 | if (!dummyImageLoaded) {
|
1459 | _this.LGel.trigger(lGEvents.slideItemLoad, {
|
1460 | index: index,
|
1461 | delay: delay || 0,
|
1462 | });
|
1463 | }
|
1464 | }, speed);
|
1465 | };
|
1466 | |
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 | LightGallery.prototype.isVideo = function (src, index) {
|
1475 | if (!src) {
|
1476 | if (this.galleryItems[index].video) {
|
1477 | return {
|
1478 | html5: true,
|
1479 | };
|
1480 | }
|
1481 | else {
|
1482 | console.error('lightGallery :- data-src is not provided on slide item ' +
|
1483 | (index + 1) +
|
1484 | '. Please make sure the selector property is properly configured. More info - https://www.lightgalleryjs.com/demos/html-markup/');
|
1485 | return;
|
1486 | }
|
1487 | }
|
1488 | var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com|be-nocookie\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);
|
1489 | var vimeo = src.match(/\/\/(?:www\.)?(?:player\.)?vimeo.com\/(?:video\/)?([0-9a-z\-_]+)/i);
|
1490 | var wistia = src.match(/https?:\/\/(.+)?(wistia\.com|wi\.st)\/(medias|embed)\/([0-9a-z\-_]+)(.*)/);
|
1491 | if (youtube) {
|
1492 | return {
|
1493 | youtube: youtube,
|
1494 | };
|
1495 | }
|
1496 | else if (vimeo) {
|
1497 | return {
|
1498 | vimeo: vimeo,
|
1499 | };
|
1500 | }
|
1501 | else if (wistia) {
|
1502 | return {
|
1503 | wistia: wistia,
|
1504 | };
|
1505 | }
|
1506 | };
|
1507 |
|
1508 | LightGallery.prototype.addSlideVideoInfo = function (items) {
|
1509 | var _this = this;
|
1510 | items.forEach(function (element, index) {
|
1511 | element.__slideVideoInfo = _this.isVideo(element.src, index);
|
1512 | });
|
1513 | };
|
1514 | |
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 | LightGallery.prototype.loadContent = function (index, rec) {
|
1521 | var _this = this;
|
1522 | var currentGalleryItem = this.galleryItems[index];
|
1523 | var $currentSlide = $LG(this.getSlideItemId(index));
|
1524 | var poster = currentGalleryItem.poster, srcset = currentGalleryItem.srcset, sizes = currentGalleryItem.sizes, sources = currentGalleryItem.sources;
|
1525 | var src = currentGalleryItem.src;
|
1526 | var video = currentGalleryItem.video;
|
1527 | var _html5Video = video && typeof video === 'string' ? JSON.parse(video) : video;
|
1528 | if (currentGalleryItem.responsive) {
|
1529 | var srcDyItms = currentGalleryItem.responsive.split(',');
|
1530 | src = utils.getResponsiveSrc(srcDyItms) || src;
|
1531 | }
|
1532 | var videoInfo = currentGalleryItem.__slideVideoInfo;
|
1533 | var lgVideoStyle = '';
|
1534 | var iframe = !!currentGalleryItem.iframe;
|
1535 | if (!$currentSlide.hasClass('lg-loaded')) {
|
1536 | if (videoInfo) {
|
1537 | var _a = this.mediaContainerPosition, top_2 = _a.top, bottom = _a.bottom;
|
1538 | var videoSize = utils.getSize(this.items[index], this.outer, top_2 + bottom, videoInfo && this.settings.videoMaxSize);
|
1539 | lgVideoStyle = this.getVideoContStyle(videoSize);
|
1540 | }
|
1541 | if (iframe) {
|
1542 | var markup = utils.getIframeMarkup(this.settings.iframeWidth, this.settings.iframeHeight, src, currentGalleryItem.iframeTitle);
|
1543 | $currentSlide.prepend(markup);
|
1544 | }
|
1545 | else if (poster) {
|
1546 | var dummyImg = '';
|
1547 | var isFirstSlide_1 = !this.lGalleryOn;
|
1548 | var hasStartAnimation = !this.lGalleryOn &&
|
1549 | this.zoomFromOrigin &&
|
1550 | this.currentImageSize;
|
1551 | if (hasStartAnimation) {
|
1552 | dummyImg = this.getDummyImageContent($currentSlide, index, '');
|
1553 | }
|
1554 | var markup = utils.getVideoPosterMarkup(poster, dummyImg || '', lgVideoStyle, videoInfo);
|
1555 | $currentSlide.prepend(markup);
|
1556 | var delay_1 = (hasStartAnimation
|
1557 | ? this.settings.startAnimationDuration
|
1558 | : this.settings.backdropDuration) + 100;
|
1559 | setTimeout(function () {
|
1560 | _this.LGel.trigger(lGEvents.hasVideo, {
|
1561 | index: index,
|
1562 | src: src,
|
1563 | html5Video: _html5Video,
|
1564 | hasPoster: true,
|
1565 | isFirstSlide: isFirstSlide_1,
|
1566 | });
|
1567 | }, delay_1);
|
1568 | }
|
1569 | else if (videoInfo) {
|
1570 | var markup = "<div class=\"lg-video-cont \" style=\"" + lgVideoStyle + "\"></div>";
|
1571 | $currentSlide.prepend(markup);
|
1572 | this.LGel.trigger(lGEvents.hasVideo, {
|
1573 | index: index,
|
1574 | src: src,
|
1575 | html5Video: _html5Video,
|
1576 | hasPoster: false,
|
1577 | });
|
1578 | }
|
1579 | else {
|
1580 | this.setImgMarkup(src, $currentSlide, index);
|
1581 | if (srcset || sources) {
|
1582 | var $img = $currentSlide.find('.lg-object');
|
1583 | this.initPictureFill($img);
|
1584 | }
|
1585 | }
|
1586 | this.LGel.trigger(lGEvents.afterAppendSlide, { index: index });
|
1587 | if (this.lGalleryOn &&
|
1588 | this.settings.appendSubHtmlTo === '.lg-item') {
|
1589 | this.addHtml(index);
|
1590 | }
|
1591 | }
|
1592 |
|
1593 | var _speed = 0;
|
1594 |
|
1595 | var delay = 0;
|
1596 | if (!this.lGalleryOn) {
|
1597 | if (this.zoomFromOrigin && this.currentImageSize) {
|
1598 | delay = this.settings.startAnimationDuration + 10;
|
1599 | }
|
1600 | else {
|
1601 | delay = this.settings.backdropDuration + 10;
|
1602 | }
|
1603 | }
|
1604 |
|
1605 |
|
1606 | if (delay && !$LG(document.body).hasClass('lg-from-hash')) {
|
1607 | _speed = delay;
|
1608 | }
|
1609 |
|
1610 | if (!this.lGalleryOn && this.zoomFromOrigin && this.currentImageSize) {
|
1611 | setTimeout(function () {
|
1612 | $currentSlide
|
1613 | .removeClass('lg-start-end-progress lg-start-progress')
|
1614 | .removeAttr('style');
|
1615 | }, this.settings.startAnimationDuration + 100);
|
1616 | if (!$currentSlide.hasClass('lg-loaded')) {
|
1617 | setTimeout(function () {
|
1618 | $currentSlide
|
1619 | .find('.lg-img-wrap')
|
1620 | .append(utils.getImgMarkup(index, src, '', srcset, sizes, currentGalleryItem.sources));
|
1621 | if (srcset || sources) {
|
1622 | var $img = $currentSlide.find('.lg-object');
|
1623 | _this.initPictureFill($img);
|
1624 | }
|
1625 | _this.onLgObjectLoad($currentSlide, index, delay, _speed, true);
|
1626 | var mediaObject = $currentSlide
|
1627 | .find('.lg-object')
|
1628 | .first();
|
1629 | if (utils.isImageLoaded(mediaObject.get())) {
|
1630 | _this.loadContentOnLoad(index, $currentSlide, _speed);
|
1631 | }
|
1632 | else {
|
1633 | mediaObject.on('load.lg error.lg', function () {
|
1634 | _this.loadContentOnLoad(index, $currentSlide, _speed);
|
1635 | });
|
1636 | }
|
1637 | }, this.settings.startAnimationDuration + 100);
|
1638 | }
|
1639 | }
|
1640 |
|
1641 | $currentSlide.addClass('lg-loaded');
|
1642 | this.onLgObjectLoad($currentSlide, index, delay, _speed, false);
|
1643 |
|
1644 | if (videoInfo && videoInfo.html5 && !poster) {
|
1645 | $currentSlide.addClass('lg-complete lg-complete_');
|
1646 | }
|
1647 |
|
1648 | if ((!this.zoomFromOrigin || !this.currentImageSize) &&
|
1649 | $currentSlide.hasClass('lg-complete_') &&
|
1650 | !this.lGalleryOn) {
|
1651 | setTimeout(function () {
|
1652 | $currentSlide.addClass('lg-complete');
|
1653 | }, this.settings.backdropDuration);
|
1654 | }
|
1655 |
|
1656 |
|
1657 | this.lGalleryOn = true;
|
1658 | if (rec === true) {
|
1659 | if (!$currentSlide.hasClass('lg-complete_')) {
|
1660 | $currentSlide
|
1661 | .find('.lg-object')
|
1662 | .first()
|
1663 | .on('load.lg error.lg', function () {
|
1664 | _this.preload(index);
|
1665 | });
|
1666 | }
|
1667 | else {
|
1668 | this.preload(index);
|
1669 | }
|
1670 | }
|
1671 | };
|
1672 | LightGallery.prototype.loadContentOnLoad = function (index, $currentSlide, speed) {
|
1673 | var _this = this;
|
1674 | setTimeout(function () {
|
1675 | $currentSlide.find('.lg-dummy-img').remove();
|
1676 | $currentSlide.removeClass('lg-first-slide');
|
1677 | _this.outer.removeClass('lg-first-slide-loading');
|
1678 | _this.isDummyImageRemoved = true;
|
1679 | _this.preload(index);
|
1680 | }, speed + 300);
|
1681 | };
|
1682 | LightGallery.prototype.getItemsToBeInsertedToDom = function (index, prevIndex, numberOfItems) {
|
1683 | var _this = this;
|
1684 | if (numberOfItems === void 0) { numberOfItems = 0; }
|
1685 | var itemsToBeInsertedToDom = [];
|
1686 |
|
1687 | var possibleNumberOfItems = Math.max(numberOfItems, 3);
|
1688 | possibleNumberOfItems = Math.min(possibleNumberOfItems, this.galleryItems.length);
|
1689 | var prevIndexItem = "lg-item-" + this.lgId + "-" + prevIndex;
|
1690 | if (this.galleryItems.length <= 3) {
|
1691 | this.galleryItems.forEach(function (_element, index) {
|
1692 | itemsToBeInsertedToDom.push("lg-item-" + _this.lgId + "-" + index);
|
1693 | });
|
1694 | return itemsToBeInsertedToDom;
|
1695 | }
|
1696 | if (index < (this.galleryItems.length - 1) / 2) {
|
1697 | for (var idx = index; idx > index - possibleNumberOfItems / 2 && idx >= 0; idx--) {
|
1698 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + idx);
|
1699 | }
|
1700 | var numberOfExistingItems = itemsToBeInsertedToDom.length;
|
1701 | for (var idx = 0; idx < possibleNumberOfItems - numberOfExistingItems; idx++) {
|
1702 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + (index + idx + 1));
|
1703 | }
|
1704 | }
|
1705 | else {
|
1706 | for (var idx = index; idx <= this.galleryItems.length - 1 &&
|
1707 | idx < index + possibleNumberOfItems / 2; idx++) {
|
1708 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + idx);
|
1709 | }
|
1710 | var numberOfExistingItems = itemsToBeInsertedToDom.length;
|
1711 | for (var idx = 0; idx < possibleNumberOfItems - numberOfExistingItems; idx++) {
|
1712 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + (index - idx - 1));
|
1713 | }
|
1714 | }
|
1715 | if (this.settings.loop) {
|
1716 | if (index === this.galleryItems.length - 1) {
|
1717 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + 0);
|
1718 | }
|
1719 | else if (index === 0) {
|
1720 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + (this.galleryItems.length - 1));
|
1721 | }
|
1722 | }
|
1723 | if (itemsToBeInsertedToDom.indexOf(prevIndexItem) === -1) {
|
1724 | itemsToBeInsertedToDom.push("lg-item-" + this.lgId + "-" + prevIndex);
|
1725 | }
|
1726 | return itemsToBeInsertedToDom;
|
1727 | };
|
1728 | LightGallery.prototype.organizeSlideItems = function (index, prevIndex) {
|
1729 | var _this = this;
|
1730 | var itemsToBeInsertedToDom = this.getItemsToBeInsertedToDom(index, prevIndex, this.settings.numberOfSlideItemsInDom);
|
1731 | itemsToBeInsertedToDom.forEach(function (item) {
|
1732 | if (_this.currentItemsInDom.indexOf(item) === -1) {
|
1733 | _this.$inner.append("<div id=\"" + item + "\" class=\"lg-item\"></div>");
|
1734 | }
|
1735 | });
|
1736 | this.currentItemsInDom.forEach(function (item) {
|
1737 | if (itemsToBeInsertedToDom.indexOf(item) === -1) {
|
1738 | $LG("#" + item).remove();
|
1739 | }
|
1740 | });
|
1741 | return itemsToBeInsertedToDom;
|
1742 | };
|
1743 | |
1744 |
|
1745 |
|
1746 | LightGallery.prototype.getPreviousSlideIndex = function () {
|
1747 | var prevIndex = 0;
|
1748 | try {
|
1749 | var currentItemId = this.outer
|
1750 | .find('.lg-current')
|
1751 | .first()
|
1752 | .attr('id');
|
1753 | prevIndex = parseInt(currentItemId.split('-')[3]) || 0;
|
1754 | }
|
1755 | catch (error) {
|
1756 | prevIndex = 0;
|
1757 | }
|
1758 | return prevIndex;
|
1759 | };
|
1760 | LightGallery.prototype.setDownloadValue = function (index) {
|
1761 | if (this.settings.download) {
|
1762 | var currentGalleryItem = this.galleryItems[index];
|
1763 | var hideDownloadBtn = currentGalleryItem.downloadUrl === false ||
|
1764 | currentGalleryItem.downloadUrl === 'false';
|
1765 | if (hideDownloadBtn) {
|
1766 | this.outer.addClass('lg-hide-download');
|
1767 | }
|
1768 | else {
|
1769 | var $download = this.getElementById('lg-download');
|
1770 | this.outer.removeClass('lg-hide-download');
|
1771 | $download.attr('href', currentGalleryItem.downloadUrl ||
|
1772 | currentGalleryItem.src);
|
1773 | if (currentGalleryItem.download) {
|
1774 | $download.attr('download', currentGalleryItem.download);
|
1775 | }
|
1776 | }
|
1777 | }
|
1778 | };
|
1779 | LightGallery.prototype.makeSlideAnimation = function (direction, currentSlideItem, previousSlideItem) {
|
1780 | var _this = this;
|
1781 | if (this.lGalleryOn) {
|
1782 | previousSlideItem.addClass('lg-slide-progress');
|
1783 | }
|
1784 | setTimeout(function () {
|
1785 |
|
1786 | _this.outer.addClass('lg-no-trans');
|
1787 | _this.outer
|
1788 | .find('.lg-item')
|
1789 | .removeClass('lg-prev-slide lg-next-slide');
|
1790 | if (direction === 'prev') {
|
1791 |
|
1792 | currentSlideItem.addClass('lg-prev-slide');
|
1793 | previousSlideItem.addClass('lg-next-slide');
|
1794 | }
|
1795 | else {
|
1796 |
|
1797 | currentSlideItem.addClass('lg-next-slide');
|
1798 | previousSlideItem.addClass('lg-prev-slide');
|
1799 | }
|
1800 |
|
1801 | setTimeout(function () {
|
1802 | _this.outer.find('.lg-item').removeClass('lg-current');
|
1803 | currentSlideItem.addClass('lg-current');
|
1804 |
|
1805 | _this.outer.removeClass('lg-no-trans');
|
1806 | }, 50);
|
1807 | }, this.lGalleryOn ? this.settings.slideDelay : 0);
|
1808 | };
|
1809 | |
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 | LightGallery.prototype.slide = function (index, fromTouch, fromThumb, direction) {
|
1823 | var _this = this;
|
1824 | var prevIndex = this.getPreviousSlideIndex();
|
1825 | this.currentItemsInDom = this.organizeSlideItems(index, prevIndex);
|
1826 |
|
1827 | if (this.lGalleryOn && prevIndex === index) {
|
1828 | return;
|
1829 | }
|
1830 | var numberOfGalleryItems = this.galleryItems.length;
|
1831 | if (!this.lgBusy) {
|
1832 | if (this.settings.counter) {
|
1833 | this.updateCurrentCounter(index);
|
1834 | }
|
1835 | var currentSlideItem = this.getSlideItem(index);
|
1836 | var previousSlideItem_1 = this.getSlideItem(prevIndex);
|
1837 | var currentGalleryItem = this.galleryItems[index];
|
1838 | var videoInfo = currentGalleryItem.__slideVideoInfo;
|
1839 | this.outer.attr('data-lg-slide-type', this.getSlideType(currentGalleryItem));
|
1840 | this.setDownloadValue(index);
|
1841 | if (videoInfo) {
|
1842 | var _a = this.mediaContainerPosition, top_3 = _a.top, bottom = _a.bottom;
|
1843 | var videoSize = utils.getSize(this.items[index], this.outer, top_3 + bottom, videoInfo && this.settings.videoMaxSize);
|
1844 | this.resizeVideoSlide(index, videoSize);
|
1845 | }
|
1846 | this.LGel.trigger(lGEvents.beforeSlide, {
|
1847 | prevIndex: prevIndex,
|
1848 | index: index,
|
1849 | fromTouch: !!fromTouch,
|
1850 | fromThumb: !!fromThumb,
|
1851 | });
|
1852 | this.lgBusy = true;
|
1853 | clearTimeout(this.hideBarTimeout);
|
1854 | this.arrowDisable(index);
|
1855 | if (!direction) {
|
1856 | if (index < prevIndex) {
|
1857 | direction = 'prev';
|
1858 | }
|
1859 | else if (index > prevIndex) {
|
1860 | direction = 'next';
|
1861 | }
|
1862 | }
|
1863 | if (!fromTouch) {
|
1864 | this.makeSlideAnimation(direction, currentSlideItem, previousSlideItem_1);
|
1865 | }
|
1866 | else {
|
1867 | this.outer
|
1868 | .find('.lg-item')
|
1869 | .removeClass('lg-prev-slide lg-current lg-next-slide');
|
1870 | var touchPrev = void 0;
|
1871 | var touchNext = void 0;
|
1872 | if (numberOfGalleryItems > 2) {
|
1873 | touchPrev = index - 1;
|
1874 | touchNext = index + 1;
|
1875 | if (index === 0 && prevIndex === numberOfGalleryItems - 1) {
|
1876 |
|
1877 | touchNext = 0;
|
1878 | touchPrev = numberOfGalleryItems - 1;
|
1879 | }
|
1880 | else if (index === numberOfGalleryItems - 1 &&
|
1881 | prevIndex === 0) {
|
1882 |
|
1883 | touchNext = 0;
|
1884 | touchPrev = numberOfGalleryItems - 1;
|
1885 | }
|
1886 | }
|
1887 | else {
|
1888 | touchPrev = 0;
|
1889 | touchNext = 1;
|
1890 | }
|
1891 | if (direction === 'prev') {
|
1892 | this.getSlideItem(touchNext).addClass('lg-next-slide');
|
1893 | }
|
1894 | else {
|
1895 | this.getSlideItem(touchPrev).addClass('lg-prev-slide');
|
1896 | }
|
1897 | currentSlideItem.addClass('lg-current');
|
1898 | }
|
1899 |
|
1900 | if (!this.lGalleryOn) {
|
1901 | this.loadContent(index, true);
|
1902 | }
|
1903 | setTimeout(function () {
|
1904 | if (_this.lGalleryOn) {
|
1905 | _this.loadContent(index, true);
|
1906 | }
|
1907 |
|
1908 | if (_this.settings.appendSubHtmlTo !== '.lg-item') {
|
1909 | _this.addHtml(index);
|
1910 | }
|
1911 | }, (this.lGalleryOn ? this.settings.speed + 50 : 50) + (fromTouch ? 0 : this.settings.slideDelay));
|
1912 | setTimeout(function () {
|
1913 | _this.lgBusy = false;
|
1914 | previousSlideItem_1.removeClass('lg-slide-progress');
|
1915 | _this.LGel.trigger(lGEvents.afterSlide, {
|
1916 | prevIndex: prevIndex,
|
1917 | index: index,
|
1918 | fromTouch: fromTouch,
|
1919 | fromThumb: fromThumb,
|
1920 | });
|
1921 | }, (this.lGalleryOn ? this.settings.speed + 100 : 100) + (fromTouch ? 0 : this.settings.slideDelay));
|
1922 | }
|
1923 | this.index = index;
|
1924 | };
|
1925 | LightGallery.prototype.updateCurrentCounter = function (index) {
|
1926 | this.getElementById('lg-counter-current').html(index + 1 + '');
|
1927 | };
|
1928 | LightGallery.prototype.updateCounterTotal = function () {
|
1929 | this.getElementById('lg-counter-all').html(this.galleryItems.length + '');
|
1930 | };
|
1931 | LightGallery.prototype.getSlideType = function (item) {
|
1932 | if (item.__slideVideoInfo) {
|
1933 | return 'video';
|
1934 | }
|
1935 | else if (item.iframe) {
|
1936 | return 'iframe';
|
1937 | }
|
1938 | else {
|
1939 | return 'image';
|
1940 | }
|
1941 | };
|
1942 | LightGallery.prototype.touchMove = function (startCoords, endCoords, e) {
|
1943 | var distanceX = endCoords.pageX - startCoords.pageX;
|
1944 | var distanceY = endCoords.pageY - startCoords.pageY;
|
1945 | var allowSwipe = false;
|
1946 | if (this.swipeDirection) {
|
1947 | allowSwipe = true;
|
1948 | }
|
1949 | else {
|
1950 | if (Math.abs(distanceX) > 15) {
|
1951 | this.swipeDirection = 'horizontal';
|
1952 | allowSwipe = true;
|
1953 | }
|
1954 | else if (Math.abs(distanceY) > 15) {
|
1955 | this.swipeDirection = 'vertical';
|
1956 | allowSwipe = true;
|
1957 | }
|
1958 | }
|
1959 | if (!allowSwipe) {
|
1960 | return;
|
1961 | }
|
1962 | var $currentSlide = this.getSlideItem(this.index);
|
1963 | if (this.swipeDirection === 'horizontal') {
|
1964 | e === null || e === void 0 ? void 0 : e.preventDefault();
|
1965 |
|
1966 | this.outer.addClass('lg-dragging');
|
1967 |
|
1968 | this.setTranslate($currentSlide, distanceX, 0);
|
1969 |
|
1970 | var width = $currentSlide.get().offsetWidth;
|
1971 | var slideWidthAmount = (width * 15) / 100;
|
1972 | var gutter = slideWidthAmount - Math.abs((distanceX * 10) / 100);
|
1973 | this.setTranslate(this.outer.find('.lg-prev-slide').first(), -width + distanceX - gutter, 0);
|
1974 | this.setTranslate(this.outer.find('.lg-next-slide').first(), width + distanceX + gutter, 0);
|
1975 | }
|
1976 | else if (this.swipeDirection === 'vertical') {
|
1977 | if (this.settings.swipeToClose) {
|
1978 | e === null || e === void 0 ? void 0 : e.preventDefault();
|
1979 | this.$container.addClass('lg-dragging-vertical');
|
1980 | var opacity = 1 - Math.abs(distanceY) / window.innerHeight;
|
1981 | this.$backdrop.css('opacity', opacity);
|
1982 | var scale = 1 - Math.abs(distanceY) / (window.innerWidth * 2);
|
1983 | this.setTranslate($currentSlide, 0, distanceY, scale, scale);
|
1984 | if (Math.abs(distanceY) > 100) {
|
1985 | this.outer
|
1986 | .addClass('lg-hide-items')
|
1987 | .removeClass('lg-components-open');
|
1988 | }
|
1989 | }
|
1990 | }
|
1991 | };
|
1992 | LightGallery.prototype.touchEnd = function (endCoords, startCoords, event) {
|
1993 | var _this = this;
|
1994 | var distance;
|
1995 |
|
1996 | if (this.settings.mode !== 'lg-slide') {
|
1997 | this.outer.addClass('lg-slide');
|
1998 | }
|
1999 |
|
2000 | setTimeout(function () {
|
2001 | _this.$container.removeClass('lg-dragging-vertical');
|
2002 | _this.outer
|
2003 | .removeClass('lg-dragging lg-hide-items')
|
2004 | .addClass('lg-components-open');
|
2005 | var triggerClick = true;
|
2006 | if (_this.swipeDirection === 'horizontal') {
|
2007 | distance = endCoords.pageX - startCoords.pageX;
|
2008 | var distanceAbs = Math.abs(endCoords.pageX - startCoords.pageX);
|
2009 | if (distance < 0 &&
|
2010 | distanceAbs > _this.settings.swipeThreshold) {
|
2011 | _this.goToNextSlide(true);
|
2012 | triggerClick = false;
|
2013 | }
|
2014 | else if (distance > 0 &&
|
2015 | distanceAbs > _this.settings.swipeThreshold) {
|
2016 | _this.goToPrevSlide(true);
|
2017 | triggerClick = false;
|
2018 | }
|
2019 | }
|
2020 | else if (_this.swipeDirection === 'vertical') {
|
2021 | distance = Math.abs(endCoords.pageY - startCoords.pageY);
|
2022 | if (_this.settings.closable &&
|
2023 | _this.settings.swipeToClose &&
|
2024 | distance > 100) {
|
2025 | _this.closeGallery();
|
2026 | return;
|
2027 | }
|
2028 | else {
|
2029 | _this.$backdrop.css('opacity', 1);
|
2030 | }
|
2031 | }
|
2032 | _this.outer.find('.lg-item').removeAttr('style');
|
2033 | if (triggerClick &&
|
2034 | Math.abs(endCoords.pageX - startCoords.pageX) < 5) {
|
2035 |
|
2036 | var target = $LG(event.target);
|
2037 | if (_this.isPosterElement(target)) {
|
2038 | _this.LGel.trigger(lGEvents.posterClick);
|
2039 | }
|
2040 | }
|
2041 | _this.swipeDirection = undefined;
|
2042 | });
|
2043 |
|
2044 | setTimeout(function () {
|
2045 | if (!_this.outer.hasClass('lg-dragging') &&
|
2046 | _this.settings.mode !== 'lg-slide') {
|
2047 | _this.outer.removeClass('lg-slide');
|
2048 | }
|
2049 | }, this.settings.speed + 100);
|
2050 | };
|
2051 | LightGallery.prototype.enableSwipe = function () {
|
2052 | var _this = this;
|
2053 | var startCoords = {};
|
2054 | var endCoords = {};
|
2055 | var isMoved = false;
|
2056 | var isSwiping = false;
|
2057 | if (this.settings.enableSwipe) {
|
2058 | this.$inner.on('touchstart.lg', function (e) {
|
2059 | _this.dragOrSwipeEnabled = true;
|
2060 | var $item = _this.getSlideItem(_this.index);
|
2061 | if (($LG(e.target).hasClass('lg-item') ||
|
2062 | $item.get().contains(e.target)) &&
|
2063 | !_this.outer.hasClass('lg-zoomed') &&
|
2064 | !_this.lgBusy &&
|
2065 | e.targetTouches.length === 1) {
|
2066 | isSwiping = true;
|
2067 | _this.touchAction = 'swipe';
|
2068 | _this.manageSwipeClass();
|
2069 | startCoords = {
|
2070 | pageX: e.targetTouches[0].pageX,
|
2071 | pageY: e.targetTouches[0].pageY,
|
2072 | };
|
2073 | }
|
2074 | });
|
2075 | this.$inner.on('touchmove.lg', function (e) {
|
2076 | if (isSwiping &&
|
2077 | _this.touchAction === 'swipe' &&
|
2078 | e.targetTouches.length === 1) {
|
2079 | endCoords = {
|
2080 | pageX: e.targetTouches[0].pageX,
|
2081 | pageY: e.targetTouches[0].pageY,
|
2082 | };
|
2083 | _this.touchMove(startCoords, endCoords, e);
|
2084 | isMoved = true;
|
2085 | }
|
2086 | });
|
2087 | this.$inner.on('touchend.lg', function (event) {
|
2088 | if (_this.touchAction === 'swipe') {
|
2089 | if (isMoved) {
|
2090 | isMoved = false;
|
2091 | _this.touchEnd(endCoords, startCoords, event);
|
2092 | }
|
2093 | else if (isSwiping) {
|
2094 | var target = $LG(event.target);
|
2095 | if (_this.isPosterElement(target)) {
|
2096 | _this.LGel.trigger(lGEvents.posterClick);
|
2097 | }
|
2098 | }
|
2099 | _this.touchAction = undefined;
|
2100 | isSwiping = false;
|
2101 | }
|
2102 | });
|
2103 | }
|
2104 | };
|
2105 | LightGallery.prototype.enableDrag = function () {
|
2106 | var _this = this;
|
2107 | var startCoords = {};
|
2108 | var endCoords = {};
|
2109 | var isDraging = false;
|
2110 | var isMoved = false;
|
2111 | if (this.settings.enableDrag) {
|
2112 | this.outer.on('mousedown.lg', function (e) {
|
2113 | _this.dragOrSwipeEnabled = true;
|
2114 | var $item = _this.getSlideItem(_this.index);
|
2115 | if ($LG(e.target).hasClass('lg-item') ||
|
2116 | $item.get().contains(e.target)) {
|
2117 | if (!_this.outer.hasClass('lg-zoomed') && !_this.lgBusy) {
|
2118 | e.preventDefault();
|
2119 | if (!_this.lgBusy) {
|
2120 | _this.manageSwipeClass();
|
2121 | startCoords = {
|
2122 | pageX: e.pageX,
|
2123 | pageY: e.pageY,
|
2124 | };
|
2125 | isDraging = true;
|
2126 |
|
2127 | _this.outer.get().scrollLeft += 1;
|
2128 | _this.outer.get().scrollLeft -= 1;
|
2129 |
|
2130 | _this.outer
|
2131 | .removeClass('lg-grab')
|
2132 | .addClass('lg-grabbing');
|
2133 | _this.LGel.trigger(lGEvents.dragStart);
|
2134 | }
|
2135 | }
|
2136 | }
|
2137 | });
|
2138 | $LG(window).on("mousemove.lg.global" + this.lgId, function (e) {
|
2139 | if (isDraging && _this.lgOpened) {
|
2140 | isMoved = true;
|
2141 | endCoords = {
|
2142 | pageX: e.pageX,
|
2143 | pageY: e.pageY,
|
2144 | };
|
2145 | _this.touchMove(startCoords, endCoords);
|
2146 | _this.LGel.trigger(lGEvents.dragMove);
|
2147 | }
|
2148 | });
|
2149 | $LG(window).on("mouseup.lg.global" + this.lgId, function (event) {
|
2150 | if (!_this.lgOpened) {
|
2151 | return;
|
2152 | }
|
2153 | var target = $LG(event.target);
|
2154 | if (isMoved) {
|
2155 | isMoved = false;
|
2156 | _this.touchEnd(endCoords, startCoords, event);
|
2157 | _this.LGel.trigger(lGEvents.dragEnd);
|
2158 | }
|
2159 | else if (_this.isPosterElement(target)) {
|
2160 | _this.LGel.trigger(lGEvents.posterClick);
|
2161 | }
|
2162 |
|
2163 | if (isDraging) {
|
2164 | isDraging = false;
|
2165 | _this.outer.removeClass('lg-grabbing').addClass('lg-grab');
|
2166 | }
|
2167 | });
|
2168 | }
|
2169 | };
|
2170 | LightGallery.prototype.triggerPosterClick = function () {
|
2171 | var _this = this;
|
2172 | this.$inner.on('click.lg', function (event) {
|
2173 | if (!_this.dragOrSwipeEnabled &&
|
2174 | _this.isPosterElement($LG(event.target))) {
|
2175 | _this.LGel.trigger(lGEvents.posterClick);
|
2176 | }
|
2177 | });
|
2178 | };
|
2179 | LightGallery.prototype.manageSwipeClass = function () {
|
2180 | var _touchNext = this.index + 1;
|
2181 | var _touchPrev = this.index - 1;
|
2182 | if (this.settings.loop && this.galleryItems.length > 2) {
|
2183 | if (this.index === 0) {
|
2184 | _touchPrev = this.galleryItems.length - 1;
|
2185 | }
|
2186 | else if (this.index === this.galleryItems.length - 1) {
|
2187 | _touchNext = 0;
|
2188 | }
|
2189 | }
|
2190 | this.outer.find('.lg-item').removeClass('lg-next-slide lg-prev-slide');
|
2191 | if (_touchPrev > -1) {
|
2192 | this.getSlideItem(_touchPrev).addClass('lg-prev-slide');
|
2193 | }
|
2194 | this.getSlideItem(_touchNext).addClass('lg-next-slide');
|
2195 | };
|
2196 | |
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 | LightGallery.prototype.goToNextSlide = function (fromTouch) {
|
2206 | var _this = this;
|
2207 | var _loop = this.settings.loop;
|
2208 | if (fromTouch && this.galleryItems.length < 3) {
|
2209 | _loop = false;
|
2210 | }
|
2211 | if (!this.lgBusy) {
|
2212 | if (this.index + 1 < this.galleryItems.length) {
|
2213 | this.index++;
|
2214 | this.LGel.trigger(lGEvents.beforeNextSlide, {
|
2215 | index: this.index,
|
2216 | });
|
2217 | this.slide(this.index, !!fromTouch, false, 'next');
|
2218 | }
|
2219 | else {
|
2220 | if (_loop) {
|
2221 | this.index = 0;
|
2222 | this.LGel.trigger(lGEvents.beforeNextSlide, {
|
2223 | index: this.index,
|
2224 | });
|
2225 | this.slide(this.index, !!fromTouch, false, 'next');
|
2226 | }
|
2227 | else if (this.settings.slideEndAnimation && !fromTouch) {
|
2228 | this.outer.addClass('lg-right-end');
|
2229 | setTimeout(function () {
|
2230 | _this.outer.removeClass('lg-right-end');
|
2231 | }, 400);
|
2232 | }
|
2233 | }
|
2234 | }
|
2235 | };
|
2236 | |
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 | LightGallery.prototype.goToPrevSlide = function (fromTouch) {
|
2247 | var _this = this;
|
2248 | var _loop = this.settings.loop;
|
2249 | if (fromTouch && this.galleryItems.length < 3) {
|
2250 | _loop = false;
|
2251 | }
|
2252 | if (!this.lgBusy) {
|
2253 | if (this.index > 0) {
|
2254 | this.index--;
|
2255 | this.LGel.trigger(lGEvents.beforePrevSlide, {
|
2256 | index: this.index,
|
2257 | fromTouch: fromTouch,
|
2258 | });
|
2259 | this.slide(this.index, !!fromTouch, false, 'prev');
|
2260 | }
|
2261 | else {
|
2262 | if (_loop) {
|
2263 | this.index = this.galleryItems.length - 1;
|
2264 | this.LGel.trigger(lGEvents.beforePrevSlide, {
|
2265 | index: this.index,
|
2266 | fromTouch: fromTouch,
|
2267 | });
|
2268 | this.slide(this.index, !!fromTouch, false, 'prev');
|
2269 | }
|
2270 | else if (this.settings.slideEndAnimation && !fromTouch) {
|
2271 | this.outer.addClass('lg-left-end');
|
2272 | setTimeout(function () {
|
2273 | _this.outer.removeClass('lg-left-end');
|
2274 | }, 400);
|
2275 | }
|
2276 | }
|
2277 | }
|
2278 | };
|
2279 | LightGallery.prototype.keyPress = function () {
|
2280 | var _this = this;
|
2281 | $LG(window).on("keydown.lg.global" + this.lgId, function (e) {
|
2282 | if (_this.lgOpened &&
|
2283 | _this.settings.escKey === true &&
|
2284 | e.keyCode === 27) {
|
2285 | e.preventDefault();
|
2286 | if (_this.settings.allowMediaOverlap &&
|
2287 | _this.outer.hasClass('lg-can-toggle') &&
|
2288 | _this.outer.hasClass('lg-components-open')) {
|
2289 | _this.outer.removeClass('lg-components-open');
|
2290 | }
|
2291 | else {
|
2292 | _this.closeGallery();
|
2293 | }
|
2294 | }
|
2295 | if (_this.lgOpened && _this.galleryItems.length > 1) {
|
2296 | if (e.keyCode === 37) {
|
2297 | e.preventDefault();
|
2298 | _this.goToPrevSlide();
|
2299 | }
|
2300 | if (e.keyCode === 39) {
|
2301 | e.preventDefault();
|
2302 | _this.goToNextSlide();
|
2303 | }
|
2304 | }
|
2305 | });
|
2306 | };
|
2307 | LightGallery.prototype.arrow = function () {
|
2308 | var _this = this;
|
2309 | this.getElementById('lg-prev').on('click.lg', function () {
|
2310 | _this.goToPrevSlide();
|
2311 | });
|
2312 | this.getElementById('lg-next').on('click.lg', function () {
|
2313 | _this.goToNextSlide();
|
2314 | });
|
2315 | };
|
2316 | LightGallery.prototype.arrowDisable = function (index) {
|
2317 |
|
2318 | if (!this.settings.loop && this.settings.hideControlOnEnd) {
|
2319 | var $prev = this.getElementById('lg-prev');
|
2320 | var $next = this.getElementById('lg-next');
|
2321 | if (index + 1 === this.galleryItems.length) {
|
2322 | $next.attr('disabled', 'disabled').addClass('disabled');
|
2323 | }
|
2324 | else {
|
2325 | $next.removeAttr('disabled').removeClass('disabled');
|
2326 | }
|
2327 | if (index === 0) {
|
2328 | $prev.attr('disabled', 'disabled').addClass('disabled');
|
2329 | }
|
2330 | else {
|
2331 | $prev.removeAttr('disabled').removeClass('disabled');
|
2332 | }
|
2333 | }
|
2334 | };
|
2335 | LightGallery.prototype.setTranslate = function ($el, xValue, yValue, scaleX, scaleY) {
|
2336 | if (scaleX === void 0) { scaleX = 1; }
|
2337 | if (scaleY === void 0) { scaleY = 1; }
|
2338 | $el.css('transform', 'translate3d(' +
|
2339 | xValue +
|
2340 | 'px, ' +
|
2341 | yValue +
|
2342 | 'px, 0px) scale3d(' +
|
2343 | scaleX +
|
2344 | ', ' +
|
2345 | scaleY +
|
2346 | ', 1)');
|
2347 | };
|
2348 | LightGallery.prototype.mousewheel = function () {
|
2349 | var _this = this;
|
2350 | this.outer.on('mousewheel.lg', function (e) {
|
2351 | if (!e.deltaY || _this.galleryItems.length < 2) {
|
2352 | return;
|
2353 | }
|
2354 | if (e.deltaY > 0) {
|
2355 | _this.goToPrevSlide();
|
2356 | }
|
2357 | else {
|
2358 | _this.goToNextSlide();
|
2359 | }
|
2360 | e.preventDefault();
|
2361 | });
|
2362 | };
|
2363 | LightGallery.prototype.isSlideElement = function (target) {
|
2364 | return (target.hasClass('lg-outer') ||
|
2365 | target.hasClass('lg-item') ||
|
2366 | target.hasClass('lg-img-wrap'));
|
2367 | };
|
2368 | LightGallery.prototype.isPosterElement = function (target) {
|
2369 | var playButton = this.getSlideItem(this.index)
|
2370 | .find('.lg-video-play-button')
|
2371 | .get();
|
2372 | return (target.hasClass('lg-video-poster') ||
|
2373 | target.hasClass('lg-video-play-button') ||
|
2374 | (playButton && playButton.contains(target.get())));
|
2375 | };
|
2376 | |
2377 |
|
2378 |
|
2379 |
|
2380 | LightGallery.prototype.toggleMaximize = function () {
|
2381 | var _this = this;
|
2382 | this.getElementById('lg-maximize').on('click.lg', function () {
|
2383 | _this.$container.toggleClass('lg-inline');
|
2384 | _this.refreshOnResize();
|
2385 | });
|
2386 | };
|
2387 | LightGallery.prototype.invalidateItems = function () {
|
2388 | for (var index = 0; index < this.items.length; index++) {
|
2389 | var element = this.items[index];
|
2390 | var $element = $LG(element);
|
2391 | $element.off("click.lgcustom-item-" + $element.attr('data-lg-id'));
|
2392 | }
|
2393 | };
|
2394 | LightGallery.prototype.manageCloseGallery = function () {
|
2395 | var _this = this;
|
2396 | if (!this.settings.closable)
|
2397 | return;
|
2398 | var mousedown = false;
|
2399 | this.getElementById('lg-close').on('click.lg', function () {
|
2400 | _this.closeGallery();
|
2401 | });
|
2402 | if (this.settings.closeOnTap) {
|
2403 |
|
2404 |
|
2405 | this.outer.on('mousedown.lg', function (e) {
|
2406 | var target = $LG(e.target);
|
2407 | if (_this.isSlideElement(target)) {
|
2408 | mousedown = true;
|
2409 | }
|
2410 | else {
|
2411 | mousedown = false;
|
2412 | }
|
2413 | });
|
2414 | this.outer.on('mousemove.lg', function () {
|
2415 | mousedown = false;
|
2416 | });
|
2417 | this.outer.on('mouseup.lg', function (e) {
|
2418 | var target = $LG(e.target);
|
2419 | if (_this.isSlideElement(target) && mousedown) {
|
2420 | if (!_this.outer.hasClass('lg-dragging')) {
|
2421 | _this.closeGallery();
|
2422 | }
|
2423 | }
|
2424 | });
|
2425 | }
|
2426 | };
|
2427 | |
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 | LightGallery.prototype.closeGallery = function (force) {
|
2439 | var _this = this;
|
2440 | if (!this.lgOpened || (!this.settings.closable && !force)) {
|
2441 | return 0;
|
2442 | }
|
2443 | this.LGel.trigger(lGEvents.beforeClose);
|
2444 | $LG(window).scrollTop(this.prevScrollTop);
|
2445 | var currentItem = this.items[this.index];
|
2446 | var transform;
|
2447 | if (this.zoomFromOrigin && currentItem) {
|
2448 | var _a = this.mediaContainerPosition, top_4 = _a.top, bottom = _a.bottom;
|
2449 | var imageSize = utils.getSize(currentItem, this.outer, top_4 + bottom, this.galleryItems[this.index].__slideVideoInfo &&
|
2450 | this.settings.videoMaxSize);
|
2451 | transform = utils.getTransform(currentItem, this.outer, top_4, bottom, imageSize);
|
2452 | }
|
2453 | if (this.zoomFromOrigin && transform) {
|
2454 | this.outer.addClass('lg-closing lg-zoom-from-image');
|
2455 | this.getSlideItem(this.index)
|
2456 | .addClass('lg-start-end-progress')
|
2457 | .css('transition-duration', this.settings.startAnimationDuration + 'ms')
|
2458 | .css('transform', transform);
|
2459 | }
|
2460 | else {
|
2461 | this.outer.addClass('lg-hide-items');
|
2462 |
|
2463 |
|
2464 | this.outer.removeClass('lg-zoom-from-image');
|
2465 | }
|
2466 |
|
2467 |
|
2468 |
|
2469 | this.destroyModules();
|
2470 | this.lGalleryOn = false;
|
2471 | this.isDummyImageRemoved = false;
|
2472 | this.zoomFromOrigin = this.settings.zoomFromOrigin;
|
2473 | clearTimeout(this.hideBarTimeout);
|
2474 | this.hideBarTimeout = false;
|
2475 | $LG('html').removeClass('lg-on');
|
2476 | this.outer.removeClass('lg-visible lg-components-open');
|
2477 |
|
2478 | this.$backdrop.removeClass('in').css('opacity', 0);
|
2479 | var removeTimeout = this.zoomFromOrigin && transform
|
2480 | ? Math.max(this.settings.startAnimationDuration, this.settings.backdropDuration)
|
2481 | : this.settings.backdropDuration;
|
2482 | this.$container.removeClass('lg-show-in');
|
2483 |
|
2484 | setTimeout(function () {
|
2485 | if (_this.zoomFromOrigin && transform) {
|
2486 | _this.outer.removeClass('lg-zoom-from-image');
|
2487 | }
|
2488 | _this.$container.removeClass('lg-show');
|
2489 |
|
2490 | _this.$backdrop
|
2491 | .removeAttr('style')
|
2492 | .css('transition-duration', _this.settings.backdropDuration + 'ms');
|
2493 | _this.outer.removeClass("lg-closing " + _this.settings.startClass);
|
2494 | _this.getSlideItem(_this.index).removeClass('lg-start-end-progress');
|
2495 | _this.$inner.empty();
|
2496 | if (_this.lgOpened) {
|
2497 | _this.LGel.trigger(lGEvents.afterClose, {
|
2498 | instance: _this,
|
2499 | });
|
2500 | }
|
2501 | if (_this.outer.get()) {
|
2502 | _this.outer.get().blur();
|
2503 | }
|
2504 | _this.lgOpened = false;
|
2505 | }, removeTimeout + 100);
|
2506 | return removeTimeout + 100;
|
2507 | };
|
2508 | LightGallery.prototype.initModules = function () {
|
2509 | this.plugins.forEach(function (module) {
|
2510 | try {
|
2511 | module.init();
|
2512 | }
|
2513 | catch (err) {
|
2514 | console.warn("lightGallery:- make sure lightGallery module is properly initiated");
|
2515 | }
|
2516 | });
|
2517 | };
|
2518 | LightGallery.prototype.destroyModules = function (destroy) {
|
2519 | this.plugins.forEach(function (module) {
|
2520 | try {
|
2521 | if (destroy) {
|
2522 | module.destroy();
|
2523 | }
|
2524 | else {
|
2525 | module.closeGallery && module.closeGallery();
|
2526 | }
|
2527 | }
|
2528 | catch (err) {
|
2529 | console.warn("lightGallery:- make sure lightGallery module is properly destroyed");
|
2530 | }
|
2531 | });
|
2532 | };
|
2533 | |
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 | LightGallery.prototype.refresh = function (galleryItems) {
|
2548 | if (!this.settings.dynamic) {
|
2549 | this.invalidateItems();
|
2550 | }
|
2551 | if (galleryItems) {
|
2552 | this.galleryItems = galleryItems;
|
2553 | }
|
2554 | else {
|
2555 | this.galleryItems = this.getItems();
|
2556 | }
|
2557 | this.updateControls();
|
2558 | this.openGalleryOnItemClick();
|
2559 | this.LGel.trigger(lGEvents.updateSlides);
|
2560 | };
|
2561 | LightGallery.prototype.updateControls = function () {
|
2562 | this.addSlideVideoInfo(this.galleryItems);
|
2563 | this.updateCounterTotal();
|
2564 | this.manageSingleSlideClassName();
|
2565 | };
|
2566 | |
2567 |
|
2568 |
|
2569 |
|
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 | LightGallery.prototype.destroy = function () {
|
2580 | var _this = this;
|
2581 | var closeTimeout = this.closeGallery(true);
|
2582 | setTimeout(function () {
|
2583 | _this.destroyModules(true);
|
2584 | if (!_this.settings.dynamic) {
|
2585 | _this.invalidateItems();
|
2586 | }
|
2587 | $LG(window).off(".lg.global" + _this.lgId);
|
2588 | _this.LGel.off('.lg');
|
2589 | _this.$container.remove();
|
2590 | }, closeTimeout);
|
2591 | return closeTimeout;
|
2592 | };
|
2593 | return LightGallery;
|
2594 | }());
|
2595 |
|
2596 | function lightGallery(el, options) {
|
2597 | return new LightGallery(el, options);
|
2598 | }
|
2599 |
|
2600 | return lightGallery;
|
2601 |
|
2602 | })));
|
2603 |
|