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