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