PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.37
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.37
3.37 3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 All 142 releases
photonic / include / ext / glightbox / glightbox.js

glightbox.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.37, at include/ext/glightbox/glightbox.js

3,657 lines 107.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * "Gie" Lightbox (GLightbox) - https://biati-digital.github.io/glightbox/ | https://github.com/biati-digital/glightbox
3 * MIT License
4 * Version Date: 2022-03-12
5 */
6 (function (global, factory) {
7 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8 typeof define === 'function' && define.amd ? define(factory) :
9 (global = global || self, global.GLightbox = factory());
10 }(this, (function () { 'use strict';
11
12 function _typeof(obj) {
13 "@babel/helpers - typeof";
14
15 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
16 _typeof = function (obj) {
17 return typeof obj;
18 };
19 } else {
20 _typeof = function (obj) {
21 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
22 };
23 }
24
25 return _typeof(obj);
26 }
27
28 function _classCallCheck(instance, Constructor) {
29 if (!(instance instanceof Constructor)) {
30 throw new TypeError("Cannot call a class as a function");
31 }
32 }
33
34 function _defineProperties(target, props) {
35 for (var i = 0; i < props.length; i++) {
36 var descriptor = props[i];
37 descriptor.enumerable = descriptor.enumerable || false;
38 descriptor.configurable = true;
39 if ("value" in descriptor) descriptor.writable = true;
40 Object.defineProperty(target, descriptor.key, descriptor);
41 }
42 }
43
44 function _createClass(Constructor, protoProps, staticProps) {
45 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
46 if (staticProps) _defineProperties(Constructor, staticProps);
47 return Constructor;
48 }
49
50 var uid = Date.now();
51 function extend() {
52 var extended = {};
53 var deep = true;
54 var i = 0;
55 var length = arguments.length;
56
57 if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
58 deep = arguments[0];
59 i++;
60 }
61
62 var merge = function merge(obj) {
63 for (var prop in obj) {
64 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
65 if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
66 extended[prop] = extend(true, extended[prop], obj[prop]);
67 } else {
68 extended[prop] = obj[prop];
69 }
70 }
71 }
72 };
73
74 for (; i < length; i++) {
75 var obj = arguments[i];
76 merge(obj);
77 }
78
79 return extended;
80 }
81 function each(collection, callback) {
82 if (isNode(collection) || collection === window || collection === document) {
83 collection = [collection];
84 }
85
86 if (!isArrayLike(collection) && !isObject(collection)) {
87 collection = [collection];
88 }
89
90 if (size(collection) == 0) {
91 return;
92 }
93
94 if (isArrayLike(collection) && !isObject(collection)) {
95 var l = collection.length,
96 i = 0;
97
98 for (; i < l; i++) {
99 if (callback.call(collection[i], collection[i], i, collection) === false) {
100 break;
101 }
102 }
103 } else if (isObject(collection)) {
104 for (var key in collection) {
105 if (has(collection, key)) {
106 if (callback.call(collection[key], collection[key], key, collection) === false) {
107 break;
108 }
109 }
110 }
111 }
112 }
113 function getNodeEvents(node) {
114 var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
115 var fn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
116 var cache = node[uid] = node[uid] || [];
117 var data = {
118 all: cache,
119 evt: null,
120 found: null
121 };
122
123 if (name && fn && size(cache) > 0) {
124 each(cache, function (cl, i) {
125 if (cl.eventName == name && cl.fn.toString() == fn.toString()) {
126 data.found = true;
127 data.evt = i;
128 return false;
129 }
130 });
131 }
132
133 return data;
134 }
135 function addEvent(eventName) {
136 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
137 onElement = _ref.onElement,
138 withCallback = _ref.withCallback,
139 _ref$avoidDuplicate = _ref.avoidDuplicate,
140 avoidDuplicate = _ref$avoidDuplicate === void 0 ? true : _ref$avoidDuplicate,
141 _ref$once = _ref.once,
142 once = _ref$once === void 0 ? false : _ref$once,
143 _ref$useCapture = _ref.useCapture,
144 useCapture = _ref$useCapture === void 0 ? false : _ref$useCapture;
145
146 var thisArg = arguments.length > 2 ? arguments[2] : undefined;
147 var element = onElement || [];
148
149 if (isString(element)) {
150 element = document.querySelectorAll(element);
151 }
152
153 function handler(event) {
154 if (isFunction(withCallback)) {
155 withCallback.call(thisArg, event, this);
156 }
157
158 if (once) {
159 handler.destroy();
160 }
161 }
162
163 handler.destroy = function () {
164 each(element, function (el) {
165 var events = getNodeEvents(el, eventName, handler);
166
167 if (events.found) {
168 events.all.splice(events.evt, 1);
169 }
170
171 if (el.removeEventListener) {
172 el.removeEventListener(eventName, handler, useCapture);
173 }
174 });
175 };
176
177 each(element, function (el) {
178 var events = getNodeEvents(el, eventName, handler);
179
180 if (el.addEventListener && avoidDuplicate && !events.found || !avoidDuplicate) {
181 el.addEventListener(eventName, handler, useCapture);
182 events.all.push({
183 eventName: eventName,
184 fn: handler
185 });
186 }
187 });
188 return handler;
189 }
190 function addClass(node, name) {
191 each(name.split(' '), function (cl) {
192 return node.classList.add(cl);
193 });
194 }
195 function removeClass(node, name) {
196 each(name.split(' '), function (cl) {
197 return node.classList.remove(cl);
198 });
199 }
200 function hasClass(node, name) {
201 return node.classList.contains(name);
202 }
203 function closest(elem, selector) {
204 while (elem !== document.body) {
205 elem = elem.parentElement;
206
207 if (!elem) {
208 return false;
209 }
210
211 var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msMatchesSelector(selector);
212
213 if (matches) {
214 return elem;
215 }
216 }
217 }
218 function animateElement(element) {
219 var animation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
220 var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
221
222 if (!element || animation === '') {
223 return false;
224 }
225
226 if (animation === 'none') {
227 if (isFunction(callback)) {
228 callback();
229 }
230
231 return false;
232 }
233
234 var animationEnd = whichAnimationEvent();
235 var animationNames = animation.split(' ');
236 each(animationNames, function (name) {
237 addClass(element, 'g' + name);
238 });
239 addEvent(animationEnd, {
240 onElement: element,
241 avoidDuplicate: false,
242 once: true,
243 withCallback: function withCallback(event, target) {
244 each(animationNames, function (name) {
245 removeClass(target, 'g' + name);
246 });
247
248 if (isFunction(callback)) {
249 callback();
250 }
251 }
252 });
253 }
254 function cssTransform(node) {
255 var translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
256
257 if (translate === '') {
258 node.style.webkitTransform = '';
259 node.style.MozTransform = '';
260 node.style.msTransform = '';
261 node.style.OTransform = '';
262 node.style.transform = '';
263 return false;
264 }
265
266 node.style.webkitTransform = translate;
267 node.style.MozTransform = translate;
268 node.style.msTransform = translate;
269 node.style.OTransform = translate;
270 node.style.transform = translate;
271 }
272 function show(element) {
273 element.style.display = 'block';
274 }
275 function hide(element) {
276 element.style.display = 'none';
277 }
278 function createHTML(htmlStr) {
279 var frag = document.createDocumentFragment(),
280 temp = document.createElement('div');
281 temp.innerHTML = htmlStr;
282
283 while (temp.firstChild) {
284 frag.appendChild(temp.firstChild);
285 }
286
287 return frag;
288 }
289 function windowSize() {
290 return {
291 width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
292 height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
293 };
294 }
295 function whichAnimationEvent() {
296 var t,
297 el = document.createElement('fakeelement');
298 var animations = {
299 animation: 'animationend',
300 OAnimation: 'oAnimationEnd',
301 MozAnimation: 'animationend',
302 WebkitAnimation: 'webkitAnimationEnd'
303 };
304
305 for (t in animations) {
306 if (el.style[t] !== undefined) {
307 return animations[t];
308 }
309 }
310 }
311 function whichTransitionEvent() {
312 var t,
313 el = document.createElement('fakeelement');
314 var transitions = {
315 transition: 'transitionend',
316 OTransition: 'oTransitionEnd',
317 MozTransition: 'transitionend',
318 WebkitTransition: 'webkitTransitionEnd'
319 };
320
321 for (t in transitions) {
322 if (el.style[t] !== undefined) {
323 return transitions[t];
324 }
325 }
326 }
327 function createIframe(config) {
328 var url = config.url,
329 allow = config.allow,
330 callback = config.callback,
331 appendTo = config.appendTo;
332 var iframe = document.createElement('iframe');
333 iframe.className = 'vimeo-video gvideo';
334 iframe.src = url;
335 iframe.style.width = '100%';
336 iframe.style.height = '100%';
337
338 if (allow) {
339 iframe.setAttribute('allow', allow);
340 }
341
342 iframe.onload = function () {
343 iframe.onload = null;
344 addClass(iframe, 'node-ready');
345
346 if (isFunction(callback)) {
347 callback();
348 }
349 };
350
351 if (appendTo) {
352 appendTo.appendChild(iframe);
353 }
354
355 return iframe;
356 }
357 function waitUntil(check, onComplete, delay, timeout) {
358 if (check()) {
359 onComplete();
360 return;
361 }
362
363 if (!delay) {
364 delay = 100;
365 }
366
367 var timeoutPointer;
368 var intervalPointer = setInterval(function () {
369 if (!check()) {
370 return;
371 }
372
373 clearInterval(intervalPointer);
374
375 if (timeoutPointer) {
376 clearTimeout(timeoutPointer);
377 }
378
379 onComplete();
380 }, delay);
381
382 if (timeout) {
383 timeoutPointer = setTimeout(function () {
384 clearInterval(intervalPointer);
385 }, timeout);
386 }
387 }
388 function injectAssets(url, waitFor, callback) {
389 if (isNil(url)) {
390 console.error('Inject assets error');
391 return;
392 }
393
394 if (isFunction(waitFor)) {
395 callback = waitFor;
396 waitFor = false;
397 }
398
399 if (isString(waitFor) && waitFor in window) {
400 if (isFunction(callback)) {
401 callback();
402 }
403
404 return;
405 }
406
407 var found;
408
409 if (url.indexOf('.css') !== -1) {
410 found = document.querySelectorAll('link[href="' + url + '"]');
411
412 if (found && found.length > 0) {
413 if (isFunction(callback)) {
414 callback();
415 }
416
417 return;
418 }
419
420 var head = document.getElementsByTagName('head')[0];
421 var headStyles = head.querySelectorAll('link[rel="stylesheet"]');
422 var link = document.createElement('link');
423 link.rel = 'stylesheet';
424 link.type = 'text/css';
425 link.href = url;
426 link.media = 'all';
427
428 if (headStyles) {
429 head.insertBefore(link, headStyles[0]);
430 } else {
431 head.appendChild(link);
432 }
433
434 if (isFunction(callback)) {
435 callback();
436 }
437
438 return;
439 }
440
441 found = document.querySelectorAll('script[src="' + url + '"]');
442
443 if (found && found.length > 0) {
444 if (isFunction(callback)) {
445 if (isString(waitFor)) {
446 waitUntil(function () {
447 return typeof window[waitFor] !== 'undefined';
448 }, function () {
449 callback();
450 });
451 return false;
452 }
453
454 callback();
455 }
456
457 return;
458 }
459
460 var script = document.createElement('script');
461 script.type = 'text/javascript';
462 script.src = url;
463
464 script.onload = function () {
465 if (isFunction(callback)) {
466 if (isString(waitFor)) {
467 waitUntil(function () {
468 return typeof window[waitFor] !== 'undefined';
469 }, function () {
470 callback();
471 });
472 return false;
473 }
474
475 callback();
476 }
477 };
478
479 document.body.appendChild(script);
480 }
481 function isMobile() {
482 return 'navigator' in window && window.navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i);
483 }
484 function isTouch() {
485 return isMobile() !== null || document.createTouch !== undefined || 'ontouchstart' in window || 'onmsgesturechange' in window || navigator.msMaxTouchPoints;
486 }
487 function isFunction(f) {
488 return typeof f === 'function';
489 }
490 function isString(s) {
491 return typeof s === 'string';
492 }
493 function isNode(el) {
494 return !!(el && el.nodeType && el.nodeType == 1);
495 }
496 function isArray(ar) {
497 return Array.isArray(ar);
498 }
499 function isArrayLike(ar) {
500 return ar && ar.length && isFinite(ar.length);
501 }
502 function isObject(o) {
503 var type = _typeof(o);
504
505 return type === 'object' && o != null && !isFunction(o) && !isArray(o);
506 }
507 function isNil(o) {
508 return o == null;
509 }
510 function has(obj, key) {
511 return obj !== null && hasOwnProperty.call(obj, key);
512 }
513 function size(o) {
514 if (isObject(o)) {
515 if (o.keys) {
516 return o.keys().length;
517 }
518
519 var l = 0;
520
521 for (var k in o) {
522 if (has(o, k)) {
523 l++;
524 }
525 }
526
527 return l;
528 } else {
529 return o.length;
530 }
531 }
532 function isNumber(n) {
533 return !isNaN(parseFloat(n)) && isFinite(n);
534 }
535
536 function getNextFocusElement() {
537 var current = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
538 var btns = document.querySelectorAll('.gbtn[data-taborder]:not(.disabled)');
539
540 if (!btns.length) {
541 return false;
542 }
543
544 if (btns.length == 1) {
545 return btns[0];
546 }
547
548 if (typeof current == 'string') {
549 current = parseInt(current);
550 }
551
552 var orders = [];
553 each(btns, function (btn) {
554 orders.push(btn.getAttribute('data-taborder'));
555 });
556 var highestOrder = Math.max.apply(Math, orders.map(function (order) {
557 return parseInt(order);
558 }));
559 var newIndex = current < 0 ? 1 : current + 1;
560
561 if (newIndex > highestOrder) {
562 newIndex = '1';
563 }
564
565 var nextOrders = orders.filter(function (el) {
566 return el >= parseInt(newIndex);
567 });
568 var nextFocus = nextOrders.sort()[0];
569 return document.querySelector(".gbtn[data-taborder=\"".concat(nextFocus, "\"]"));
570 }
571
572 function keyboardNavigation(instance) {
573 if (instance.events.hasOwnProperty('keyboard')) {
574 return false;
575 }
576
577 instance.events['keyboard'] = addEvent('keydown', {
578 onElement: window,
579 withCallback: function withCallback(event, target) {
580 event = event || window.event;
581 var key = event.keyCode;
582
583 if (key == 9) {
584 var focusedButton = document.querySelector('.gbtn.focused');
585
586 if (!focusedButton) {
587 var activeElement = document.activeElement && document.activeElement.nodeName ? document.activeElement.nodeName.toLocaleLowerCase() : false;
588
589 if (activeElement == 'input' || activeElement == 'textarea' || activeElement == 'button') {
590 return;
591 }
592 }
593
594 event.preventDefault();
595 var btns = document.querySelectorAll('.gbtn[data-taborder]');
596
597 if (!btns || btns.length <= 0) {
598 return;
599 }
600
601 if (!focusedButton) {
602 var first = getNextFocusElement();
603
604 if (first) {
605 first.focus();
606 addClass(first, 'focused');
607 }
608
609 return;
610 }
611
612 var currentFocusOrder = focusedButton.getAttribute('data-taborder');
613 var nextFocus = getNextFocusElement(currentFocusOrder);
614 removeClass(focusedButton, 'focused');
615
616 if (nextFocus) {
617 nextFocus.focus();
618 addClass(nextFocus, 'focused');
619 }
620 }
621
622 if (key == 39) {
623 instance.nextSlide();
624 }
625
626 if (key == 37) {
627 instance.prevSlide();
628 }
629
630 if (key == 27) {
631 instance.close();
632 }
633 }
634 });
635 }
636
637 function getLen(v) {
638 return Math.sqrt(v.x * v.x + v.y * v.y);
639 }
640
641 function dot(v1, v2) {
642 return v1.x * v2.x + v1.y * v2.y;
643 }
644
645 function getAngle(v1, v2) {
646 var mr = getLen(v1) * getLen(v2);
647
648 if (mr === 0) {
649 return 0;
650 }
651
652 var r = dot(v1, v2) / mr;
653
654 if (r > 1) {
655 r = 1;
656 }
657
658 return Math.acos(r);
659 }
660
661 function cross(v1, v2) {
662 return v1.x * v2.y - v2.x * v1.y;
663 }
664
665 function getRotateAngle(v1, v2) {
666 var angle = getAngle(v1, v2);
667
668 if (cross(v1, v2) > 0) {
669 angle *= -1;
670 }
671
672 return angle * 180 / Math.PI;
673 }
674
675 var EventsHandlerAdmin = function () {
676 function EventsHandlerAdmin(el) {
677 _classCallCheck(this, EventsHandlerAdmin);
678
679 this.handlers = [];
680 this.el = el;
681 }
682
683 _createClass(EventsHandlerAdmin, [{
684 key: "add",
685 value: function add(handler) {
686 this.handlers.push(handler);
687 }
688 }, {
689 key: "del",
690 value: function del(handler) {
691 if (!handler) {
692 this.handlers = [];
693 }
694
695 for (var i = this.handlers.length; i >= 0; i--) {
696 if (this.handlers[i] === handler) {
697 this.handlers.splice(i, 1);
698 }
699 }
700 }
701 }, {
702 key: "dispatch",
703 value: function dispatch() {
704 for (var i = 0, len = this.handlers.length; i < len; i++) {
705 var handler = this.handlers[i];
706
707 if (typeof handler === 'function') {
708 handler.apply(this.el, arguments);
709 }
710 }
711 }
712 }]);
713
714 return EventsHandlerAdmin;
715 }();
716
717 function wrapFunc(el, handler) {
718 var EventshandlerAdmin = new EventsHandlerAdmin(el);
719 EventshandlerAdmin.add(handler);
720 return EventshandlerAdmin;
721 }
722
723 var TouchEvents = function () {
724 function TouchEvents(el, option) {
725 _classCallCheck(this, TouchEvents);
726
727 this.element = typeof el == 'string' ? document.querySelector(el) : el;
728 this.start = this.start.bind(this);
729 this.move = this.move.bind(this);
730 this.end = this.end.bind(this);
731 this.cancel = this.cancel.bind(this);
732 this.element.addEventListener('touchstart', this.start, false);
733 this.element.addEventListener('touchmove', this.move, false);
734 this.element.addEventListener('touchend', this.end, false);
735 this.element.addEventListener('touchcancel', this.cancel, false);
736 this.preV = {
737 x: null,
738 y: null
739 };
740 this.pinchStartLen = null;
741 this.zoom = 1;
742 this.isDoubleTap = false;
743
744 var noop = function noop() {};
745
746 this.rotate = wrapFunc(this.element, option.rotate || noop);
747 this.touchStart = wrapFunc(this.element, option.touchStart || noop);
748 this.multipointStart = wrapFunc(this.element, option.multipointStart || noop);
749 this.multipointEnd = wrapFunc(this.element, option.multipointEnd || noop);
750 this.pinch = wrapFunc(this.element, option.pinch || noop);
751 this.swipe = wrapFunc(this.element, option.swipe || noop);
752 this.tap = wrapFunc(this.element, option.tap || noop);
753 this.doubleTap = wrapFunc(this.element, option.doubleTap || noop);
754 this.longTap = wrapFunc(this.element, option.longTap || noop);
755 this.singleTap = wrapFunc(this.element, option.singleTap || noop);
756 this.pressMove = wrapFunc(this.element, option.pressMove || noop);
757 this.twoFingerPressMove = wrapFunc(this.element, option.twoFingerPressMove || noop);
758 this.touchMove = wrapFunc(this.element, option.touchMove || noop);
759 this.touchEnd = wrapFunc(this.element, option.touchEnd || noop);
760 this.touchCancel = wrapFunc(this.element, option.touchCancel || noop);
761 this.translateContainer = this.element;
762 this._cancelAllHandler = this.cancelAll.bind(this);
763 window.addEventListener('scroll', this._cancelAllHandler);
764 this.delta = null;
765 this.last = null;
766 this.now = null;
767 this.tapTimeout = null;
768 this.singleTapTimeout = null;
769 this.longTapTimeout = null;
770 this.swipeTimeout = null;
771 this.x1 = this.x2 = this.y1 = this.y2 = null;
772 this.preTapPosition = {
773 x: null,
774 y: null
775 };
776 }
777
778 _createClass(TouchEvents, [{
779 key: "start",
780 value: function start(evt) {
781 if (!evt.touches) {
782 return;
783 }
784
785 var ignoreDragFor = ['a', 'button', 'input'];
786
787 if (evt.target && evt.target.nodeName && ignoreDragFor.indexOf(evt.target.nodeName.toLowerCase()) >= 0) {
788 console.log('ignore drag for this touched element', evt.target.nodeName.toLowerCase());
789 return;
790 }
791
792 this.now = Date.now();
793 this.x1 = evt.touches[0].pageX;
794 this.y1 = evt.touches[0].pageY;
795 this.delta = this.now - (this.last || this.now);
796 this.touchStart.dispatch(evt, this.element);
797
798 if (this.preTapPosition.x !== null) {
799 this.isDoubleTap = this.delta > 0 && this.delta <= 250 && Math.abs(this.preTapPosition.x - this.x1) < 30 && Math.abs(this.preTapPosition.y - this.y1) < 30;
800
801 if (this.isDoubleTap) {
802 clearTimeout(this.singleTapTimeout);
803 }
804 }
805
806 this.preTapPosition.x = this.x1;
807 this.preTapPosition.y = this.y1;
808 this.last = this.now;
809 var preV = this.preV,
810 len = evt.touches.length;
811
812 if (len > 1) {
813 this._cancelLongTap();
814
815 this._cancelSingleTap();
816
817 var v = {
818 x: evt.touches[1].pageX - this.x1,
819 y: evt.touches[1].pageY - this.y1
820 };
821 preV.x = v.x;
822 preV.y = v.y;
823 this.pinchStartLen = getLen(preV);
824 this.multipointStart.dispatch(evt, this.element);
825 }
826
827 this._preventTap = false;
828 this.longTapTimeout = setTimeout(function () {
829 this.longTap.dispatch(evt, this.element);
830 this._preventTap = true;
831 }.bind(this), 750);
832 }
833 }, {
834 key: "move",
835 value: function move(evt) {
836 if (!evt.touches) {
837 return;
838 }
839
840 var preV = this.preV,
841 len = evt.touches.length,
842 currentX = evt.touches[0].pageX,
843 currentY = evt.touches[0].pageY;
844 this.isDoubleTap = false;
845
846 if (len > 1) {
847 var sCurrentX = evt.touches[1].pageX,
848 sCurrentY = evt.touches[1].pageY;
849 var v = {
850 x: evt.touches[1].pageX - currentX,
851 y: evt.touches[1].pageY - currentY
852 };
853
854 if (preV.x !== null) {
855 if (this.pinchStartLen > 0) {
856 evt.zoom = getLen(v) / this.pinchStartLen;
857 this.pinch.dispatch(evt, this.element);
858 }
859
860 evt.angle = getRotateAngle(v, preV);
861 this.rotate.dispatch(evt, this.element);
862 }
863
864 preV.x = v.x;
865 preV.y = v.y;
866
867 if (this.x2 !== null && this.sx2 !== null) {
868 evt.deltaX = (currentX - this.x2 + sCurrentX - this.sx2) / 2;
869 evt.deltaY = (currentY - this.y2 + sCurrentY - this.sy2) / 2;
870 } else {
871 evt.deltaX = 0;
872 evt.deltaY = 0;
873 }
874
875 this.twoFingerPressMove.dispatch(evt, this.element);
876 this.sx2 = sCurrentX;
877 this.sy2 = sCurrentY;
878 } else {
879 if (this.x2 !== null) {
880 evt.deltaX = currentX - this.x2;
881 evt.deltaY = currentY - this.y2;
882 var movedX = Math.abs(this.x1 - this.x2),
883 movedY = Math.abs(this.y1 - this.y2);
884
885 if (movedX > 10 || movedY > 10) {
886 this._preventTap = true;
887 }
888 } else {
889 evt.deltaX = 0;
890 evt.deltaY = 0;
891 }
892
893 this.pressMove.dispatch(evt, this.element);
894 }
895
896 this.touchMove.dispatch(evt, this.element);
897
898 this._cancelLongTap();
899
900 this.x2 = currentX;
901 this.y2 = currentY;
902
903 if (len > 1) {
904 evt.preventDefault();
905 }
906 }
907 }, {
908 key: "end",
909 value: function end(evt) {
910 if (!evt.changedTouches) {
911 return;
912 }
913
914 this._cancelLongTap();
915
916 var self = this;
917
918 if (evt.touches.length < 2) {
919 this.multipointEnd.dispatch(evt, this.element);
920 this.sx2 = this.sy2 = null;
921 }
922
923 if (this.x2 && Math.abs(this.x1 - this.x2) > 30 || this.y2 && Math.abs(this.y1 - this.y2) > 30) {
924 evt.direction = this._swipeDirection(this.x1, this.x2, this.y1, this.y2);
925 this.swipeTimeout = setTimeout(function () {
926 self.swipe.dispatch(evt, self.element);
927 }, 0);
928 } else {
929 this.tapTimeout = setTimeout(function () {
930 if (!self._preventTap) {
931 self.tap.dispatch(evt, self.element);
932 }
933
934 if (self.isDoubleTap) {
935 self.doubleTap.dispatch(evt, self.element);
936 self.isDoubleTap = false;
937 }
938 }, 0);
939
940 if (!self.isDoubleTap) {
941 self.singleTapTimeout = setTimeout(function () {
942 self.singleTap.dispatch(evt, self.element);
943 }, 250);
944 }
945 }
946
947 this.touchEnd.dispatch(evt, this.element);
948 this.preV.x = 0;
949 this.preV.y = 0;
950 this.zoom = 1;
951 this.pinchStartLen = null;
952 this.x1 = this.x2 = this.y1 = this.y2 = null;
953 }
954 }, {
955 key: "cancelAll",
956 value: function cancelAll() {
957 this._preventTap = true;
958 clearTimeout(this.singleTapTimeout);
959 clearTimeout(this.tapTimeout);
960 clearTimeout(this.longTapTimeout);
961 clearTimeout(this.swipeTimeout);
962 }
963 }, {
964 key: "cancel",
965 value: function cancel(evt) {
966 this.cancelAll();
967 this.touchCancel.dispatch(evt, this.element);
968 }
969 }, {
970 key: "_cancelLongTap",
971 value: function _cancelLongTap() {
972 clearTimeout(this.longTapTimeout);
973 }
974 }, {
975 key: "_cancelSingleTap",
976 value: function _cancelSingleTap() {
977 clearTimeout(this.singleTapTimeout);
978 }
979 }, {
980 key: "_swipeDirection",
981 value: function _swipeDirection(x1, x2, y1, y2) {
982 return Math.abs(x1 - x2) >= Math.abs(y1 - y2) ? x1 - x2 > 0 ? 'Left' : 'Right' : y1 - y2 > 0 ? 'Up' : 'Down';
983 }
984 }, {
985 key: "on",
986 value: function on(evt, handler) {
987 if (this[evt]) {
988 this[evt].add(handler);
989 }
990 }
991 }, {
992 key: "off",
993 value: function off(evt, handler) {
994 if (this[evt]) {
995 this[evt].del(handler);
996 }
997 }
998 }, {
999 key: "destroy",
1000 value: function destroy() {
1001 if (this.singleTapTimeout) {
1002 clearTimeout(this.singleTapTimeout);
1003 }
1004
1005 if (this.tapTimeout) {
1006 clearTimeout(this.tapTimeout);
1007 }
1008
1009 if (this.longTapTimeout) {
1010 clearTimeout(this.longTapTimeout);
1011 }
1012
1013 if (this.swipeTimeout) {
1014 clearTimeout(this.swipeTimeout);
1015 }
1016
1017 this.element.removeEventListener('touchstart', this.start);
1018 this.element.removeEventListener('touchmove', this.move);
1019 this.element.removeEventListener('touchend', this.end);
1020 this.element.removeEventListener('touchcancel', this.cancel);
1021 this.rotate.del();
1022 this.touchStart.del();
1023 this.multipointStart.del();
1024 this.multipointEnd.del();
1025 this.pinch.del();
1026 this.swipe.del();
1027 this.tap.del();
1028 this.doubleTap.del();
1029 this.longTap.del();
1030 this.singleTap.del();
1031 this.pressMove.del();
1032 this.twoFingerPressMove.del();
1033 this.touchMove.del();
1034 this.touchEnd.del();
1035 this.touchCancel.del();
1036 this.preV = this.pinchStartLen = this.zoom = this.isDoubleTap = this.delta = this.last = this.now = this.tapTimeout = this.singleTapTimeout = this.longTapTimeout = this.swipeTimeout = this.x1 = this.x2 = this.y1 = this.y2 = this.preTapPosition = this.rotate = this.touchStart = this.multipointStart = this.multipointEnd = this.pinch = this.swipe = this.tap = this.doubleTap = this.longTap = this.singleTap = this.pressMove = this.touchMove = this.touchEnd = this.touchCancel = this.twoFingerPressMove = null;
1037 window.removeEventListener('scroll', this._cancelAllHandler);
1038 return null;
1039 }
1040 }]);
1041
1042 return TouchEvents;
1043 }();
1044
1045 function resetSlideMove(slide) {
1046 var transitionEnd = whichTransitionEvent();
1047 var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
1048 var media = hasClass(slide, 'gslide-media') ? slide : slide.querySelector('.gslide-media');
1049 var container = closest(media, '.ginner-container');
1050 var desc = slide.querySelector('.gslide-description');
1051
1052 if (windowWidth > 769) {
1053 media = container;
1054 }
1055
1056 addClass(media, 'greset');
1057 cssTransform(media, 'translate3d(0, 0, 0)');
1058 addEvent(transitionEnd, {
1059 onElement: media,
1060 once: true,
1061 withCallback: function withCallback(event, target) {
1062 removeClass(media, 'greset');
1063 }
1064 });
1065 media.style.opacity = '';
1066
1067 if (desc) {
1068 desc.style.opacity = '';
1069 }
1070 }
1071
1072 function touchNavigation(instance) {
1073 if (instance.events.hasOwnProperty('touch')) {
1074 return false;
1075 }
1076
1077 var winSize = windowSize();
1078 var winWidth = winSize.width;
1079 var winHeight = winSize.height;
1080 var process = false;
1081 var currentSlide = null;
1082 var media = null;
1083 var mediaImage = null;
1084 var doingMove = false;
1085 var initScale = 1;
1086 var maxScale = 4.5;
1087 var currentScale = 1;
1088 var doingZoom = false;
1089 var imageZoomed = false;
1090 var zoomedPosX = null;
1091 var zoomedPosY = null;
1092 var lastZoomedPosX = null;
1093 var lastZoomedPosY = null;
1094 var hDistance;
1095 var vDistance;
1096 var hDistancePercent = 0;
1097 var vDistancePercent = 0;
1098 var vSwipe = false;
1099 var hSwipe = false;
1100 var startCoords = {};
1101 var endCoords = {};
1102 var xDown = 0;
1103 var yDown = 0;
1104 var isInlined;
1105 var sliderWrapper = document.getElementById('glightbox-slider');
1106 var overlay = document.querySelector('.goverlay');
1107 var touchInstance = new TouchEvents(sliderWrapper, {
1108 touchStart: function touchStart(e) {
1109 process = true;
1110
1111 if (hasClass(e.targetTouches[0].target, 'ginner-container') || closest(e.targetTouches[0].target, '.gslide-desc') || e.targetTouches[0].target.nodeName.toLowerCase() == 'a') {
1112 process = false;
1113 }
1114
1115 if (closest(e.targetTouches[0].target, '.gslide-inline') && !hasClass(e.targetTouches[0].target.parentNode, 'gslide-inline')) {
1116 process = false;
1117 }
1118
1119 if (process) {
1120 endCoords = e.targetTouches[0];
1121 startCoords.pageX = e.targetTouches[0].pageX;
1122 startCoords.pageY = e.targetTouches[0].pageY;
1123 xDown = e.targetTouches[0].clientX;
1124 yDown = e.targetTouches[0].clientY;
1125 currentSlide = instance.activeSlide;
1126 media = currentSlide.querySelector('.gslide-media');
1127 isInlined = currentSlide.querySelector('.gslide-inline');
1128 mediaImage = null;
1129
1130 if (hasClass(media, 'gslide-image')) {
1131 mediaImage = media.querySelector('img');
1132 }
1133
1134 var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
1135
1136 if (windowWidth > 769) {
1137 media = currentSlide.querySelector('.ginner-container');
1138 }
1139
1140 removeClass(overlay, 'greset');
1141
1142 if (e.pageX > 20 && e.pageX < window.innerWidth - 20) {
1143 return;
1144 }
1145
1146 e.preventDefault();
1147 }
1148 },
1149 touchMove: function touchMove(e) {
1150 if (!process) {
1151 return;
1152 }
1153
1154 endCoords = e.targetTouches[0];
1155
1156 if (doingZoom || imageZoomed) {
1157 return;
1158 }
1159
1160 if (isInlined && isInlined.offsetHeight > winHeight) {
1161 var moved = startCoords.pageX - endCoords.pageX;
1162
1163 if (Math.abs(moved) <= 13) {
1164 return false;
1165 }
1166 }
1167
1168 doingMove = true;
1169 var xUp = e.targetTouches[0].clientX;
1170 var yUp = e.targetTouches[0].clientY;
1171 var xDiff = xDown - xUp;
1172 var yDiff = yDown - yUp;
1173
1174 if (Math.abs(xDiff) > Math.abs(yDiff)) {
1175 vSwipe = false;
1176 hSwipe = true;
1177 } else {
1178 hSwipe = false;
1179 vSwipe = true;
1180 }
1181
1182 hDistance = endCoords.pageX - startCoords.pageX;
1183 hDistancePercent = hDistance * 100 / winWidth;
1184 vDistance = endCoords.pageY - startCoords.pageY;
1185 vDistancePercent = vDistance * 100 / winHeight;
1186 var opacity;
1187
1188 if (vSwipe && mediaImage) {
1189 opacity = 1 - Math.abs(vDistance) / winHeight;
1190 overlay.style.opacity = opacity;
1191
1192 if (instance.settings.touchFollowAxis) {
1193 hDistancePercent = 0;
1194 }
1195 }
1196
1197 if (hSwipe) {
1198 opacity = 1 - Math.abs(hDistance) / winWidth;
1199 media.style.opacity = opacity;
1200
1201 if (instance.settings.touchFollowAxis) {
1202 vDistancePercent = 0;
1203 }
1204 }
1205
1206 if (!mediaImage) {
1207 return cssTransform(media, "translate3d(".concat(hDistancePercent, "%, 0, 0)"));
1208 }
1209
1210 cssTransform(media, "translate3d(".concat(hDistancePercent, "%, ").concat(vDistancePercent, "%, 0)"));
1211 },
1212 touchEnd: function touchEnd() {
1213 if (!process) {
1214 return;
1215 }
1216
1217 doingMove = false;
1218
1219 if (imageZoomed || doingZoom) {
1220 lastZoomedPosX = zoomedPosX;
1221 lastZoomedPosY = zoomedPosY;
1222 return;
1223 }
1224
1225 var v = Math.abs(parseInt(vDistancePercent));
1226 var h = Math.abs(parseInt(hDistancePercent));
1227
1228 if (v > 29 && mediaImage) {
1229 instance.close();
1230 return;
1231 }
1232
1233 if (v < 29 && h < 25) {
1234 addClass(overlay, 'greset');
1235 overlay.style.opacity = 1;
1236 return resetSlideMove(media);
1237 }
1238 },
1239 multipointEnd: function multipointEnd() {
1240 setTimeout(function () {
1241 doingZoom = false;
1242 }, 50);
1243 },
1244 multipointStart: function multipointStart() {
1245 doingZoom = true;
1246 initScale = currentScale ? currentScale : 1;
1247 },
1248 pinch: function pinch(evt) {
1249 if (!mediaImage || doingMove) {
1250 return false;
1251 }
1252
1253 doingZoom = true;
1254 mediaImage.scaleX = mediaImage.scaleY = initScale * evt.zoom;
1255 var scale = initScale * evt.zoom;
1256 imageZoomed = true;
1257
1258 if (scale <= 1) {
1259 imageZoomed = false;
1260 scale = 1;
1261 lastZoomedPosY = null;
1262 lastZoomedPosX = null;
1263 zoomedPosX = null;
1264 zoomedPosY = null;
1265 mediaImage.setAttribute('style', '');
1266 return;
1267 }
1268
1269 if (scale > maxScale) {
1270 scale = maxScale;
1271 }
1272
1273 mediaImage.style.transform = "scale3d(".concat(scale, ", ").concat(scale, ", 1)");
1274 currentScale = scale;
1275 },
1276 pressMove: function pressMove(e) {
1277 if (imageZoomed && !doingZoom) {
1278 var mhDistance = endCoords.pageX - startCoords.pageX;
1279 var mvDistance = endCoords.pageY - startCoords.pageY;
1280
1281 if (lastZoomedPosX) {
1282 mhDistance = mhDistance + lastZoomedPosX;
1283 }
1284
1285 if (lastZoomedPosY) {
1286 mvDistance = mvDistance + lastZoomedPosY;
1287 }
1288
1289 zoomedPosX = mhDistance;
1290 zoomedPosY = mvDistance;
1291 var style = "translate3d(".concat(mhDistance, "px, ").concat(mvDistance, "px, 0)");
1292
1293 if (currentScale) {
1294 style += " scale3d(".concat(currentScale, ", ").concat(currentScale, ", 1)");
1295 }
1296
1297 cssTransform(mediaImage, style);
1298 }
1299 },
1300 swipe: function swipe(evt) {
1301 if (imageZoomed) {
1302 return;
1303 }
1304
1305 if (doingZoom) {
1306 doingZoom = false;
1307 return;
1308 }
1309
1310 if (evt.direction == 'Left') {
1311 if (instance.index == instance.elements.length - 1) {
1312 return resetSlideMove(media);
1313 }
1314
1315 instance.nextSlide();
1316 }
1317
1318 if (evt.direction == 'Right') {
1319 if (instance.index == 0) {
1320 return resetSlideMove(media);
1321 }
1322
1323 instance.prevSlide();
1324 }
1325 }
1326 });
1327 instance.events['touch'] = touchInstance;
1328 }
1329
1330 var ZoomImages = function () {
1331 function ZoomImages(el, slide) {
1332 var _this = this;
1333
1334 var onclose = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1335
1336 _classCallCheck(this, ZoomImages);
1337
1338 this.img = el;
1339 this.slide = slide;
1340 this.onclose = onclose;
1341
1342 if (this.img.setZoomEvents) {
1343 return false;
1344 }
1345
1346 this.active = false;
1347 this.zoomedIn = false;
1348 this.dragging = false;
1349 this.currentX = null;
1350 this.currentY = null;
1351 this.initialX = null;
1352 this.initialY = null;
1353 this.xOffset = 0;
1354 this.yOffset = 0;
1355 this.img.addEventListener('mousedown', function (e) {
1356 return _this.dragStart(e);
1357 }, false);
1358 this.img.addEventListener('mouseup', function (e) {
1359 return _this.dragEnd(e);
1360 }, false);
1361 this.img.addEventListener('mousemove', function (e) {
1362 return _this.drag(e);
1363 }, false);
1364 this.img.addEventListener('click', function (e) {
1365 if (_this.slide.classList.contains('dragging-nav')) {
1366 _this.zoomOut();
1367
1368 return false;
1369 }
1370
1371 if (!_this.zoomedIn) {
1372 return _this.zoomIn();
1373 }
1374
1375 if (_this.zoomedIn && !_this.dragging) {
1376 _this.zoomOut();
1377 }
1378 }, false);
1379 this.img.setZoomEvents = true;
1380 }
1381
1382 _createClass(ZoomImages, [{
1383 key: "zoomIn",
1384 value: function zoomIn() {
1385 var winWidth = this.widowWidth();
1386
1387 if (this.zoomedIn || winWidth <= 768) {
1388 return;
1389 }
1390
1391 var img = this.img;
1392 img.setAttribute('data-style', img.getAttribute('style'));
1393 img.style.maxWidth = img.naturalWidth + 'px';
1394 img.style.maxHeight = img.naturalHeight + 'px';
1395
1396 if (img.naturalWidth > winWidth) {
1397 var centerX = winWidth / 2 - img.naturalWidth / 2;
1398 this.setTranslate(this.img.parentNode, centerX, 0);
1399 }
1400
1401 this.slide.classList.add('zoomed');
1402 this.zoomedIn = true;
1403 }
1404 }, {
1405 key: "zoomOut",
1406 value: function zoomOut() {
1407 this.img.parentNode.setAttribute('style', '');
1408 this.img.setAttribute('style', this.img.getAttribute('data-style'));
1409 this.slide.classList.remove('zoomed');
1410 this.zoomedIn = false;
1411 this.currentX = null;
1412 this.currentY = null;
1413 this.initialX = null;
1414 this.initialY = null;
1415 this.xOffset = 0;
1416 this.yOffset = 0;
1417
1418 if (this.onclose && typeof this.onclose == 'function') {
1419 this.onclose();
1420 }
1421 }
1422 }, {
1423 key: "dragStart",
1424 value: function dragStart(e) {
1425 e.preventDefault();
1426
1427 if (!this.zoomedIn) {
1428 this.active = false;
1429 return;
1430 }
1431
1432 if (e.type === 'touchstart') {
1433 this.initialX = e.touches[0].clientX - this.xOffset;
1434 this.initialY = e.touches[0].clientY - this.yOffset;
1435 } else {
1436 this.initialX = e.clientX - this.xOffset;
1437 this.initialY = e.clientY - this.yOffset;
1438 }
1439
1440 if (e.target === this.img) {
1441 this.active = true;
1442 this.img.classList.add('dragging');
1443 }
1444 }
1445 }, {
1446 key: "dragEnd",
1447 value: function dragEnd(e) {
1448 var _this2 = this;
1449
1450 e.preventDefault();
1451 this.initialX = this.currentX;
1452 this.initialY = this.currentY;
1453 this.active = false;
1454 setTimeout(function () {
1455 _this2.dragging = false;
1456 _this2.img.isDragging = false;
1457
1458 _this2.img.classList.remove('dragging');
1459 }, 100);
1460 }
1461 }, {
1462 key: "drag",
1463 value: function drag(e) {
1464 if (this.active) {
1465 e.preventDefault();
1466
1467 if (e.type === 'touchmove') {
1468 this.currentX = e.touches[0].clientX - this.initialX;
1469 this.currentY = e.touches[0].clientY - this.initialY;
1470 } else {
1471 this.currentX = e.clientX - this.initialX;
1472 this.currentY = e.clientY - this.initialY;
1473 }
1474
1475 this.xOffset = this.currentX;
1476 this.yOffset = this.currentY;
1477 this.img.isDragging = true;
1478 this.dragging = true;
1479 this.setTranslate(this.img, this.currentX, this.currentY);
1480 }
1481 }
1482 }, {
1483 key: "onMove",
1484 value: function onMove(e) {
1485 if (!this.zoomedIn) {
1486 return;
1487 }
1488
1489 var xOffset = e.clientX - this.img.naturalWidth / 2;
1490 var yOffset = e.clientY - this.img.naturalHeight / 2;
1491 this.setTranslate(this.img, xOffset, yOffset);
1492 }
1493 }, {
1494 key: "setTranslate",
1495 value: function setTranslate(node, xPos, yPos) {
1496 node.style.transform = 'translate3d(' + xPos + 'px, ' + yPos + 'px, 0)';
1497 }
1498 }, {
1499 key: "widowWidth",
1500 value: function widowWidth() {
1501 return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
1502 }
1503 }]);
1504
1505 return ZoomImages;
1506 }();
1507
1508 var DragSlides = function () {
1509 function DragSlides() {
1510 var _this = this;
1511
1512 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1513
1514 _classCallCheck(this, DragSlides);
1515
1516 var dragEl = config.dragEl,
1517 _config$toleranceX = config.toleranceX,
1518 toleranceX = _config$toleranceX === void 0 ? 40 : _config$toleranceX,
1519 _config$toleranceY = config.toleranceY,
1520 toleranceY = _config$toleranceY === void 0 ? 65 : _config$toleranceY,
1521 _config$slide = config.slide,
1522 slide = _config$slide === void 0 ? null : _config$slide,
1523 _config$instance = config.instance,
1524 instance = _config$instance === void 0 ? null : _config$instance;
1525 this.el = dragEl;
1526 this.active = false;
1527 this.dragging = false;
1528 this.currentX = null;
1529 this.currentY = null;
1530 this.initialX = null;
1531 this.initialY = null;
1532 this.xOffset = 0;
1533 this.yOffset = 0;
1534 this.direction = null;
1535 this.lastDirection = null;
1536 this.toleranceX = toleranceX;
1537 this.toleranceY = toleranceY;
1538 this.toleranceReached = false;
1539 this.dragContainer = this.el;
1540 this.slide = slide;
1541 this.instance = instance;
1542 this.el.addEventListener('mousedown', function (e) {
1543 return _this.dragStart(e);
1544 }, false);
1545 this.el.addEventListener('mouseup', function (e) {
1546 return _this.dragEnd(e);
1547 }, false);
1548 this.el.addEventListener('mousemove', function (e) {
1549 return _this.drag(e);
1550 }, false);
1551 }
1552
1553 _createClass(DragSlides, [{
1554 key: "dragStart",
1555 value: function dragStart(e) {
1556 if (this.slide.classList.contains('zoomed')) {
1557 this.active = false;
1558 return;
1559 }
1560
1561 if (e.type === 'touchstart') {
1562 this.initialX = e.touches[0].clientX - this.xOffset;
1563 this.initialY = e.touches[0].clientY - this.yOffset;
1564 } else {
1565 this.initialX = e.clientX - this.xOffset;
1566 this.initialY = e.clientY - this.yOffset;
1567 }
1568
1569 var clicked = e.target.nodeName.toLowerCase();
1570 var exludeClicks = ['input', 'select', 'textarea', 'button', 'a'];
1571
1572 if (e.target.classList.contains('nodrag') || closest(e.target, '.nodrag') || exludeClicks.indexOf(clicked) !== -1) {
1573 this.active = false;
1574 return;
1575 }
1576
1577 e.preventDefault();
1578
1579 if (e.target === this.el || clicked !== 'img' && closest(e.target, '.gslide-inline')) {
1580 this.active = true;
1581 this.el.classList.add('dragging');
1582 this.dragContainer = closest(e.target, '.ginner-container');
1583 }
1584 }
1585 }, {
1586 key: "dragEnd",
1587 value: function dragEnd(e) {
1588 var _this2 = this;
1589
1590 e && e.preventDefault();
1591 this.initialX = 0;
1592 this.initialY = 0;
1593 this.currentX = null;
1594 this.currentY = null;
1595 this.initialX = null;
1596 this.initialY = null;
1597 this.xOffset = 0;
1598 this.yOffset = 0;
1599 this.active = false;
1600
1601 if (this.doSlideChange) {
1602 this.instance.preventOutsideClick = true;
1603 this.doSlideChange == 'right' && this.instance.prevSlide();
1604 this.doSlideChange == 'left' && this.instance.nextSlide();
1605 }
1606
1607 if (this.doSlideClose) {
1608 this.instance.close();
1609 }
1610
1611 if (!this.toleranceReached) {
1612 this.setTranslate(this.dragContainer, 0, 0, true);
1613 }
1614
1615 setTimeout(function () {
1616 _this2.instance.preventOutsideClick = false;
1617 _this2.toleranceReached = false;
1618 _this2.lastDirection = null;
1619 _this2.dragging = false;
1620 _this2.el.isDragging = false;
1621
1622 _this2.el.classList.remove('dragging');
1623
1624 _this2.slide.classList.remove('dragging-nav');
1625
1626 _this2.dragContainer.style.transform = '';
1627 _this2.dragContainer.style.transition = '';
1628 }, 100);
1629 }
1630 }, {
1631 key: "drag",
1632 value: function drag(e) {
1633 if (this.active) {
1634 e.preventDefault();
1635 this.slide.classList.add('dragging-nav');
1636
1637 if (e.type === 'touchmove') {
1638 this.currentX = e.touches[0].clientX - this.initialX;
1639 this.currentY = e.touches[0].clientY - this.initialY;
1640 } else {
1641 this.currentX = e.clientX - this.initialX;
1642 this.currentY = e.clientY - this.initialY;
1643 }
1644
1645 this.xOffset = this.currentX;
1646 this.yOffset = this.currentY;
1647 this.el.isDragging = true;
1648 this.dragging = true;
1649 this.doSlideChange = false;
1650 this.doSlideClose = false;
1651 var currentXInt = Math.abs(this.currentX);
1652 var currentYInt = Math.abs(this.currentY);
1653
1654 if (currentXInt > 0 && currentXInt >= Math.abs(this.currentY) && (!this.lastDirection || this.lastDirection == 'x')) {
1655 this.yOffset = 0;
1656 this.lastDirection = 'x';
1657 this.setTranslate(this.dragContainer, this.currentX, 0);
1658 var doChange = this.shouldChange();
1659
1660 if (!this.instance.settings.dragAutoSnap && doChange) {
1661 this.doSlideChange = doChange;
1662 }
1663
1664 if (this.instance.settings.dragAutoSnap && doChange) {
1665 this.instance.preventOutsideClick = true;
1666 this.toleranceReached = true;
1667 this.active = false;
1668 this.instance.preventOutsideClick = true;
1669 this.dragEnd(null);
1670 doChange == 'right' && this.instance.prevSlide();
1671 doChange == 'left' && this.instance.nextSlide();
1672 return;
1673 }
1674 }
1675
1676 if (this.toleranceY > 0 && currentYInt > 0 && currentYInt >= currentXInt && (!this.lastDirection || this.lastDirection == 'y')) {
1677 this.xOffset = 0;
1678 this.lastDirection = 'y';
1679 this.setTranslate(this.dragContainer, 0, this.currentY);
1680 var doClose = this.shouldClose();
1681
1682 if (!this.instance.settings.dragAutoSnap && doClose) {
1683 this.doSlideClose = true;
1684 }
1685
1686 if (this.instance.settings.dragAutoSnap && doClose) {
1687 this.instance.close();
1688 }
1689
1690 return;
1691 }
1692 }
1693 }
1694 }, {
1695 key: "shouldChange",
1696 value: function shouldChange() {
1697 var doChange = false;
1698 var currentXInt = Math.abs(this.currentX);
1699
1700 if (currentXInt >= this.toleranceX) {
1701 var dragDir = this.currentX > 0 ? 'right' : 'left';
1702
1703 if (dragDir == 'left' && this.slide !== this.slide.parentNode.lastChild || dragDir == 'right' && this.slide !== this.slide.parentNode.firstChild) {
1704 doChange = dragDir;
1705 }
1706 }
1707
1708 return doChange;
1709 }
1710 }, {
1711 key: "shouldClose",
1712 value: function shouldClose() {
1713 var doClose = false;
1714 var currentYInt = Math.abs(this.currentY);
1715
1716 if (currentYInt >= this.toleranceY) {
1717 doClose = true;
1718 }
1719
1720 return doClose;
1721 }
1722 }, {
1723 key: "setTranslate",
1724 value: function setTranslate(node, xPos, yPos) {
1725 var animated = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1726
1727 if (animated) {
1728 node.style.transition = 'all .2s ease';
1729 } else {
1730 node.style.transition = '';
1731 }
1732
1733 node.style.transform = "translate3d(".concat(xPos, "px, ").concat(yPos, "px, 0)");
1734 }
1735 }]);
1736
1737 return DragSlides;
1738 }();
1739
1740 function slideImage(slide, data, index, callback) {
1741 var slideMedia = slide.querySelector('.gslide-media');
1742 var img = new Image();
1743 var titleID = 'gSlideTitle_' + index;
1744 var textID = 'gSlideDesc_' + index;
1745 img.addEventListener('load', function () {
1746 if (isFunction(callback)) {
1747 callback();
1748 }
1749 }, false);
1750 img.src = data.href;
1751
1752 if (data.sizes != '' && data.srcset != '') {
1753 img.sizes = data.sizes;
1754 img.srcset = data.srcset;
1755 }
1756
1757 img.alt = '';
1758
1759 if (!isNil(data.alt) && data.alt !== '') {
1760 img.alt = data.alt;
1761 }
1762
1763 if (data.title !== '') {
1764 img.setAttribute('aria-labelledby', titleID);
1765 }
1766
1767 if (data.description !== '') {
1768 img.setAttribute('aria-describedby', textID);
1769 }
1770
1771 if (data.hasOwnProperty('_hasCustomWidth') && data._hasCustomWidth) {
1772 img.style.width = data.width;
1773 }
1774
1775 if (data.hasOwnProperty('_hasCustomHeight') && data._hasCustomHeight) {
1776 img.style.height = data.height;
1777 }
1778
1779 slideMedia.insertBefore(img, slideMedia.firstChild);
1780 return;
1781 }
1782
1783 function slideVideo(slide, data, index, callback) {
1784 var _this = this;
1785
1786 var slideContainer = slide.querySelector('.ginner-container');
1787 var videoID = 'gvideo' + index;
1788 var slideMedia = slide.querySelector('.gslide-media');
1789 var videoPlayers = this.getAllPlayers();
1790 addClass(slideContainer, 'gvideo-container');
1791 slideMedia.insertBefore(createHTML('<div class="gvideo-wrapper"></div>'), slideMedia.firstChild);
1792 var videoWrapper = slide.querySelector('.gvideo-wrapper');
1793 injectAssets(this.settings.plyr.css, 'Plyr');
1794 var url = data.href;
1795 var provider = data === null || data === void 0 ? void 0 : data.videoProvider;
1796 var customPlaceholder = false;
1797 slideMedia.style.maxWidth = data.width;
1798 injectAssets(this.settings.plyr.js, 'Plyr', function () {
1799 if (!provider && url.match(/vimeo\.com\/([0-9]*)/)) {
1800 provider = 'vimeo';
1801 } else if (!provider && (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/))) {
1802 provider = 'youtube';
1803 } else {
1804 provider = 'local';
1805 var html = '<video id="' + videoID + '" ';
1806 html += "style=\"background:#000; max-width: ".concat(data.width, ";\" ");
1807 html += 'preload="metadata" ';
1808 html += 'x-webkit-airplay="allow" ';
1809 html += 'playsinline ';
1810 html += 'controls ';
1811 html += 'class="gvideo-local">';
1812 html += "<source src=\"".concat(url, "\">");
1813 html += '</video>';
1814 customPlaceholder = createHTML(html);
1815 }
1816
1817 var placeholder = customPlaceholder ? customPlaceholder : createHTML("<div id=\"".concat(videoID, "\" data-plyr-provider=\"").concat(provider, "\" data-plyr-embed-id=\"").concat(url, "\"></div>"));
1818 addClass(videoWrapper, "".concat(provider, "-video gvideo"));
1819 videoWrapper.appendChild(placeholder);
1820 videoWrapper.setAttribute('data-id', videoID);
1821 videoWrapper.setAttribute('data-index', index);
1822 var playerConfig = has(_this.settings.plyr, 'config') ? _this.settings.plyr.config : {};
1823 var player = new Plyr('#' + videoID, playerConfig);
1824 player.on('ready', function (event) {
1825 videoPlayers[videoID] = event.detail.plyr;
1826
1827 if (isFunction(callback)) {
1828 callback();
1829 }
1830 });
1831 waitUntil(function () {
1832 return slide.querySelector('iframe') && slide.querySelector('iframe').dataset.ready == 'true';
1833 }, function () {
1834 _this.resize(slide);
1835 });
1836 player.on('enterfullscreen', handleMediaFullScreen);
1837 player.on('exitfullscreen', handleMediaFullScreen);
1838 });
1839 }
1840
1841 function handleMediaFullScreen(event) {
1842 var media = closest(event.target, '.gslide-media');
1843
1844 if (event.type === 'enterfullscreen') {
1845 addClass(media, 'fullscreen');
1846 }
1847
1848 if (event.type === 'exitfullscreen') {
1849 removeClass(media, 'fullscreen');
1850 }
1851 }
1852
1853 function slideInline(slide, data, index, callback) {
1854 var _this = this;
1855
1856 var slideMedia = slide.querySelector('.gslide-media');
1857 var hash = has(data, 'href') && data.href ? data.href.split('#').pop().trim() : false;
1858 var content = has(data, 'content') && data.content ? data.content : false;
1859 var innerContent;
1860
1861 if (content) {
1862 if (isString(content)) {
1863 innerContent = createHTML("<div class=\"ginlined-content\">".concat(content, "</div>"));
1864 }
1865
1866 if (isNode(content)) {
1867 if (content.style.display == 'none') {
1868 content.style.display = 'block';
1869 }
1870
1871 var container = document.createElement('div');
1872 container.className = 'ginlined-content';
1873 container.appendChild(content);
1874 innerContent = container;
1875 }
1876 }
1877
1878 if (hash) {
1879 var div = document.getElementById(hash);
1880
1881 if (!div) {
1882 return false;
1883 }
1884
1885 var cloned = div.cloneNode(true);
1886 cloned.style.height = data.height;
1887 cloned.style.maxWidth = data.width;
1888 addClass(cloned, 'ginlined-content');
1889 innerContent = cloned;
1890 }
1891
1892 if (!innerContent) {
1893 console.error('Unable to append inline slide content', data);
1894 return false;
1895 }
1896
1897 slideMedia.style.height = data.height;
1898 slideMedia.style.width = data.width;
1899 slideMedia.appendChild(innerContent);
1900 this.events['inlineclose' + hash] = addEvent('click', {
1901 onElement: slideMedia.querySelectorAll('.gtrigger-close'),
1902 withCallback: function withCallback(e) {
1903 e.preventDefault();
1904
1905 _this.close();
1906 }
1907 });
1908
1909 if (isFunction(callback)) {
1910 callback();
1911 }
1912
1913 return;
1914 }
1915
1916 function slideIframe(slide, data, index, callback) {
1917 var slideMedia = slide.querySelector('.gslide-media');
1918 var iframe = createIframe({
1919 url: data.href,
1920 callback: callback
1921 });
1922 slideMedia.parentNode.style.maxWidth = data.width;
1923 slideMedia.parentNode.style.height = data.height;
1924 slideMedia.appendChild(iframe);
1925 return;
1926 }
1927
1928 var SlideConfigParser = function () {
1929 function SlideConfigParser() {
1930 var slideParamas = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1931
1932 _classCallCheck(this, SlideConfigParser);
1933
1934 this.defaults = {
1935 href: '',
1936 sizes: '',
1937 srcset: '',
1938 title: '',
1939 type: '',
1940 videoProvider: '',
1941 description: '',
1942 alt: '',
1943 descPosition: 'bottom',
1944 effect: '',
1945 width: '',
1946 height: '',
1947 content: false,
1948 zoomable: true,
1949 draggable: true
1950 };
1951
1952 if (isObject(slideParamas)) {
1953 this.defaults = extend(this.defaults, slideParamas);
1954 }
1955 }
1956
1957 _createClass(SlideConfigParser, [{
1958 key: "sourceType",
1959 value: function sourceType(url) {
1960 var origin = url;
1961 url = url.toLowerCase();
1962
1963 if (url.match(/\.(jpeg|jpg|jpe|gif|png|apn|webp|avif|svg)/) !== null) {
1964 return 'image';
1965 }
1966
1967 if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/)) {
1968 return 'video';
1969 }
1970
1971 if (url.match(/vimeo\.com\/([0-9]*)/)) {
1972 return 'video';
1973 }
1974
1975 if (url.match(/\.(mp4|ogg|webm|mov)/) !== null) {
1976 return 'video';
1977 }
1978
1979 if (url.match(/\.(mp3|wav|wma|aac|ogg)/) !== null) {
1980 return 'audio';
1981 }
1982
1983 if (url.indexOf('#') > -1) {
1984 var hash = origin.split('#').pop();
1985
1986 if (hash.trim() !== '') {
1987 return 'inline';
1988 }
1989 }
1990
1991 if (url.indexOf('goajax=true') > -1) {
1992 return 'ajax';
1993 }
1994
1995 return 'external';
1996 }
1997 }, {
1998 key: "parseConfig",
1999 value: function parseConfig(element, settings) {
2000 var _this = this;
2001
2002 var data = extend({
2003 descPosition: settings.descPosition
2004 }, this.defaults);
2005
2006 if (isObject(element) && !isNode(element)) {
2007 if (!has(element, 'type')) {
2008 if (has(element, 'content') && element.content) {
2009 element.type = 'inline';
2010 } else if (has(element, 'href')) {
2011 element.type = this.sourceType(element.href);
2012 }
2013 }
2014
2015 var objectData = extend(data, element);
2016 this.setSize(objectData, settings);
2017 return objectData;
2018 }
2019
2020 var url = '';
2021 var config = element.getAttribute('data-glightbox');
2022 var nodeType = element.nodeName.toLowerCase();
2023
2024 if (nodeType === 'a') {
2025 url = element.href;
2026 }
2027
2028 if (nodeType === 'img') {
2029 url = element.src;
2030 data.alt = element.alt;
2031 }
2032
2033 data.href = url;
2034 each(data, function (val, key) {
2035 if (has(settings, key) && key !== 'width') {
2036 data[key] = settings[key];
2037 }
2038
2039 var nodeData = element.dataset[key];
2040
2041 if (!isNil(nodeData)) {
2042 data[key] = _this.sanitizeValue(nodeData);
2043 }
2044 });
2045
2046 if (data.content) {
2047 data.type = 'inline';
2048 }
2049
2050 if (!data.type && url) {
2051 data.type = this.sourceType(url);
2052 }
2053
2054 if (!isNil(config)) {
2055 var cleanKeys = [];
2056 each(data, function (v, k) {
2057 cleanKeys.push(';\\s?' + k);
2058 });
2059 cleanKeys = cleanKeys.join('\\s?:|');
2060
2061 if (config.trim() !== '') {
2062 each(data, function (val, key) {
2063 var str = config;
2064 var match = 's?' + key + 's?:s?(.*?)(' + cleanKeys + 's?:|$)';
2065 var regex = new RegExp(match);
2066 var matches = str.match(regex);
2067
2068 if (matches && matches.length && matches[1]) {
2069 var value = matches[1].trim().replace(/;\s*$/, '');
2070 data[key] = _this.sanitizeValue(value);
2071 }
2072 });
2073 }
2074 } else {
2075 if (!data.title && nodeType == 'a') {
2076 var title = element.title;
2077
2078 if (!isNil(title) && title !== '') {
2079 data.title = title;
2080 }
2081 }
2082
2083 if (!data.title && nodeType == 'img') {
2084 var alt = element.alt;
2085
2086 if (!isNil(alt) && alt !== '') {
2087 data.title = alt;
2088 }
2089 }
2090 }
2091
2092 if (data.description && data.description.substring(0, 1) === '.') {
2093 var description;
2094
2095 try {
2096 description = document.querySelector(data.description).innerHTML;
2097 } catch (error) {
2098 if (!(error instanceof DOMException)) {
2099 throw error;
2100 }
2101 }
2102
2103 if (description) {
2104 data.description = description;
2105 }
2106 }
2107
2108 if (!data.description) {
2109 var nodeDesc = element.querySelector('.glightbox-desc');
2110
2111 if (nodeDesc) {
2112 data.description = nodeDesc.innerHTML;
2113 }
2114 }
2115
2116 this.setSize(data, settings, element);
2117 this.slideConfig = data;
2118 return data;
2119 }
2120 }, {
2121 key: "setSize",
2122 value: function setSize(data, settings) {
2123 var element = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2124 var defaultWith = data.type == 'video' ? this.checkSize(settings.videosWidth) : this.checkSize(settings.width);
2125 var defaultHeight = this.checkSize(settings.height);
2126 data.width = has(data, 'width') && data.width !== '' ? this.checkSize(data.width) : defaultWith;
2127 data.height = has(data, 'height') && data.height !== '' ? this.checkSize(data.height) : defaultHeight;
2128
2129 if (element && data.type == 'image') {
2130 data._hasCustomWidth = element.dataset.width ? true : false;
2131 data._hasCustomHeight = element.dataset.height ? true : false;
2132 }
2133
2134 return data;
2135 }
2136 }, {
2137 key: "checkSize",
2138 value: function checkSize(size) {
2139 return isNumber(size) ? "".concat(size, "px") : size;
2140 }
2141 }, {
2142 key: "sanitizeValue",
2143 value: function sanitizeValue(val) {
2144 if (val !== 'true' && val !== 'false') {
2145 return val;
2146 }
2147
2148 return val === 'true';
2149 }
2150 }]);
2151
2152 return SlideConfigParser;
2153 }();
2154
2155 var Slide = function () {
2156 function Slide(el, instance, index) {
2157 _classCallCheck(this, Slide);
2158
2159 this.element = el;
2160 this.instance = instance;
2161 this.index = index;
2162 }
2163
2164 _createClass(Slide, [{
2165 key: "setContent",
2166 value: function setContent() {
2167 var _this = this;
2168
2169 var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2170 var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2171
2172 if (hasClass(slide, 'loaded')) {
2173 return false;
2174 }
2175
2176 var settings = this.instance.settings;
2177 var slideConfig = this.slideConfig;
2178 var isMobileDevice = isMobile();
2179
2180 if (isFunction(settings.beforeSlideLoad)) {
2181 settings.beforeSlideLoad({
2182 index: this.index,
2183 slide: slide,
2184 player: false
2185 });
2186 }
2187
2188 var type = slideConfig.type;
2189 var position = slideConfig.descPosition;
2190 var slideMedia = slide.querySelector('.gslide-media');
2191 var slideTitle = slide.querySelector('.gslide-title');
2192 var slideText = slide.querySelector('.gslide-desc');
2193 var slideDesc = slide.querySelector('.gdesc-inner');
2194 var finalCallback = callback;
2195 var titleID = 'gSlideTitle_' + this.index;
2196 var textID = 'gSlideDesc_' + this.index;
2197
2198 if (isFunction(settings.afterSlideLoad)) {
2199 finalCallback = function finalCallback() {
2200 if (isFunction(callback)) {
2201 callback();
2202 }
2203
2204 settings.afterSlideLoad({
2205 index: _this.index,
2206 slide: slide,
2207 player: _this.instance.getSlidePlayerInstance(_this.index)
2208 });
2209 };
2210 }
2211
2212 if (slideConfig.title == '' && slideConfig.description == '') {
2213 if (slideDesc) {
2214 slideDesc.parentNode.parentNode.removeChild(slideDesc.parentNode);
2215 }
2216 } else {
2217 if (slideTitle && slideConfig.title !== '') {
2218 slideTitle.id = titleID;
2219 slideTitle.innerHTML = slideConfig.title;
2220 } else {
2221 slideTitle.parentNode.removeChild(slideTitle);
2222 }
2223
2224 if (slideText && slideConfig.description !== '') {
2225 slideText.id = textID;
2226
2227 if (isMobileDevice && settings.moreLength > 0) {
2228 slideConfig.smallDescription = this.slideShortDesc(slideConfig.description, settings.moreLength, settings.moreText);
2229 slideText.innerHTML = slideConfig.smallDescription;
2230 this.descriptionEvents(slideText, slideConfig);
2231 } else {
2232 slideText.innerHTML = slideConfig.description;
2233 }
2234 } else {
2235 slideText.parentNode.removeChild(slideText);
2236 }
2237
2238 addClass(slideMedia.parentNode, "desc-".concat(position));
2239 addClass(slideDesc.parentNode, "description-".concat(position));
2240 }
2241
2242 addClass(slideMedia, "gslide-".concat(type));
2243 addClass(slide, 'loaded');
2244
2245 if (type === 'video') {
2246 slideVideo.apply(this.instance, [slide, slideConfig, this.index, finalCallback]);
2247 return;
2248 }
2249
2250 if (type === 'external') {
2251 slideIframe.apply(this, [slide, slideConfig, this.index, finalCallback]);
2252 return;
2253 }
2254
2255 if (type === 'inline') {
2256 slideInline.apply(this.instance, [slide, slideConfig, this.index, finalCallback]);
2257
2258 if (slideConfig.draggable) {
2259 new DragSlides({
2260 dragEl: slide.querySelector('.gslide-inline'),
2261 toleranceX: settings.dragToleranceX,
2262 toleranceY: settings.dragToleranceY,
2263 slide: slide,
2264 instance: this.instance
2265 });
2266 }
2267
2268 return;
2269 }
2270
2271 if (type === 'image') {
2272 slideImage(slide, slideConfig, this.index, function () {
2273 var img = slide.querySelector('img');
2274
2275 if (slideConfig.draggable) {
2276 new DragSlides({
2277 dragEl: img,
2278 toleranceX: settings.dragToleranceX,
2279 toleranceY: settings.dragToleranceY,
2280 slide: slide,
2281 instance: _this.instance
2282 });
2283 }
2284
2285 if (slideConfig.zoomable && img.naturalWidth > img.offsetWidth) {
2286 addClass(img, 'zoomable');
2287 new ZoomImages(img, slide, function () {
2288 _this.instance.resize();
2289 });
2290 }
2291
2292 if (isFunction(finalCallback)) {
2293 finalCallback();
2294 }
2295 });
2296 return;
2297 }
2298
2299 if (isFunction(finalCallback)) {
2300 finalCallback();
2301 }
2302 }
2303 }, {
2304 key: "slideShortDesc",
2305 value: function slideShortDesc(string) {
2306 var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
2307 var wordBoundary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2308 var div = document.createElement('div');
2309 div.innerHTML = string;
2310 var cleanedString = div.innerText;
2311 var useWordBoundary = wordBoundary;
2312 string = cleanedString.trim();
2313
2314 if (string.length <= n) {
2315 return string;
2316 }
2317
2318 var subString = string.substr(0, n - 1);
2319
2320 if (!useWordBoundary) {
2321 return subString;
2322 }
2323
2324 div = null;
2325 return subString + '... <a href="#" class="desc-more">' + wordBoundary + '</a>';
2326 }
2327 }, {
2328 key: "descriptionEvents",
2329 value: function descriptionEvents(desc, data) {
2330 var _this2 = this;
2331
2332 var moreLink = desc.querySelector('.desc-more');
2333
2334 if (!moreLink) {
2335 return false;
2336 }
2337
2338 addEvent('click', {
2339 onElement: moreLink,
2340 withCallback: function withCallback(event, target) {
2341 event.preventDefault();
2342 var body = document.body;
2343 var desc = closest(target, '.gslide-desc');
2344
2345 if (!desc) {
2346 return false;
2347 }
2348
2349 desc.innerHTML = data.description;
2350 addClass(body, 'gdesc-open');
2351 var shortEvent = addEvent('click', {
2352 onElement: [body, closest(desc, '.gslide-description')],
2353 withCallback: function withCallback(event, target) {
2354 if (event.target.nodeName.toLowerCase() !== 'a') {
2355 removeClass(body, 'gdesc-open');
2356 addClass(body, 'gdesc-closed');
2357 desc.innerHTML = data.smallDescription;
2358
2359 _this2.descriptionEvents(desc, data);
2360
2361 setTimeout(function () {
2362 removeClass(body, 'gdesc-closed');
2363 }, 400);
2364 shortEvent.destroy();
2365 }
2366 }
2367 });
2368 }
2369 });
2370 }
2371 }, {
2372 key: "create",
2373 value: function create() {
2374 return createHTML(this.instance.settings.slideHTML);
2375 }
2376 }, {
2377 key: "getConfig",
2378 value: function getConfig() {
2379 if (!isNode(this.element) && !this.element.hasOwnProperty('draggable')) {
2380 this.element.draggable = this.instance.settings.draggable;
2381 }
2382
2383 var parser = new SlideConfigParser(this.instance.settings.slideExtraAttributes);
2384 this.slideConfig = parser.parseConfig(this.element, this.instance.settings);
2385 return this.slideConfig;
2386 }
2387 }]);
2388
2389 return Slide;
2390 }();
2391
2392 var _version = '3.1.0';
2393
2394 var isMobile$1 = isMobile();
2395
2396 var isTouch$1 = isTouch();
2397
2398 var html = document.getElementsByTagName('html')[0];
2399 var defaults = {
2400 selector: '.glightbox',
2401 elements: null,
2402 skin: 'clean',
2403 theme: 'clean',
2404 closeButton: true,
2405 startAt: null,
2406 autoplayVideos: true,
2407 autofocusVideos: true,
2408 descPosition: 'bottom',
2409 width: '900px',
2410 height: '506px',
2411 videosWidth: '960px',
2412 beforeSlideChange: null,
2413 afterSlideChange: null,
2414 beforeSlideLoad: null,
2415 afterSlideLoad: null,
2416 slideInserted: null,
2417 slideRemoved: null,
2418 slideExtraAttributes: null,
2419 onOpen: null,
2420 onClose: null,
2421 loop: false,
2422 zoomable: true,
2423 draggable: true,
2424 dragAutoSnap: false,
2425 dragToleranceX: 40,
2426 dragToleranceY: 65,
2427 preload: true,
2428 oneSlidePerOpen: false,
2429 touchNavigation: true,
2430 touchFollowAxis: true,
2431 keyboardNavigation: true,
2432 closeOnOutsideClick: true,
2433 plugins: false,
2434 plyr: {
2435 css: 'https://cdn.plyr.io/3.6.12/plyr.css',
2436 js: 'https://cdn.plyr.io/3.6.12/plyr.js',
2437 config: {
2438 ratio: '16:9',
2439 fullscreen: {
2440 enabled: true,
2441 iosNative: true
2442 },
2443 youtube: {
2444 noCookie: true,
2445 rel: 0,
2446 showinfo: 0,
2447 iv_load_policy: 3
2448 },
2449 vimeo: {
2450 byline: false,
2451 portrait: false,
2452 title: false,
2453 transparent: false
2454 }
2455 }
2456 },
2457 openEffect: 'zoom',
2458 closeEffect: 'zoom',
2459 slideEffect: 'slide',
2460 moreText: 'See more',
2461 moreLength: 60,
2462 cssEfects: {
2463 fade: {
2464 "in": 'fadeIn',
2465 out: 'fadeOut'
2466 },
2467 zoom: {
2468 "in": 'zoomIn',
2469 out: 'zoomOut'
2470 },
2471 slide: {
2472 "in": 'slideInRight',
2473 out: 'slideOutLeft'
2474 },
2475 slideBack: {
2476 "in": 'slideInLeft',
2477 out: 'slideOutRight'
2478 },
2479 none: {
2480 "in": 'none',
2481 out: 'none'
2482 }
2483 },
2484 svg: {
2485 close: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"><g><g><path d="M505.943,6.058c-8.077-8.077-21.172-8.077-29.249,0L6.058,476.693c-8.077,8.077-8.077,21.172,0,29.249C10.096,509.982,15.39,512,20.683,512c5.293,0,10.586-2.019,14.625-6.059L505.943,35.306C514.019,27.23,514.019,14.135,505.943,6.058z"/></g></g><g><g><path d="M505.942,476.694L35.306,6.059c-8.076-8.077-21.172-8.077-29.248,0c-8.077,8.076-8.077,21.171,0,29.248l470.636,470.636c4.038,4.039,9.332,6.058,14.625,6.058c5.293,0,10.587-2.019,14.624-6.057C514.018,497.866,514.018,484.771,505.942,476.694z"/></g></g></svg>',
2486 next: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"> <g><path d="M360.731,229.075l-225.1-225.1c-5.3-5.3-13.8-5.3-19.1,0s-5.3,13.8,0,19.1l215.5,215.5l-215.5,215.5c-5.3,5.3-5.3,13.8,0,19.1c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-4l225.1-225.1C365.931,242.875,365.931,234.275,360.731,229.075z"/></g></svg>',
2487 prev: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"><g><path d="M145.188,238.575l215.5-215.5c5.3-5.3,5.3-13.8,0-19.1s-13.8-5.3-19.1,0l-225.1,225.1c-5.3,5.3-5.3,13.8,0,19.1l225.1,225c2.6,2.6,6.1,4,9.5,4s6.9-1.3,9.5-4c5.3-5.3,5.3-13.8,0-19.1L145.188,238.575z"/></g></svg>'
2488 }
2489 };
2490 defaults.slideHTML = "<div class=\"gslide\">\n <div class=\"gslide-inner-content\">\n <div class=\"ginner-container\">\n <div class=\"gslide-media\">\n </div>\n <div class=\"gslide-description\">\n <div class=\"gdesc-inner\">\n <h4 class=\"gslide-title\"></h4>\n <div class=\"gslide-desc\"></div>\n </div>\n </div>\n </div>\n </div>\n</div>";
2491 defaults.lightboxHTML = "<div id=\"glightbox-body\" class=\"glightbox-container\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"false\">\n <div class=\"gloader visible\"></div>\n <div class=\"goverlay\"></div>\n <div class=\"gcontainer\">\n <div id=\"glightbox-slider\" class=\"gslider\"></div>\n <button class=\"gclose gbtn\" aria-label=\"Close\" data-taborder=\"3\">{closeSVG}</button>\n <button class=\"gprev gbtn\" aria-label=\"Previous\" data-taborder=\"2\">{prevSVG}</button>\n <button class=\"gnext gbtn\" aria-label=\"Next\" data-taborder=\"1\">{nextSVG}</button>\n</div>\n</div>";
2492
2493 var GlightboxInit = function () {
2494 function GlightboxInit() {
2495 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2496
2497 _classCallCheck(this, GlightboxInit);
2498
2499 this.customOptions = options;
2500 this.settings = extend(defaults, options);
2501 this.effectsClasses = this.getAnimationClasses();
2502 this.videoPlayers = {};
2503 this.apiEvents = [];
2504 this.fullElementsList = false;
2505 }
2506
2507 _createClass(GlightboxInit, [{
2508 key: "init",
2509 value: function init() {
2510 var _this = this;
2511
2512 var selector = this.getSelector();
2513
2514 if (selector) {
2515 this.baseEvents = addEvent('click', {
2516 onElement: selector,
2517 withCallback: function withCallback(e, target) {
2518 e.preventDefault();
2519
2520 _this.open(target);
2521 }
2522 });
2523 }
2524
2525 this.elements = this.getElements();
2526 }
2527 }, {
2528 key: "open",
2529 value: function open() {
2530 var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2531 var startAt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2532
2533 if (this.elements.length === 0) {
2534 return false;
2535 }
2536
2537 this.activeSlide = null;
2538 this.prevActiveSlideIndex = null;
2539 this.prevActiveSlide = null;
2540 var index = isNumber(startAt) ? startAt : this.settings.startAt;
2541
2542 if (isNode(element)) {
2543 var gallery = element.getAttribute('data-gallery');
2544
2545 if (gallery) {
2546 this.fullElementsList = this.elements;
2547 this.elements = this.getGalleryElements(this.elements, gallery);
2548 }
2549
2550 if (isNil(index)) {
2551 index = this.getElementIndex(element);
2552
2553 if (index < 0) {
2554 index = 0;
2555 }
2556 }
2557 }
2558
2559 if (!isNumber(index)) {
2560 index = 0;
2561 }
2562
2563 this.build();
2564
2565 animateElement(this.overlay, this.settings.openEffect === 'none' ? 'none' : this.settings.cssEfects.fade["in"]);
2566
2567 var body = document.body;
2568 var scrollBar = window.innerWidth - document.documentElement.clientWidth;
2569
2570 if (scrollBar > 0) {
2571 var styleSheet = document.createElement('style');
2572 styleSheet.type = 'text/css';
2573 styleSheet.className = 'gcss-styles';
2574 styleSheet.innerText = ".gscrollbar-fixer {margin-right: ".concat(scrollBar, "px}");
2575 document.head.appendChild(styleSheet);
2576
2577 addClass(body, 'gscrollbar-fixer');
2578 }
2579
2580 addClass(body, 'glightbox-open');
2581
2582 addClass(html, 'glightbox-open');
2583
2584 if (isMobile$1) {
2585 addClass(document.body, 'glightbox-mobile');
2586
2587 this.settings.slideEffect = 'slide';
2588 }
2589
2590 this.showSlide(index, true);
2591
2592 if (this.elements.length === 1) {
2593 addClass(this.prevButton, 'glightbox-button-hidden');
2594
2595 addClass(this.nextButton, 'glightbox-button-hidden');
2596 } else {
2597 removeClass(this.prevButton, 'glightbox-button-hidden');
2598
2599 removeClass(this.nextButton, 'glightbox-button-hidden');
2600 }
2601
2602 this.lightboxOpen = true;
2603 this.trigger('open');
2604
2605 if (isFunction(this.settings.onOpen)) {
2606 this.settings.onOpen();
2607 }
2608
2609 if (isTouch$1 && this.settings.touchNavigation) {
2610 touchNavigation(this);
2611 }
2612
2613 if (this.settings.keyboardNavigation) {
2614 keyboardNavigation(this);
2615 }
2616 }
2617 }, {
2618 key: "openAt",
2619 value: function openAt() {
2620 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2621 this.open(null, index);
2622 }
2623 }, {
2624 key: "showSlide",
2625 value: function showSlide() {
2626 var _this2 = this;
2627
2628 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2629 var first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2630
2631 show(this.loader);
2632
2633 this.index = parseInt(index);
2634 var current = this.slidesContainer.querySelector('.current');
2635
2636 if (current) {
2637 removeClass(current, 'current');
2638 }
2639
2640 this.slideAnimateOut();
2641 var slideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
2642
2643 if (hasClass(slideNode, 'loaded')) {
2644 this.slideAnimateIn(slideNode, first);
2645
2646 hide(this.loader);
2647 } else {
2648 show(this.loader);
2649
2650 var slide = this.elements[index];
2651 var slideData = {
2652 index: this.index,
2653 slide: slideNode,
2654 slideNode: slideNode,
2655 slideConfig: slide.slideConfig,
2656 slideIndex: this.index,
2657 trigger: slide.node,
2658 player: null
2659 };
2660 this.trigger('slide_before_load', slideData);
2661 slide.instance.setContent(slideNode, function () {
2662 hide(_this2.loader);
2663
2664 _this2.resize();
2665
2666 _this2.slideAnimateIn(slideNode, first);
2667
2668 _this2.trigger('slide_after_load', slideData);
2669 });
2670 }
2671
2672 this.slideDescription = slideNode.querySelector('.gslide-description');
2673 this.slideDescriptionContained = this.slideDescription && hasClass(this.slideDescription.parentNode, 'gslide-media');
2674
2675 if (this.settings.preload) {
2676 this.preloadSlide(index + 1);
2677 this.preloadSlide(index - 1);
2678 }
2679
2680 this.updateNavigationClasses();
2681 this.activeSlide = slideNode;
2682 }
2683 }, {
2684 key: "preloadSlide",
2685 value: function preloadSlide(index) {
2686 var _this3 = this;
2687
2688 if (index < 0 || index > this.elements.length - 1) {
2689 return false;
2690 }
2691
2692 if (isNil(this.elements[index])) {
2693 return false;
2694 }
2695
2696 var slideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
2697
2698 if (hasClass(slideNode, 'loaded')) {
2699 return false;
2700 }
2701
2702 var slide = this.elements[index];
2703 var type = slide.type;
2704 var slideData = {
2705 index: index,
2706 slide: slideNode,
2707 slideNode: slideNode,
2708 slideConfig: slide.slideConfig,
2709 slideIndex: index,
2710 trigger: slide.node,
2711 player: null
2712 };
2713 this.trigger('slide_before_load', slideData);
2714
2715 if (type === 'video' || type === 'external') {
2716 setTimeout(function () {
2717 slide.instance.setContent(slideNode, function () {
2718 _this3.trigger('slide_after_load', slideData);
2719 });
2720 }, 200);
2721 } else {
2722 slide.instance.setContent(slideNode, function () {
2723 _this3.trigger('slide_after_load', slideData);
2724 });
2725 }
2726 }
2727 }, {
2728 key: "prevSlide",
2729 value: function prevSlide() {
2730 this.goToSlide(this.index - 1);
2731 }
2732 }, {
2733 key: "nextSlide",
2734 value: function nextSlide() {
2735 this.goToSlide(this.index + 1);
2736 }
2737 }, {
2738 key: "goToSlide",
2739 value: function goToSlide() {
2740 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2741 this.prevActiveSlide = this.activeSlide;
2742 this.prevActiveSlideIndex = this.index;
2743
2744 if (!this.loop() && (index < 0 || index > this.elements.length - 1)) {
2745 return false;
2746 }
2747
2748 if (index < 0) {
2749 index = this.elements.length - 1;
2750 } else if (index >= this.elements.length) {
2751 index = 0;
2752 }
2753
2754 this.showSlide(index);
2755 }
2756 }, {
2757 key: "insertSlide",
2758 value: function insertSlide() {
2759 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2760 var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
2761
2762 if (index < 0) {
2763 index = this.elements.length;
2764 }
2765
2766 var slide = new Slide(config, this, index);
2767 var data = slide.getConfig();
2768
2769 var slideInfo = extend({}, data);
2770
2771 var newSlide = slide.create();
2772 var totalSlides = this.elements.length - 1;
2773 slideInfo.index = index;
2774 slideInfo.node = false;
2775 slideInfo.instance = slide;
2776 slideInfo.slideConfig = data;
2777 this.elements.splice(index, 0, slideInfo);
2778 var addedSlideNode = null;
2779 var addedSlidePlayer = null;
2780
2781 if (this.slidesContainer) {
2782 if (index > totalSlides) {
2783 this.slidesContainer.appendChild(newSlide);
2784 } else {
2785 var existingSlide = this.slidesContainer.querySelectorAll('.gslide')[index];
2786 this.slidesContainer.insertBefore(newSlide, existingSlide);
2787 }
2788
2789 if (this.settings.preload && this.index == 0 && index == 0 || this.index - 1 == index || this.index + 1 == index) {
2790 this.preloadSlide(index);
2791 }
2792
2793 if (this.index === 0 && index === 0) {
2794 this.index = 1;
2795 }
2796
2797 this.updateNavigationClasses();
2798 addedSlideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
2799 addedSlidePlayer = this.getSlidePlayerInstance(index);
2800 slideInfo.slideNode = addedSlideNode;
2801 }
2802
2803 this.trigger('slide_inserted', {
2804 index: index,
2805 slide: addedSlideNode,
2806 slideNode: addedSlideNode,
2807 slideConfig: data,
2808 slideIndex: index,
2809 trigger: null,
2810 player: addedSlidePlayer
2811 });
2812
2813 if (isFunction(this.settings.slideInserted)) {
2814 this.settings.slideInserted({
2815 index: index,
2816 slide: addedSlideNode,
2817 player: addedSlidePlayer
2818 });
2819 }
2820 }
2821 }, {
2822 key: "removeSlide",
2823 value: function removeSlide() {
2824 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
2825
2826 if (index < 0 || index > this.elements.length - 1) {
2827 return false;
2828 }
2829
2830 var slide = this.slidesContainer && this.slidesContainer.querySelectorAll('.gslide')[index];
2831
2832 if (slide) {
2833 if (this.getActiveSlideIndex() == index) {
2834 if (index == this.elements.length - 1) {
2835 this.prevSlide();
2836 } else {
2837 this.nextSlide();
2838 }
2839 }
2840
2841 slide.parentNode.removeChild(slide);
2842 }
2843
2844 this.elements.splice(index, 1);
2845 this.trigger('slide_removed', index);
2846
2847 if (isFunction(this.settings.slideRemoved)) {
2848 this.settings.slideRemoved(index);
2849 }
2850 }
2851 }, {
2852 key: "slideAnimateIn",
2853 value: function slideAnimateIn(slide, first) {
2854 var _this4 = this;
2855
2856 var slideMedia = slide.querySelector('.gslide-media');
2857 var slideDesc = slide.querySelector('.gslide-description');
2858 var prevData = {
2859 index: this.prevActiveSlideIndex,
2860 slide: this.prevActiveSlide,
2861 slideNode: this.prevActiveSlide,
2862 slideIndex: this.prevActiveSlide,
2863 slideConfig: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].slideConfig,
2864 trigger: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].node,
2865 player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
2866 };
2867 var nextData = {
2868 index: this.index,
2869 slide: this.activeSlide,
2870 slideNode: this.activeSlide,
2871 slideConfig: this.elements[this.index].slideConfig,
2872 slideIndex: this.index,
2873 trigger: this.elements[this.index].node,
2874 player: this.getSlidePlayerInstance(this.index)
2875 };
2876
2877 if (slideMedia.offsetWidth > 0 && slideDesc) {
2878 hide(slideDesc);
2879
2880 slideDesc.style.display = '';
2881 }
2882
2883 removeClass(slide, this.effectsClasses);
2884
2885 if (first) {
2886 animateElement(slide, this.settings.cssEfects[this.settings.openEffect]["in"], function () {
2887 if (_this4.settings.autoplayVideos) {
2888 _this4.slidePlayerPlay(slide);
2889 }
2890
2891 _this4.trigger('slide_changed', {
2892 prev: prevData,
2893 current: nextData
2894 });
2895
2896 if (isFunction(_this4.settings.afterSlideChange)) {
2897 _this4.settings.afterSlideChange.apply(_this4, [prevData, nextData]);
2898 }
2899 });
2900 } else {
2901 var effectName = this.settings.slideEffect;
2902 var animIn = effectName !== 'none' ? this.settings.cssEfects[effectName]["in"] : effectName;
2903
2904 if (this.prevActiveSlideIndex > this.index) {
2905 if (this.settings.slideEffect == 'slide') {
2906 animIn = this.settings.cssEfects.slideBack["in"];
2907 }
2908 }
2909
2910 animateElement(slide, animIn, function () {
2911 if (_this4.settings.autoplayVideos) {
2912 _this4.slidePlayerPlay(slide);
2913 }
2914
2915 _this4.trigger('slide_changed', {
2916 prev: prevData,
2917 current: nextData
2918 });
2919
2920 if (isFunction(_this4.settings.afterSlideChange)) {
2921 _this4.settings.afterSlideChange.apply(_this4, [prevData, nextData]);
2922 }
2923 });
2924 }
2925
2926 setTimeout(function () {
2927 _this4.resize(slide);
2928 }, 100);
2929
2930 addClass(slide, 'current');
2931 }
2932 }, {
2933 key: "slideAnimateOut",
2934 value: function slideAnimateOut() {
2935 if (!this.prevActiveSlide) {
2936 return false;
2937 }
2938
2939 var prevSlide = this.prevActiveSlide;
2940
2941 removeClass(prevSlide, this.effectsClasses);
2942
2943 addClass(prevSlide, 'prev');
2944
2945 var animation = this.settings.slideEffect;
2946 var animOut = animation !== 'none' ? this.settings.cssEfects[animation].out : animation;
2947 this.slidePlayerPause(prevSlide);
2948 this.trigger('slide_before_change', {
2949 prev: {
2950 index: this.prevActiveSlideIndex,
2951 slide: this.prevActiveSlide,
2952 slideNode: this.prevActiveSlide,
2953 slideIndex: this.prevActiveSlideIndex,
2954 slideConfig: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].slideConfig,
2955 trigger: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].node,
2956 player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
2957 },
2958 current: {
2959 index: this.index,
2960 slide: this.activeSlide,
2961 slideNode: this.activeSlide,
2962 slideIndex: this.index,
2963 slideConfig: this.elements[this.index].slideConfig,
2964 trigger: this.elements[this.index].node,
2965 player: this.getSlidePlayerInstance(this.index)
2966 }
2967 });
2968
2969 if (isFunction(this.settings.beforeSlideChange)) {
2970 this.settings.beforeSlideChange.apply(this, [{
2971 index: this.prevActiveSlideIndex,
2972 slide: this.prevActiveSlide,
2973 player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
2974 }, {
2975 index: this.index,
2976 slide: this.activeSlide,
2977 player: this.getSlidePlayerInstance(this.index)
2978 }]);
2979 }
2980
2981 if (this.prevActiveSlideIndex > this.index && this.settings.slideEffect == 'slide') {
2982 animOut = this.settings.cssEfects.slideBack.out;
2983 }
2984
2985 animateElement(prevSlide, animOut, function () {
2986 var container = prevSlide.querySelector('.ginner-container');
2987 var media = prevSlide.querySelector('.gslide-media');
2988 var desc = prevSlide.querySelector('.gslide-description');
2989 container.style.transform = '';
2990 media.style.transform = '';
2991
2992 removeClass(media, 'greset');
2993
2994 media.style.opacity = '';
2995
2996 if (desc) {
2997 desc.style.opacity = '';
2998 }
2999
3000 removeClass(prevSlide, 'prev');
3001 });
3002 }
3003 }, {
3004 key: "getAllPlayers",
3005 value: function getAllPlayers() {
3006 return this.videoPlayers;
3007 }
3008 }, {
3009 key: "getSlidePlayerInstance",
3010 value: function getSlidePlayerInstance(index) {
3011 var id = 'gvideo' + index;
3012 var videoPlayers = this.getAllPlayers();
3013
3014 if (has(videoPlayers, id) && videoPlayers[id]) {
3015 return videoPlayers[id];
3016 }
3017
3018 return false;
3019 }
3020 }, {
3021 key: "stopSlideVideo",
3022 value: function stopSlideVideo(slide) {
3023 if (isNode(slide)) {
3024 var node = slide.querySelector('.gvideo-wrapper');
3025
3026 if (node) {
3027 slide = node.getAttribute('data-index');
3028 }
3029 }
3030
3031 console.log('stopSlideVideo is deprecated, use slidePlayerPause');
3032 var player = this.getSlidePlayerInstance(slide);
3033
3034 if (player && player.playing) {
3035 player.pause();
3036 }
3037 }
3038 }, {
3039 key: "slidePlayerPause",
3040 value: function slidePlayerPause(slide) {
3041 if (isNode(slide)) {
3042 var node = slide.querySelector('.gvideo-wrapper');
3043
3044 if (node) {
3045 slide = node.getAttribute('data-index');
3046 }
3047 }
3048
3049 var player = this.getSlidePlayerInstance(slide);
3050
3051 if (player && player.playing) {
3052 player.pause();
3053 }
3054 }
3055 }, {
3056 key: "playSlideVideo",
3057 value: function playSlideVideo(slide) {
3058 if (isNode(slide)) {
3059 var node = slide.querySelector('.gvideo-wrapper');
3060
3061 if (node) {
3062 slide = node.getAttribute('data-index');
3063 }
3064 }
3065
3066 console.log('playSlideVideo is deprecated, use slidePlayerPlay');
3067 var player = this.getSlidePlayerInstance(slide);
3068
3069 if (player && !player.playing) {
3070 player.play();
3071 }
3072 }
3073 }, {
3074 key: "slidePlayerPlay",
3075 value: function slidePlayerPlay(slide) {
3076 var _this$settings$plyr$c;
3077
3078 if (isMobile$1 && !((_this$settings$plyr$c = this.settings.plyr.config) !== null && _this$settings$plyr$c !== void 0 && _this$settings$plyr$c.muted)) {
3079 return;
3080 }
3081
3082 if (isNode(slide)) {
3083 var node = slide.querySelector('.gvideo-wrapper');
3084
3085 if (node) {
3086 slide = node.getAttribute('data-index');
3087 }
3088 }
3089
3090 var player = this.getSlidePlayerInstance(slide);
3091
3092 if (player && !player.playing) {
3093 player.play();
3094
3095 if (this.settings.autofocusVideos) {
3096 player.elements.container.focus();
3097 }
3098 }
3099 }
3100 }, {
3101 key: "setElements",
3102 value: function setElements(elements) {
3103 var _this5 = this;
3104
3105 this.settings.elements = false;
3106 var newElements = [];
3107
3108 if (elements && elements.length) {
3109 each(elements, function (el, i) {
3110 var slide = new Slide(el, _this5, i);
3111 var data = slide.getConfig();
3112
3113 var slideInfo = extend({}, data);
3114
3115 slideInfo.slideConfig = data;
3116 slideInfo.instance = slide;
3117 slideInfo.index = i;
3118 newElements.push(slideInfo);
3119 });
3120 }
3121
3122 this.elements = newElements;
3123
3124 if (this.lightboxOpen) {
3125 this.slidesContainer.innerHTML = '';
3126
3127 if (this.elements.length) {
3128 each(this.elements, function () {
3129 var slide = createHTML(_this5.settings.slideHTML);
3130
3131 _this5.slidesContainer.appendChild(slide);
3132 });
3133
3134 this.showSlide(0, true);
3135 }
3136 }
3137 }
3138 }, {
3139 key: "getElementIndex",
3140 value: function getElementIndex(node) {
3141 var index = false;
3142
3143 each(this.elements, function (el, i) {
3144 if (has(el, 'node') && el.node == node) {
3145 index = i;
3146 return true;
3147 }
3148 });
3149
3150 return index;
3151 }
3152 }, {
3153 key: "getElements",
3154 value: function getElements() {
3155 var _this6 = this;
3156
3157 var list = [];
3158 this.elements = this.elements ? this.elements : [];
3159
3160 if (!isNil(this.settings.elements) && isArray(this.settings.elements) && this.settings.elements.length) {
3161 each(this.settings.elements, function (el, i) {
3162 var slide = new Slide(el, _this6, i);
3163 var elData = slide.getConfig();
3164
3165 var slideInfo = extend({}, elData);
3166
3167 slideInfo.node = false;
3168 slideInfo.index = i;
3169 slideInfo.instance = slide;
3170 slideInfo.slideConfig = elData;
3171 list.push(slideInfo);
3172 });
3173 }
3174
3175 var nodes = false;
3176 var selector = this.getSelector();
3177
3178 if (selector) {
3179 nodes = document.querySelectorAll(this.getSelector());
3180 }
3181
3182 if (!nodes) {
3183 return list;
3184 }
3185
3186 each(nodes, function (el, i) {
3187 var slide = new Slide(el, _this6, i);
3188 var elData = slide.getConfig();
3189
3190 var slideInfo = extend({}, elData);
3191
3192 slideInfo.node = el;
3193 slideInfo.index = i;
3194 slideInfo.instance = slide;
3195 slideInfo.slideConfig = elData;
3196 slideInfo.gallery = el.getAttribute('data-gallery');
3197 list.push(slideInfo);
3198 });
3199
3200 return list;
3201 }
3202 }, {
3203 key: "getGalleryElements",
3204 value: function getGalleryElements(list, gallery) {
3205 return list.filter(function (el) {
3206 return el.gallery == gallery;
3207 });
3208 }
3209 }, {
3210 key: "getSelector",
3211 value: function getSelector() {
3212 if (this.settings.elements) {
3213 return false;
3214 }
3215
3216 if (this.settings.selector && this.settings.selector.substring(0, 5) == 'data-') {
3217 return "*[".concat(this.settings.selector, "]");
3218 }
3219
3220 return this.settings.selector;
3221 }
3222 }, {
3223 key: "getActiveSlide",
3224 value: function getActiveSlide() {
3225 return this.slidesContainer.querySelectorAll('.gslide')[this.index];
3226 }
3227 }, {
3228 key: "getActiveSlideIndex",
3229 value: function getActiveSlideIndex() {
3230 return this.index;
3231 }
3232 }, {
3233 key: "getAnimationClasses",
3234 value: function getAnimationClasses() {
3235 var effects = [];
3236
3237 for (var key in this.settings.cssEfects) {
3238 if (this.settings.cssEfects.hasOwnProperty(key)) {
3239 var effect = this.settings.cssEfects[key];
3240 effects.push("g".concat(effect["in"]));
3241 effects.push("g".concat(effect.out));
3242 }
3243 }
3244
3245 return effects.join(' ');
3246 }
3247 }, {
3248 key: "build",
3249 value: function build() {
3250 var _this7 = this;
3251
3252 if (this.built) {
3253 return false;
3254 }
3255
3256 var children = document.body.childNodes;
3257 var bodyChildElms = [];
3258
3259 each(children, function (el) {
3260 if (el.parentNode == document.body && el.nodeName.charAt(0) !== '#' && el.hasAttribute && !el.hasAttribute('aria-hidden')) {
3261 bodyChildElms.push(el);
3262 el.setAttribute('aria-hidden', 'true');
3263 }
3264 });
3265
3266 var nextSVG = has(this.settings.svg, 'next') ? this.settings.svg.next : '';
3267 var prevSVG = has(this.settings.svg, 'prev') ? this.settings.svg.prev : '';
3268 var closeSVG = has(this.settings.svg, 'close') ? this.settings.svg.close : '';
3269 var lightboxHTML = this.settings.lightboxHTML;
3270 lightboxHTML = lightboxHTML.replace(/{nextSVG}/g, nextSVG);
3271 lightboxHTML = lightboxHTML.replace(/{prevSVG}/g, prevSVG);
3272 lightboxHTML = lightboxHTML.replace(/{closeSVG}/g, closeSVG);
3273 lightboxHTML = createHTML(lightboxHTML);
3274 document.body.appendChild(lightboxHTML);
3275 var modal = document.getElementById('glightbox-body');
3276 this.modal = modal;
3277 var closeButton = modal.querySelector('.gclose');
3278 this.prevButton = modal.querySelector('.gprev');
3279 this.nextButton = modal.querySelector('.gnext');
3280 this.overlay = modal.querySelector('.goverlay');
3281 this.loader = modal.querySelector('.gloader');
3282 this.slidesContainer = document.getElementById('glightbox-slider');
3283 this.bodyHiddenChildElms = bodyChildElms;
3284 this.events = {};
3285
3286 addClass(this.modal, 'glightbox-' + this.settings.skin);
3287
3288 if (this.settings.closeButton && closeButton) {
3289 this.events['close'] = addEvent('click', {
3290 onElement: closeButton,
3291 withCallback: function withCallback(e, target) {
3292 e.preventDefault();
3293
3294 _this7.close();
3295 }
3296 });
3297 }
3298
3299 if (closeButton && !this.settings.closeButton) {
3300 closeButton.parentNode.removeChild(closeButton);
3301 }
3302
3303 if (this.nextButton) {
3304 this.events['next'] = addEvent('click', {
3305 onElement: this.nextButton,
3306 withCallback: function withCallback(e, target) {
3307 e.preventDefault();
3308
3309 _this7.nextSlide();
3310 }
3311 });
3312 }
3313
3314 if (this.prevButton) {
3315 this.events['prev'] = addEvent('click', {
3316 onElement: this.prevButton,
3317 withCallback: function withCallback(e, target) {
3318 e.preventDefault();
3319
3320 _this7.prevSlide();
3321 }
3322 });
3323 }
3324
3325 if (this.settings.closeOnOutsideClick) {
3326 this.events['outClose'] = addEvent('click', {
3327 onElement: modal,
3328 withCallback: function withCallback(e, target) {
3329 if (!_this7.preventOutsideClick && !hasClass(document.body, 'glightbox-mobile') && !closest(e.target, '.ginner-container')) {
3330 if (!closest(e.target, '.gbtn') && !hasClass(e.target, 'gnext') && !hasClass(e.target, 'gprev')) {
3331 _this7.close();
3332 }
3333 }
3334 }
3335 });
3336 }
3337
3338 each(this.elements, function (slide, i) {
3339 _this7.slidesContainer.appendChild(slide.instance.create());
3340
3341 slide.slideNode = _this7.slidesContainer.querySelectorAll('.gslide')[i];
3342 });
3343
3344 if (isTouch$1) {
3345 addClass(document.body, 'glightbox-touch');
3346 }
3347
3348 this.events['resize'] = addEvent('resize', {
3349 onElement: window,
3350 withCallback: function withCallback() {
3351 _this7.resize();
3352 }
3353 });
3354 this.built = true;
3355 }
3356 }, {
3357 key: "resize",
3358 value: function resize() {
3359 var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
3360 slide = !slide ? this.activeSlide : slide;
3361
3362 if (!slide || hasClass(slide, 'zoomed')) {
3363 return;
3364 }
3365
3366 var winSize = windowSize();
3367
3368 var video = slide.querySelector('.gvideo-wrapper');
3369 var image = slide.querySelector('.gslide-image');
3370 var description = this.slideDescription;
3371 var winWidth = winSize.width;
3372 var winHeight = winSize.height;
3373
3374 if (winWidth <= 768) {
3375 addClass(document.body, 'glightbox-mobile');
3376 } else {
3377 removeClass(document.body, 'glightbox-mobile');
3378 }
3379
3380 if (!video && !image) {
3381 return;
3382 }
3383
3384 var descriptionResize = false;
3385
3386 if (description && (hasClass(description, 'description-bottom') || hasClass(description, 'description-top')) && !hasClass(description, 'gabsolute')) {
3387 descriptionResize = true;
3388 }
3389
3390 if (image) {
3391 if (winWidth <= 768) {
3392 var imgNode = image.querySelector('img');
3393 } else if (descriptionResize) {
3394 var descHeight = description.offsetHeight;
3395
3396 var _imgNode = image.querySelector('img');
3397
3398 _imgNode.setAttribute('style', "max-height: calc(100vh - ".concat(descHeight, "px)"));
3399
3400 description.setAttribute('style', "max-width: ".concat(_imgNode.offsetWidth, "px;"));
3401 }
3402 }
3403
3404 if (video) {
3405 var ratio = has(this.settings.plyr.config, 'ratio') ? this.settings.plyr.config.ratio : '';
3406
3407 if (!ratio) {
3408 var containerWidth = video.clientWidth;
3409 var containerHeight = video.clientHeight;
3410 var divisor = containerWidth / containerHeight;
3411 ratio = "".concat(containerWidth / divisor, ":").concat(containerHeight / divisor);
3412 }
3413
3414 var videoRatio = ratio.split(':');
3415 var videoWidth = this.settings.videosWidth;
3416 var maxWidth = this.settings.videosWidth;
3417
3418 if (isNumber(videoWidth) || videoWidth.indexOf('px') !== -1) {
3419 maxWidth = parseInt(videoWidth);
3420 } else {
3421 if (videoWidth.indexOf('vw') !== -1) {
3422 maxWidth = winWidth * parseInt(videoWidth) / 100;
3423 } else if (videoWidth.indexOf('vh') !== -1) {
3424 maxWidth = winHeight * parseInt(videoWidth) / 100;
3425 } else if (videoWidth.indexOf('%') !== -1) {
3426 maxWidth = winWidth * parseInt(videoWidth) / 100;
3427 } else {
3428 maxWidth = parseInt(video.clientWidth);
3429 }
3430 }
3431
3432 var maxHeight = maxWidth / (parseInt(videoRatio[0]) / parseInt(videoRatio[1]));
3433 maxHeight = Math.floor(maxHeight);
3434
3435 if (descriptionResize) {
3436 winHeight = winHeight - description.offsetHeight;
3437 }
3438
3439 if (maxWidth > winWidth || maxHeight > winHeight || winHeight < maxHeight && winWidth > maxWidth) {
3440 var vwidth = video.offsetWidth;
3441 var vheight = video.offsetHeight;
3442
3443 var _ratio = winHeight / vheight;
3444
3445 var vsize = {
3446 width: vwidth * _ratio,
3447 height: vheight * _ratio
3448 };
3449 video.parentNode.setAttribute('style', "max-width: ".concat(vsize.width, "px"));
3450
3451 if (descriptionResize) {
3452 description.setAttribute('style', "max-width: ".concat(vsize.width, "px;"));
3453 }
3454 } else {
3455 video.parentNode.style.maxWidth = "".concat(videoWidth);
3456
3457 if (descriptionResize) {
3458 description.setAttribute('style', "max-width: ".concat(videoWidth, ";"));
3459 }
3460 }
3461 }
3462 }
3463 }, {
3464 key: "reload",
3465 value: function reload() {
3466 this.init();
3467 }
3468 }, {
3469 key: "updateNavigationClasses",
3470 value: function updateNavigationClasses() {
3471 var loop = this.loop();
3472
3473 removeClass(this.nextButton, 'disabled');
3474
3475 removeClass(this.prevButton, 'disabled');
3476
3477 if (this.index == 0 && this.elements.length - 1 == 0) {
3478 addClass(this.prevButton, 'disabled');
3479
3480 addClass(this.nextButton, 'disabled');
3481 } else if (this.index === 0 && !loop) {
3482 addClass(this.prevButton, 'disabled');
3483 } else if (this.index === this.elements.length - 1 && !loop) {
3484 addClass(this.nextButton, 'disabled');
3485 }
3486 }
3487 }, {
3488 key: "loop",
3489 value: function loop() {
3490 var loop = has(this.settings, 'loopAtEnd') ? this.settings.loopAtEnd : null;
3491 loop = has(this.settings, 'loop') ? this.settings.loop : loop;
3492 return loop;
3493 }
3494 }, {
3495 key: "close",
3496 value: function close() {
3497 var _this8 = this;
3498
3499 if (!this.lightboxOpen) {
3500 if (this.events) {
3501 for (var key in this.events) {
3502 if (this.events.hasOwnProperty(key)) {
3503 this.events[key].destroy();
3504 }
3505 }
3506
3507 this.events = null;
3508 }
3509
3510 return false;
3511 }
3512
3513 if (this.closing) {
3514 return false;
3515 }
3516
3517 this.closing = true;
3518 this.slidePlayerPause(this.activeSlide);
3519
3520 if (this.fullElementsList) {
3521 this.elements = this.fullElementsList;
3522 }
3523
3524 if (this.bodyHiddenChildElms.length) {
3525 each(this.bodyHiddenChildElms, function (el) {
3526 el.removeAttribute('aria-hidden');
3527 });
3528 }
3529
3530 addClass(this.modal, 'glightbox-closing');
3531
3532 animateElement(this.overlay, this.settings.openEffect == 'none' ? 'none' : this.settings.cssEfects.fade.out);
3533
3534 animateElement(this.activeSlide, this.settings.cssEfects[this.settings.closeEffect].out, function () {
3535 _this8.activeSlide = null;
3536 _this8.prevActiveSlideIndex = null;
3537 _this8.prevActiveSlide = null;
3538 _this8.built = false;
3539
3540 if (_this8.events) {
3541 for (var _key in _this8.events) {
3542 if (_this8.events.hasOwnProperty(_key)) {
3543 _this8.events[_key].destroy();
3544 }
3545 }
3546
3547 _this8.events = null;
3548 }
3549
3550 var body = document.body;
3551
3552 removeClass(html, 'glightbox-open');
3553
3554 removeClass(body, 'glightbox-open touching gdesc-open glightbox-touch glightbox-mobile gscrollbar-fixer');
3555
3556 _this8.modal.parentNode.removeChild(_this8.modal);
3557
3558 _this8.trigger('close');
3559
3560 if (isFunction(_this8.settings.onClose)) {
3561 _this8.settings.onClose();
3562 }
3563
3564 var styles = document.querySelector('.gcss-styles');
3565
3566 if (styles) {
3567 styles.parentNode.removeChild(styles);
3568 }
3569
3570 _this8.lightboxOpen = false;
3571 _this8.closing = null;
3572 });
3573 }
3574 }, {
3575 key: "destroy",
3576 value: function destroy() {
3577 this.close();
3578 this.clearAllEvents();
3579
3580 if (this.baseEvents) {
3581 this.baseEvents.destroy();
3582 }
3583 }
3584 }, {
3585 key: "on",
3586 value: function on(evt, callback) {
3587 var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3588
3589 if (!evt || !isFunction(callback)) {
3590 throw new TypeError('Event name and callback must be defined');
3591 }
3592
3593 this.apiEvents.push({
3594 evt: evt,
3595 once: once,
3596 callback: callback
3597 });
3598 }
3599 }, {
3600 key: "once",
3601 value: function once(evt, callback) {
3602 this.on(evt, callback, true);
3603 }
3604 }, {
3605 key: "trigger",
3606 value: function trigger(eventName) {
3607 var _this9 = this;
3608
3609 var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
3610 var onceTriggered = [];
3611
3612 each(this.apiEvents, function (event, i) {
3613 var evt = event.evt,
3614 once = event.once,
3615 callback = event.callback;
3616
3617 if (evt == eventName) {
3618 callback(data);
3619
3620 if (once) {
3621 onceTriggered.push(i);
3622 }
3623 }
3624 });
3625
3626 if (onceTriggered.length) {
3627 each(onceTriggered, function (i) {
3628 return _this9.apiEvents.splice(i, 1);
3629 });
3630 }
3631 }
3632 }, {
3633 key: "clearAllEvents",
3634 value: function clearAllEvents() {
3635 this.apiEvents.splice(0, this.apiEvents.length);
3636 }
3637 }, {
3638 key: "version",
3639 value: function version() {
3640 return _version;
3641 }
3642 }]);
3643
3644 return GlightboxInit;
3645 }();
3646
3647 function glightbox () {
3648 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3649 var instance = new GlightboxInit(options);
3650 instance.init();
3651 return instance;
3652 }
3653
3654 return glightbox;
3655
3656 })));
3657