1/*! 2 By André Rinas, www.andrerinas.de 3 Documentation, www.simplelightbox.de 4 Available for use under the MIT License 5 Version 2.10.2 6*/ 7(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ 8(function (global){(function (){ 9"use strict"; 10 11Object.defineProperty(exports, "__esModule", { 12 value: true 13}); 14exports["default"] = void 0; 15 16function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 17 18function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } 19 20function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } 21 22function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } 23 24function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 25 26function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } 27 28function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } 29 30function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 31 32var SimpleLightbox = /*#__PURE__*/function () { 33 function SimpleLightbox(elements, options) { 34 var _this = this; 35 36 _classCallCheck(this, SimpleLightbox); 37 38 _defineProperty(this, "defaultOptions", { 39 sourceAttr: 'href', 40 overlay: true, 41 overlayOpacity: 0.7, 42 spinner: true, 43 nav: true, 44 navText: ['‹', '›'], 45 captions: true, 46 captionDelay: 0, 47 captionSelector: 'img', 48 captionType: 'attr', 49 captionsData: 'title', 50 captionPosition: 'bottom', 51 captionClass: '', 52 close: true, 53 closeText: '×', 54 swipeClose: true, 55 showCounter: false, 56 fileExt: 'png|jpg|jpeg|gif|webp', 57 animationSlide: true, 58 animationSpeed: 250, 59 preloading: true, 60 enableKeyboard: true, 61 loop: true, 62 rel: false, 63 docClose: true, 64 swipeTolerance: 50, 65 className: 'simple-lightbox', 66 widthRatio: 1, 67 heightRatio: 1, 68 scaleImageToRatio: false, 69 disableRightClick: false, 70 disableScroll: true, 71 alertError: true, 72 alertErrorMessage: 'Image not found, next image will be loaded', 73 additionalHtml: false, 74 history: true, 75 throttleInterval: 0, 76 doubleTapZoom: 2, 77 maxZoom: 10, 78 htmlClass: 'has-lightbox', 79 rtl: false, 80 fixedClass: 'sl-fixed', 81 fadeSpeed: 300, 82 uniqueImages: false, 83 focus: true, 84 scrollZoom: true, 85 scrollZoomFactor: 0.5 86 }); 87 88 _defineProperty(this, "transitionPrefix", void 0); 89 90 _defineProperty(this, "isPassiveEventsSupported", void 0); 91 92 _defineProperty(this, "transitionCapable", false); 93 94 _defineProperty(this, "isTouchDevice", 'ontouchstart' in window); 95 96 _defineProperty(this, "isAppleDevice", /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)); 97 98 _defineProperty(this, "initialLocationHash", void 0); 99 100 _defineProperty(this, "pushStateSupport", 'pushState' in history); 101 102 _defineProperty(this, "isOpen", false); 103 104 _defineProperty(this, "isAnimating", false); 105 106 _defineProperty(this, "isClosing", false); 107 108 _defineProperty(this, "isFadeIn", false); 109 110 _defineProperty(this, "urlChangedOnce", false); 111 112 _defineProperty(this, "hashReseted", false); 113 114 _defineProperty(this, "historyHasChanges", false); 115 116 _defineProperty(this, "historyUpdateTimeout", null); 117 118 _defineProperty(this, "currentImage", void 0); 119 120 _defineProperty(this, "eventNamespace", 'simplelightbox'); 121 122 _defineProperty(this, "domNodes", {}); 123 124 _defineProperty(this, "loadedImages", []); 125 126 _defineProperty(this, "initialImageIndex", 0); 127 128 _defineProperty(this, "currentImageIndex", 0); 129 130 _defineProperty(this, "initialSelector", null); 131 132 _defineProperty(this, "globalScrollbarWidth", 0); 133
vendor: 69,946 bytes, lines 134-1781
134 _defineProperty(this, "controlCoordinates", { 135 swipeDiff: 0, 136 swipeYDiff: 0, 137 swipeStart: 0, 138 swipeEnd: 0, 139 swipeYStart: 0, 140 swipeYEnd: 0, 141 mousedown: false, 142 imageLeft: 0, 143 zoomed: false, 144 containerHeight: 0, 145 containerWidth: 0, 146 containerOffsetX: 0, 147 containerOffsetY: 0, 148 imgHeight: 0, 149 imgWidth: 0, 150 capture: false, 151 initialOffsetX: 0, 152 initialOffsetY: 0, 153 initialPointerOffsetX: 0, 154 initialPointerOffsetY: 0, 155 initialPointerOffsetX2: 0, 156 initialPointerOffsetY2: 0, 157 initialScale: 1, 158 initialPinchDistance: 0, 159 pointerOffsetX: 0, 160 pointerOffsetY: 0, 161 pointerOffsetX2: 0, 162 pointerOffsetY2: 0, 163 targetOffsetX: 0, 164 targetOffsetY: 0, 165 targetScale: 0, 166 pinchOffsetX: 0, 167 pinchOffsetY: 0, 168 limitOffsetX: 0, 169 limitOffsetY: 0, 170 scaleDifference: 0, 171 targetPinchDistance: 0, 172 touchCount: 0, 173 doubleTapped: false, 174 touchmoveCount: 0 175 }); 176 177 this.options = Object.assign(this.defaultOptions, options); 178 this.isPassiveEventsSupported = this.checkPassiveEventsSupport(); 179 180 if (typeof elements === 'string') { 181 this.initialSelector = elements; 182 this.elements = Array.from(document.querySelectorAll(elements)); 183 } else { 184 this.elements = typeof elements.length !== 'undefined' && elements.length > 0 ? Array.from(elements) : [elements]; 185 } 186 187 this.relatedElements = []; 188 this.transitionPrefix = this.calculateTransitionPrefix(); 189 this.transitionCapable = this.transitionPrefix !== false; 190 this.initialLocationHash = this.hash; // this should be handled by attribute selector IMHO! => 'a[rel=bla]'... 191 192 if (this.options.rel) { 193 this.elements = this.getRelated(this.options.rel); 194 } 195 196 if (this.options.uniqueImages) { 197 var imgArr = []; 198 this.elements = Array.from(this.elements).filter(function (element) { 199 var src = element.getAttribute(_this.options.sourceAttr); 200 201 if (imgArr.indexOf(src) === -1) { 202 imgArr.push(src); 203 return true; 204 } 205 206 return false; 207 }); 208 } 209 210 this.createDomNodes(); 211 212 if (this.options.close) { 213 this.domNodes.wrapper.appendChild(this.domNodes.closeButton); 214 } 215 216 if (this.options.nav) { 217 this.domNodes.wrapper.appendChild(this.domNodes.navigation); 218 } 219 220 if (this.options.spinner) { 221 this.domNodes.wrapper.appendChild(this.domNodes.spinner); 222 } 223 224 this.addEventListener(this.elements, 'click.' + this.eventNamespace, function (event) { 225 if (_this.isValidLink(event.currentTarget)) { 226 event.preventDefault(); 227 228 if (_this.isAnimating) { 229 return false; 230 } 231 232 _this.initialImageIndex = _this.elements.indexOf(event.currentTarget); 233 234 _this.openImage(event.currentTarget); 235 } 236 }); // close addEventListener click addEventListener doc 237 238 if (this.options.docClose) { 239 this.addEventListener(this.domNodes.wrapper, ['click.' + this.eventNamespace, 'touchstart.' + this.eventNamespace], function (event) { 240 if (_this.isOpen && event.target === event.currentTarget) { 241 _this.close(); 242 } 243 }); 244 } // disable rightclick 245 246 247 if (this.options.disableRightClick) { 248 this.addEventListener(document.body, 'contextmenu.' + this.eventNamespace, function (event) { 249 if (event.target.parentElement.classList.contains("sl-image")) { 250 event.preventDefault(); 251 } 252 }); 253 } // keyboard-control 254 255 256 if (this.options.enableKeyboard) { 257 this.addEventListener(document.body, 'keyup.' + this.eventNamespace, this.throttle(function (event) { 258 _this.controlCoordinates.swipeDiff = 0; // keyboard control only if lightbox is open 259 260 if (_this.isAnimating && event.key === 'Escape') { 261 _this.currentImage.setAttribute('src', ''); 262 263 _this.isAnimating = false; 264 return _this.close(); 265 } 266 267 if (_this.isOpen) { 268 event.preventDefault(); 269 270 if (event.key === 'Escape') { 271 _this.close(); 272 } 273 274 if (!_this.isAnimating && ['ArrowLeft', 'ArrowRight'].indexOf(event.key) > -1) { 275 _this.loadImage(event.key === 'ArrowRight' ? 1 : -1); 276 } 277 } 278 }, this.options.throttleInterval)); 279 } 280 281 this.addEvents(); 282 } 283 284 _createClass(SimpleLightbox, [{ 285 key: "checkPassiveEventsSupport", 286 value: function checkPassiveEventsSupport() { 287 // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection 288 // Test via a getter in the options object to see if the passive property is accessed 289 var supportsPassive = false; 290 291 try { 292 var opts = Object.defineProperty({}, 'passive', { 293 get: function get() { 294 supportsPassive = true; 295 } 296 }); 297 window.addEventListener("testPassive", null, opts); 298 window.removeEventListener("testPassive", null, opts); 299 } catch (e) {} 300 301 return supportsPassive; 302 } 303 }, { 304 key: "createDomNodes", 305 value: function createDomNodes() { 306 this.domNodes.overlay = document.createElement('div'); 307 this.domNodes.overlay.classList.add('sl-overlay'); 308 this.domNodes.overlay.dataset.opacityTarget = this.options.overlayOpacity; 309 this.domNodes.closeButton = document.createElement('button'); 310 this.domNodes.closeButton.classList.add('sl-close'); 311 this.domNodes.closeButton.innerHTML = this.options.closeText; 312 this.domNodes.spinner = document.createElement('div'); 313 this.domNodes.spinner.classList.add('sl-spinner'); 314 this.domNodes.spinner.innerHTML = '<div></div>'; 315 this.domNodes.navigation = document.createElement('div'); 316 this.domNodes.navigation.classList.add('sl-navigation'); 317 this.domNodes.navigation.innerHTML = "<button class=\"sl-prev\">".concat(this.options.navText[0], "</button><button class=\"sl-next\">").concat(this.options.navText[1], "</button>"); 318 this.domNodes.counter = document.createElement('div'); 319 this.domNodes.counter.classList.add('sl-counter'); 320 this.domNodes.counter.innerHTML = '<span class="sl-current"></span>/<span class="sl-total"></span>'; 321 this.domNodes.caption = document.createElement('div'); 322 this.domNodes.caption.classList.add('sl-caption', 'pos-' + this.options.captionPosition); 323 324 if (this.options.captionClass) { 325 this.domNodes.caption.classList.add(this.options.captionClass); 326 } 327 328 this.domNodes.image = document.createElement('div'); 329 this.domNodes.image.classList.add('sl-image'); 330 this.domNodes.wrapper = document.createElement('div'); 331 this.domNodes.wrapper.classList.add('sl-wrapper'); 332 this.domNodes.wrapper.setAttribute('tabindex', -1); 333 this.domNodes.wrapper.setAttribute('role', 'dialog'); 334 this.domNodes.wrapper.setAttribute('aria-hidden', false); 335 336 if (this.options.className) { 337 this.domNodes.wrapper.classList.add(this.options.className); 338 } 339 340 if (this.options.rtl) { 341 this.domNodes.wrapper.classList.add('sl-dir-rtl'); 342 } 343 } 344 }, { 345 key: "throttle", 346 value: function throttle(func, limit) { 347 var inThrottle; 348 return function () { 349 if (!inThrottle) { 350 func.apply(this, arguments); 351 inThrottle = true; 352 setTimeout(function () { 353 return inThrottle = false; 354 }, limit); 355 } 356 }; 357 } 358 }, { 359 key: "isValidLink", 360 value: function isValidLink(element) { 361 return !this.options.fileExt || element.getAttribute(this.options.sourceAttr) && new RegExp('(' + this.options.fileExt + ')$', 'i').test(element.getAttribute(this.options.sourceAttr)); 362 } 363 }, { 364 key: "calculateTransitionPrefix", 365 value: function calculateTransitionPrefix() { 366 var s = (document.body || document.documentElement).style; 367 return 'transition' in s ? '' : 'WebkitTransition' in s ? '-webkit-' : 'MozTransition' in s ? '-moz-' : 'OTransition' in s ? '-o' : false; 368 } 369 }, { 370 key: "toggleScrollbar", 371 value: function toggleScrollbar(type) { 372 var scrollbarWidth = 0; 373 var fixedElements = [].slice.call(document.querySelectorAll('.' + this.options.fixedClass)); 374 375 if (type === 'hide') { 376 var fullWindowWidth = window.innerWidth; 377 378 if (!fullWindowWidth) { 379 var documentElementRect = document.documentElement.getBoundingClientRect(); 380 fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left); 381 } 382 383 if (document.body.clientWidth < fullWindowWidth || this.isAppleDevice) { 384 var scrollDiv = document.createElement('div'), 385 paddingRight = parseInt(document.body.style.paddingRight || 0, 10); 386 scrollDiv.classList.add('sl-scrollbar-measure'); 387 document.body.appendChild(scrollDiv); 388 scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; 389 document.body.removeChild(scrollDiv); 390 document.body.dataset.originalPaddingRight = paddingRight; 391 392 if (scrollbarWidth > 0 || scrollbarWidth == 0 && this.isAppleDevice) { 393 document.body.classList.add('hidden-scroll'); 394 document.body.style.paddingRight = paddingRight + scrollbarWidth + 'px'; 395 fixedElements.forEach(function (element) { 396 var actualPadding = element.style.paddingRight; 397 var calculatedPadding = window.getComputedStyle(element)['padding-right']; 398 element.dataset.originalPaddingRight = actualPadding; 399 element.style.paddingRight = "".concat(parseFloat(calculatedPadding) + scrollbarWidth, "px"); 400 }); 401 } 402 } 403 } else { 404 document.body.classList.remove('hidden-scroll'); 405 document.body.style.paddingRight = document.body.dataset.originalPaddingRight; 406 fixedElements.forEach(function (element) { 407 var padding = element.dataset.originalPaddingRight; 408 409 if (typeof padding !== 'undefined') { 410 element.style.paddingRight = padding; 411 } 412 }); 413 } 414 415 return scrollbarWidth; 416 } 417 }, { 418 key: "close", 419 value: function close() { 420 var _this2 = this; 421 422 if (!this.isOpen || this.isAnimating || this.isClosing) { 423 return false; 424 } 425 426 this.isClosing = true; 427 var element = this.relatedElements[this.currentImageIndex]; 428 element.dispatchEvent(new Event('close.simplelightbox')); 429 430 if (this.options.history) { 431 this.historyHasChanges = false; 432 433 if (!this.hashReseted) { 434 this.resetHash(); 435 } 436 } 437 438 this.removeEventListener(document, 'focusin.' + this.eventNamespace); 439 this.fadeOut(this.domNodes.overlay, this.options.fadeSpeed); 440 this.fadeOut(document.querySelectorAll('.sl-image img, .sl-close, .sl-navigation, .sl-image .sl-caption, .sl-counter'), this.options.fadeSpeed, function () { 441 if (_this2.options.disableScroll) { 442 _this2.toggleScrollbar('show'); 443 } 444 445 if (_this2.options.htmlClass && _this2.options.htmlClass !== '') { 446 document.querySelector('html').classList.remove(_this2.options.htmlClass); 447 } 448 449 document.body.removeChild(_this2.domNodes.wrapper); 450 document.body.removeChild(_this2.domNodes.overlay); 451 _this2.domNodes.additionalHtml = null; 452 element.dispatchEvent(new Event('closed.simplelightbox')); 453 _this2.isClosing = false; 454 }); 455 this.currentImage = null; 456 this.isOpen = false; 457 this.isAnimating = false; // reset touchcontrol coordinates 458 459 for (var key in this.controlCoordinates) { 460 this.controlCoordinates[key] = 0; 461 } 462 463 this.controlCoordinates.mousedown = false; 464 this.controlCoordinates.zoomed = false; 465 this.controlCoordinates.capture = false; 466 this.controlCoordinates.initialScale = this.minMax(1, 1, this.options.maxZoom); 467 this.controlCoordinates.doubleTapped = false; 468 } 469 }, { 470 key: "hash", 471 get: function get() { 472 return window.location.hash.substring(1); 473 } 474 }, { 475 key: "preload", 476 value: function preload() { 477 var _this3 = this; 478 479 var index = this.currentImageIndex, 480 length = this.relatedElements.length, 481 next = index + 1 < 0 ? length - 1 : index + 1 >= length - 1 ? 0 : index + 1, 482 prev = index - 1 < 0 ? length - 1 : index - 1 >= length - 1 ? 0 : index - 1, 483 nextImage = new Image(), 484 prevImage = new Image(); 485 nextImage.addEventListener('load', function (event) { 486 var src = event.target.getAttribute('src'); 487 488 if (_this3.loadedImages.indexOf(src) === -1) { 489 //is this condition even required... setting multiple times will not change usage... 490 _this3.loadedImages.push(src); 491 } 492 493 _this3.relatedElements[index].dispatchEvent(new Event('nextImageLoaded.' + _this3.eventNamespace)); 494 }); 495 nextImage.setAttribute('src', this.relatedElements[next].getAttribute(this.options.sourceAttr)); 496 prevImage.addEventListener('load', function (event) { 497 var src = event.target.getAttribute('src'); 498 499 if (_this3.loadedImages.indexOf(src) === -1) { 500 _this3.loadedImages.push(src); 501 } 502 503 _this3.relatedElements[index].dispatchEvent(new Event('prevImageLoaded.' + _this3.eventNamespace)); 504 }); 505 prevImage.setAttribute('src', this.relatedElements[prev].getAttribute(this.options.sourceAttr)); 506 } 507 }, { 508 key: "loadImage", 509 value: function loadImage(direction) { 510 var _this4 = this; 511 512 var slideDirection = direction; 513 514 if (this.options.rtl) { 515 direction = -direction; 516 } 517 518 this.relatedElements[this.currentImageIndex].dispatchEvent(new Event('change.' + this.eventNamespace)); 519 this.relatedElements[this.currentImageIndex].dispatchEvent(new Event((direction === 1 ? 'next' : 'prev') + '.' + this.eventNamespace)); 520 var newIndex = this.currentImageIndex + direction; 521 522 if (this.isAnimating || (newIndex < 0 || newIndex >= this.relatedElements.length) && this.options.loop === false) { 523 return false; 524 } 525 526 this.currentImageIndex = newIndex < 0 ? this.relatedElements.length - 1 : newIndex > this.relatedElements.length - 1 ? 0 : newIndex; 527 this.domNodes.counter.querySelector('.sl-current').innerHTML = this.currentImageIndex + 1; 528 529 if (this.options.animationSlide) { 530 this.slide(this.options.animationSpeed / 1000, -100 * slideDirection - this.controlCoordinates.swipeDiff + 'px'); 531 } 532 533 this.fadeOut(this.domNodes.image, this.options.fadeSpeed, function () { 534 _this4.isAnimating = true; 535 536 if (!_this4.isClosing) { 537 setTimeout(function () { 538 var element = _this4.relatedElements[_this4.currentImageIndex]; 539 540 _this4.currentImage.setAttribute('src', element.getAttribute(_this4.options.sourceAttr)); 541 542 if (_this4.loadedImages.indexOf(element.getAttribute(_this4.options.sourceAttr)) === -1) { 543 _this4.show(_this4.domNodes.spinner); 544 } 545 546 if (_this4.domNodes.image.contains(_this4.domNodes.caption)) { 547 _this4.domNodes.image.removeChild(_this4.domNodes.caption); 548 } 549 550 _this4.adjustImage(slideDirection); 551 552 if (_this4.options.preloading) _this4.preload(); 553 }, 100); 554 } else { 555 _this4.isAnimating = false; 556 } 557 }); 558 } 559 }, { 560 key: "adjustImage", 561 value: function adjustImage(direction) { 562 var _this5 = this; 563 564 if (!this.currentImage) { 565 return false; 566 } 567 568 var tmpImage = new Image(), 569 windowWidth = window.innerWidth * this.options.widthRatio, 570 windowHeight = window.innerHeight * this.options.heightRatio; 571 tmpImage.setAttribute('src', this.currentImage.getAttribute('src')); 572 this.currentImage.dataset.scale = 1; 573 this.currentImage.dataset.translateX = 0; 574 this.currentImage.dataset.translateY = 0; 575 this.zoomPanElement(0, 0, 1); 576 tmpImage.addEventListener('error', function (event) { 577 _this5.relatedElements[_this5.currentImageIndex].dispatchEvent(new Event('error.' + _this5.eventNamespace)); 578 579 _this5.isAnimating = false; 580 _this5.isOpen = true; 581 _this5.domNodes.spinner.style.display = 'none'; 582 var dirIsDefined = direction === 1 || direction === -1; 583 584 if (_this5.initialImageIndex === _this5.currentImageIndex && dirIsDefined) { 585 return _this5.close(); 586 } 587 588 if (_this5.options.alertError) { 589 alert(_this5.options.alertErrorMessage); 590 } 591 592 _this5.loadImage(dirIsDefined ? direction : 1); 593 }); 594 tmpImage.addEventListener('load', function (event) { 595 if (typeof direction !== 'undefined') { 596 _this5.relatedElements[_this5.currentImageIndex].dispatchEvent(new Event('changed.' + _this5.eventNamespace)); 597 598 _this5.relatedElements[_this5.currentImageIndex].dispatchEvent(new Event((direction === 1 ? 'nextDone' : 'prevDone') + '.' + _this5.eventNamespace)); 599 } // history 600 601 602 if (_this5.options.history) { 603 _this5.updateURL(); 604 } 605 606 if (_this5.loadedImages.indexOf(_this5.currentImage.getAttribute('src')) === -1) { 607 _this5.loadedImages.push(_this5.currentImage.getAttribute('src')); 608 } 609 610 var imageWidth = event.target.width, 611 imageHeight = event.target.height; 612 613 if (_this5.options.scaleImageToRatio || imageWidth > windowWidth || imageHeight > windowHeight) { 614 var ratio = imageWidth / imageHeight > windowWidth / windowHeight ? imageWidth / windowWidth : imageHeight / windowHeight; 615 imageWidth /= ratio; 616 imageHeight /= ratio; 617 } 618 619 _this5.domNodes.image.style.top = (window.innerHeight - imageHeight) / 2 + 'px'; 620 _this5.domNodes.image.style.left = (window.innerWidth - imageWidth - _this5.globalScrollbarWidth) / 2 + 'px'; 621 _this5.domNodes.image.style.width = imageWidth + 'px'; 622 _this5.domNodes.image.style.height = imageHeight + 'px'; 623 _this5.domNodes.spinner.style.display = 'none'; 624 625 if (_this5.options.focus) { 626 _this5.forceFocus(); 627 } 628 629 _this5.fadeIn(_this5.currentImage, _this5.options.fadeSpeed, function () { 630 if (_this5.options.focus) { 631 _this5.domNodes.wrapper.focus(); 632 } 633 }); 634 635 _this5.isOpen = true; 636 var captionContainer, captionText; 637 638 if (typeof _this5.options.captionSelector === 'string') { 639 captionContainer = _this5.options.captionSelector === 'self' ? _this5.relatedElements[_this5.currentImageIndex] : _this5.relatedElements[_this5.currentImageIndex].querySelector(_this5.options.captionSelector); 640 } else if (typeof _this5.options.captionSelector === 'function') { 641 captionContainer = _this5.options.captionSelector(_this5.relatedElements[_this5.currentImageIndex]); 642 } 643 644 if (_this5.options.captions && captionContainer) { 645 if (_this5.options.captionType === 'data') { 646 captionText = captionContainer.dataset[_this5.options.captionsData]; 647 } else if (_this5.options.captionType === 'text') { 648 captionText = captionContainer.innerHTML; 649 } else { 650 captionText = captionContainer.getAttribute(_this5.options.captionsData); 651 } 652 } 653 654 if (!_this5.options.loop) { 655 if (_this5.currentImageIndex === 0) { 656 _this5.hide(_this5.domNodes.navigation.querySelector('.sl-prev')); 657 } 658 659 if (_this5.currentImageIndex >= _this5.relatedElements.length - 1) { 660 _this5.hide(_this5.domNodes.navigation.querySelector('.sl-next')); 661 } 662 663 if (_this5.currentImageIndex > 0) { 664 _this5.show(_this5.domNodes.navigation.querySelector('.sl-prev')); 665 } 666 667 if (_this5.currentImageIndex < _this5.relatedElements.length - 1) { 668 _this5.show(_this5.domNodes.navigation.querySelector('.sl-next')); 669 } 670 } else { 671 if (_this5.relatedElements.length === 1) { 672 _this5.hide(_this5.domNodes.navigation.querySelectorAll('.sl-prev, .sl-next')); 673 } else { 674 _this5.show(_this5.domNodes.navigation.querySelectorAll('.sl-prev, .sl-next')); 675 } 676 } 677 678 if (direction === 1 || direction === -1) { 679 if (_this5.options.animationSlide) { 680 _this5.slide(0, 100 * direction + 'px'); 681 682 setTimeout(function () { 683 _this5.slide(_this5.options.animationSpeed / 1000, 0 + 'px'); 684 }, 50); 685 } 686 687 _this5.fadeIn(_this5.domNodes.image, _this5.options.fadeSpeed, function () { 688 _this5.isAnimating = false; 689 690 _this5.setCaption(captionText, imageWidth); 691 }); 692 } else { 693 _this5.isAnimating = false; 694 695 _this5.setCaption(captionText, imageWidth); 696 } 697 698 if (_this5.options.additionalHtml && !_this5.domNodes.additionalHtml) { 699 _this5.domNodes.additionalHtml = document.createElement('div'); 700 701 _this5.domNodes.additionalHtml.classList.add('sl-additional-html'); 702 703 _this5.domNodes.additionalHtml.innerHTML = _this5.options.additionalHtml; 704 705 _this5.domNodes.image.appendChild(_this5.domNodes.additionalHtml); 706 } 707 }); 708 } 709 }, { 710 key: "zoomPanElement", 711 value: function zoomPanElement(targetOffsetX, targetOffsetY, targetScale) { 712 this.currentImage.style[this.transitionPrefix + 'transform'] = 'translate(' + targetOffsetX + ',' + targetOffsetY + ') scale(' + targetScale + ')'; 713 } 714 }, { 715 key: "minMax", 716 value: function minMax(value, min, max) { 717 return value < min ? min : value > max ? max : value; 718 } 719 }, { 720 key: "setZoomData", 721 value: function setZoomData(initialScale, targetOffsetX, targetOffsetY) { 722 this.currentImage.dataset.scale = initialScale; 723 this.currentImage.dataset.translateX = targetOffsetX; 724 this.currentImage.dataset.translateY = targetOffsetY; 725 } 726 }, { 727 key: "hashchangeHandler", 728 value: function hashchangeHandler() { 729 if (this.isOpen && this.hash === this.initialLocationHash) { 730 this.hashReseted = true; 731 this.close(); 732 } 733 } 734 }, { 735 key: "addEvents", 736 value: function addEvents() { 737 var _this6 = this; 738 739 // resize/responsive 740 this.addEventListener(window, 'resize.' + this.eventNamespace, function (event) { 741 //this.adjustImage.bind(this) 742 if (_this6.isOpen) { 743 _this6.adjustImage(); 744 } 745 }); 746 this.addEventListener(this.domNodes.closeButton, ['click.' + this.eventNamespace, 'touchstart.' + this.eventNamespace], this.close.bind(this)); 747 748 if (this.options.history) { 749 setTimeout(function () { 750 _this6.addEventListener(window, 'hashchange.' + _this6.eventNamespace, function (event) { 751 if (_this6.isOpen) { 752 _this6.hashchangeHandler(); 753 } 754 }); 755 }, 40); 756 } 757 758 this.addEventListener(this.domNodes.navigation.getElementsByTagName('button'), 'click.' + this.eventNamespace, function (event) { 759 if (!event.currentTarget.tagName.match(/button/i)) { 760 return true; 761 } 762 763 event.preventDefault(); 764 _this6.controlCoordinates.swipeDiff = 0; 765 766 _this6.loadImage(event.currentTarget.classList.contains('sl-next') ? 1 : -1); 767 }); 768 769 if (this.options.scrollZoom) { 770 var scale = 1; 771 this.addEventListener(this.domNodes.image, ['mousewheel', 'DOMMouseScroll'], function (event) { 772 if (_this6.controlCoordinates.mousedown || _this6.isAnimating || _this6.isClosing || !_this6.isOpen) { 773 return true; 774 } 775 776 if (_this6.controlCoordinates.containerHeight == 0) { 777 _this6.controlCoordinates.containerHeight = _this6.getDimensions(_this6.domNodes.image).height; 778 _this6.controlCoordinates.containerWidth = _this6.getDimensions(_this6.domNodes.image).width; 779 _this6.controlCoordinates.imgHeight = _this6.getDimensions(_this6.currentImage).height; 780 _this6.controlCoordinates.imgWidth = _this6.getDimensions(_this6.currentImage).width; 781 _this6.controlCoordinates.containerOffsetX = _this6.domNodes.image.offsetLeft; 782 _this6.controlCoordinates.containerOffsetY = _this6.domNodes.image.offsetTop; 783 _this6.controlCoordinates.initialOffsetX = parseFloat(_this6.currentImage.dataset.translateX); 784 _this6.controlCoordinates.initialOffsetY = parseFloat(_this6.currentImage.dataset.translateY); 785 } 786 787 event.preventDefault(); 788 var delta = event.delta || event.wheelDelta; 789 790 if (delta === undefined) { 791 //we are on firefox 792 delta = event.detail; 793 } 794 795 delta = Math.max(-1, Math.min(1, delta)); // cap the delta to [-1,1] for cross browser consistency 796 // apply zoom 797 798 scale += delta * _this6.options.scrollZoomFactor * scale; 799 scale = Math.max(1, Math.min(_this6.options.maxZoom, scale)); 800 _this6.controlCoordinates.targetScale = scale; 801 _this6.controlCoordinates.pinchOffsetX = event.pageX; 802 _this6.controlCoordinates.pinchOffsetY = event.pageY; 803 _this6.controlCoordinates.limitOffsetX = (_this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerWidth) / 2; 804 _this6.controlCoordinates.limitOffsetY = (_this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerHeight) / 2; 805 _this6.controlCoordinates.scaleDifference = _this6.controlCoordinates.targetScale - _this6.controlCoordinates.initialScale; 806 _this6.controlCoordinates.targetOffsetX = _this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerWidth ? 0 : _this6.minMax(_this6.controlCoordinates.initialOffsetX - (_this6.controlCoordinates.pinchOffsetX - _this6.controlCoordinates.containerOffsetX - _this6.controlCoordinates.containerWidth / 2 - _this6.controlCoordinates.initialOffsetX) / (_this6.controlCoordinates.targetScale - _this6.controlCoordinates.scaleDifference) * _this6.controlCoordinates.scaleDifference, _this6.controlCoordinates.limitOffsetX * -1, _this6.controlCoordinates.limitOffsetX); 807 _this6.controlCoordinates.targetOffsetY = _this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerHeight ? 0 : _this6.minMax(_this6.controlCoordinates.initialOffsetY - (_this6.controlCoordinates.pinchOffsetY - _this6.controlCoordinates.containerOffsetY - _this6.controlCoordinates.containerHeight / 2 - _this6.controlCoordinates.initialOffsetY) / (_this6.controlCoordinates.targetScale - _this6.controlCoordinates.scaleDifference) * _this6.controlCoordinates.scaleDifference, _this6.controlCoordinates.limitOffsetY * -1, _this6.controlCoordinates.limitOffsetY); 808 809 _this6.zoomPanElement(_this6.controlCoordinates.targetOffsetX + "px", _this6.controlCoordinates.targetOffsetY + "px", _this6.controlCoordinates.targetScale); 810 811 if (_this6.controlCoordinates.targetScale > 1) { 812 _this6.controlCoordinates.zoomed = true; 813 814 if ((!_this6.domNodes.caption.style.opacity || _this6.domNodes.caption.style.opacity > 0) && _this6.domNodes.caption.style.display !== 'none') { 815 _this6.fadeOut(_this6.domNodes.caption, _this6.options.fadeSpeed); 816 } 817 } else { 818 if (_this6.controlCoordinates.initialScale === 1) { 819 _this6.controlCoordinates.zoomed = false; 820 821 if (_this6.domNodes.caption.style.display === 'none') { 822 _this6.fadeIn(_this6.domNodes.caption, _this6.options.fadeSpeed); 823 } 824 } 825 826 _this6.controlCoordinates.initialPinchDistance = null; 827 _this6.controlCoordinates.capture = false; 828 } 829 830 _this6.controlCoordinates.initialPinchDistance = _this6.controlCoordinates.targetPinchDistance; 831 _this6.controlCoordinates.initialScale = _this6.controlCoordinates.targetScale; 832 _this6.controlCoordinates.initialOffsetX = _this6.controlCoordinates.targetOffsetX; 833 _this6.controlCoordinates.initialOffsetY = _this6.controlCoordinates.targetOffsetY; 834 835 _this6.setZoomData(_this6.controlCoordinates.targetScale, _this6.controlCoordinates.targetOffsetX, _this6.controlCoordinates.targetOffsetY); 836 837 _this6.zoomPanElement(_this6.controlCoordinates.targetOffsetX + "px", _this6.controlCoordinates.targetOffsetY + "px", _this6.controlCoordinates.targetScale); 838 }); 839 } 840 841 this.addEventListener(this.domNodes.image, ['touchstart.' + this.eventNamespace, 'mousedown.' + this.eventNamespace], function (event) { 842 if (event.target.tagName === 'A' && event.type === 'touchstart') { 843 return true; 844 } 845 846 if (event.type === 'mousedown') { 847 event.preventDefault(); 848 _this6.controlCoordinates.initialPointerOffsetX = event.clientX; 849 _this6.controlCoordinates.initialPointerOffsetY = event.clientY; 850 _this6.controlCoordinates.containerHeight = _this6.getDimensions(_this6.domNodes.image).height; 851 _this6.controlCoordinates.containerWidth = _this6.getDimensions(_this6.domNodes.image).width; 852 _this6.controlCoordinates.imgHeight = _this6.getDimensions(_this6.currentImage).height; 853 _this6.controlCoordinates.imgWidth = _this6.getDimensions(_this6.currentImage).width; 854 _this6.controlCoordinates.containerOffsetX = _this6.domNodes.image.offsetLeft; 855 _this6.controlCoordinates.containerOffsetY = _this6.domNodes.image.offsetTop; 856 _this6.controlCoordinates.initialOffsetX = parseFloat(_this6.currentImage.dataset.translateX); 857 _this6.controlCoordinates.initialOffsetY = parseFloat(_this6.currentImage.dataset.translateY); 858 _this6.controlCoordinates.capture = true; 859 } else { 860 _this6.controlCoordinates.touchCount = event.touches.length; 861 _this6.controlCoordinates.initialPointerOffsetX = event.touches[0].clientX; 862 _this6.controlCoordinates.initialPointerOffsetY = event.touches[0].clientY; 863 _this6.controlCoordinates.containerHeight = _this6.getDimensions(_this6.domNodes.image).height; 864 _this6.controlCoordinates.containerWidth = _this6.getDimensions(_this6.domNodes.image).width; 865 _this6.controlCoordinates.imgHeight = _this6.getDimensions(_this6.currentImage).height; 866 _this6.controlCoordinates.imgWidth = _this6.getDimensions(_this6.currentImage).width; 867 _this6.controlCoordinates.containerOffsetX = _this6.domNodes.image.offsetLeft; 868 _this6.controlCoordinates.containerOffsetY = _this6.domNodes.image.offsetTop; 869 870 if (_this6.controlCoordinates.touchCount === 1) 871 /* Single touch */ 872 { 873 if (!_this6.controlCoordinates.doubleTapped) { 874 _this6.controlCoordinates.doubleTapped = true; 875 setTimeout(function () { 876 _this6.controlCoordinates.doubleTapped = false; 877 }, 300); 878 } else { 879 _this6.currentImage.classList.add('sl-transition'); 880 881 if (!_this6.controlCoordinates.zoomed) { 882 _this6.controlCoordinates.initialScale = _this6.options.doubleTapZoom; 883 884 _this6.setZoomData(_this6.controlCoordinates.initialScale, 0, 0); 885 886 _this6.zoomPanElement(0 + "px", 0 + "px", _this6.controlCoordinates.initialScale); 887 888 if ((!_this6.domNodes.caption.style.opacity || _this6.domNodes.caption.style.opacity > 0) && _this6.domNodes.caption.style.display !== 'none') { 889 _this6.fadeOut(_this6.domNodes.caption, _this6.options.fadeSpeed); 890 } 891 892 _this6.controlCoordinates.zoomed = true; 893 } else { 894 _this6.controlCoordinates.initialScale = 1; 895 896 _this6.setZoomData(_this6.controlCoordinates.initialScale, 0, 0); 897 898 _this6.zoomPanElement(0 + "px", 0 + "px", _this6.controlCoordinates.initialScale); 899 900 _this6.controlCoordinates.zoomed = false; 901 } 902 903 setTimeout(function () { 904 if (_this6.currentImage) { 905 _this6.currentImage.classList.remove('sl-transition'); 906 } 907 }, 200); 908 return false; 909 } 910 911 _this6.controlCoordinates.initialOffsetX = parseFloat(_this6.currentImage.dataset.translateX); 912 _this6.controlCoordinates.initialOffsetY = parseFloat(_this6.currentImage.dataset.translateY); 913 } else if (_this6.controlCoordinates.touchCount === 2) 914 /* Pinch */ 915 { 916 _this6.controlCoordinates.initialPointerOffsetX2 = event.touches[1].clientX; 917 _this6.controlCoordinates.initialPointerOffsetY2 = event.touches[1].clientY; 918 _this6.controlCoordinates.initialOffsetX = parseFloat(_this6.currentImage.dataset.translateX); 919 _this6.controlCoordinates.initialOffsetY = parseFloat(_this6.currentImage.dataset.translateY); 920 _this6.controlCoordinates.pinchOffsetX = (_this6.controlCoordinates.initialPointerOffsetX + _this6.controlCoordinates.initialPointerOffsetX2) / 2; 921 _this6.controlCoordinates.pinchOffsetY = (_this6.controlCoordinates.initialPointerOffsetY + _this6.controlCoordinates.initialPointerOffsetY2) / 2; 922 _this6.controlCoordinates.initialPinchDistance = Math.sqrt((_this6.controlCoordinates.initialPointerOffsetX - _this6.controlCoordinates.initialPointerOffsetX2) * (_this6.controlCoordinates.initialPointerOffsetX - _this6.controlCoordinates.initialPointerOffsetX2) + (_this6.controlCoordinates.initialPointerOffsetY - _this6.controlCoordinates.initialPointerOffsetY2) * (_this6.controlCoordinates.initialPointerOffsetY - _this6.controlCoordinates.initialPointerOffsetY2)); 923 } 924 925 _this6.controlCoordinates.capture = true; 926 } 927 928 if (_this6.controlCoordinates.mousedown) return true; 929 930 if (_this6.transitionCapable) { 931 _this6.controlCoordinates.imageLeft = parseInt(_this6.domNodes.image.style.left, 10); 932 } 933 934 _this6.controlCoordinates.mousedown = true; 935 _this6.controlCoordinates.swipeDiff = 0; 936 _this6.controlCoordinates.swipeYDiff = 0; 937 _this6.controlCoordinates.swipeStart = event.pageX || event.touches[0].pageX; 938 _this6.controlCoordinates.swipeYStart = event.pageY || event.touches[0].pageY; 939 return false; 940 }); 941 this.addEventListener(this.domNodes.image, ['touchmove.' + this.eventNamespace, 'mousemove.' + this.eventNamespace, 'MSPointerMove'], function (event) { 942 if (!_this6.controlCoordinates.mousedown) { 943 return true; 944 } 945 946 if (event.type === 'touchmove') { 947 if (_this6.controlCoordinates.capture === false) { 948 return false; 949 } 950 951 _this6.controlCoordinates.pointerOffsetX = event.touches[0].clientX; 952 _this6.controlCoordinates.pointerOffsetY = event.touches[0].clientY; 953 _this6.controlCoordinates.touchCount = event.touches.length; 954 _this6.controlCoordinates.touchmoveCount++; 955 956 if (_this6.controlCoordinates.touchCount > 1) 957 /* Pinch */ 958 { 959 _this6.controlCoordinates.pointerOffsetX2 = event.touches[1].clientX; 960 _this6.controlCoordinates.pointerOffsetY2 = event.touches[1].clientY; 961 _this6.controlCoordinates.targetPinchDistance = Math.sqrt((_this6.controlCoordinates.pointerOffsetX - _this6.controlCoordinates.pointerOffsetX2) * (_this6.controlCoordinates.pointerOffsetX - _this6.controlCoordinates.pointerOffsetX2) + (_this6.controlCoordinates.pointerOffsetY - _this6.controlCoordinates.pointerOffsetY2) * (_this6.controlCoordinates.pointerOffsetY - _this6.controlCoordinates.pointerOffsetY2)); 962 963 if (_this6.controlCoordinates.initialPinchDistance === null) { 964 _this6.controlCoordinates.initialPinchDistance = _this6.controlCoordinates.targetPinchDistance; 965 } 966 967 if (Math.abs(_this6.controlCoordinates.initialPinchDistance - _this6.controlCoordinates.targetPinchDistance) >= 1) { 968 /* Initialize helpers */ 969 _this6.controlCoordinates.targetScale = _this6.minMax(_this6.controlCoordinates.targetPinchDistance / _this6.controlCoordinates.initialPinchDistance * _this6.controlCoordinates.initialScale, 1, _this6.options.maxZoom); 970 _this6.controlCoordinates.limitOffsetX = (_this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerWidth) / 2; 971 _this6.controlCoordinates.limitOffsetY = (_this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerHeight) / 2; 972 _this6.controlCoordinates.scaleDifference = _this6.controlCoordinates.targetScale - _this6.controlCoordinates.initialScale; 973 _this6.controlCoordinates.targetOffsetX = _this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerWidth ? 0 : _this6.minMax(_this6.controlCoordinates.initialOffsetX - (_this6.controlCoordinates.pinchOffsetX - _this6.controlCoordinates.containerOffsetX - _this6.controlCoordinates.containerWidth / 2 - _this6.controlCoordinates.initialOffsetX) / (_this6.controlCoordinates.targetScale - _this6.controlCoordinates.scaleDifference) * _this6.controlCoordinates.scaleDifference, _this6.controlCoordinates.limitOffsetX * -1, _this6.controlCoordinates.limitOffsetX); 974 _this6.controlCoordinates.targetOffsetY = _this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerHeight ? 0 : _this6.minMax(_this6.controlCoordinates.initialOffsetY - (_this6.controlCoordinates.pinchOffsetY - _this6.controlCoordinates.containerOffsetY - _this6.controlCoordinates.containerHeight / 2 - _this6.controlCoordinates.initialOffsetY) / (_this6.controlCoordinates.targetScale - _this6.controlCoordinates.scaleDifference) * _this6.controlCoordinates.scaleDifference, _this6.controlCoordinates.limitOffsetY * -1, _this6.controlCoordinates.limitOffsetY); 975 976 _this6.zoomPanElement(_this6.controlCoordinates.targetOffsetX + "px", _this6.controlCoordinates.targetOffsetY + "px", _this6.controlCoordinates.targetScale); 977 978 if (_this6.controlCoordinates.targetScale > 1) { 979 _this6.controlCoordinates.zoomed = true; 980 981 if ((!_this6.domNodes.caption.style.opacity || _this6.domNodes.caption.style.opacity > 0) && _this6.domNodes.caption.style.display !== 'none') { 982 _this6.fadeOut(_this6.domNodes.caption, _this6.options.fadeSpeed); 983 } 984 } 985 986 _this6.controlCoordinates.initialPinchDistance = _this6.controlCoordinates.targetPinchDistance; 987 _this6.controlCoordinates.initialScale = _this6.controlCoordinates.targetScale; 988 _this6.controlCoordinates.initialOffsetX = _this6.controlCoordinates.targetOffsetX; 989 _this6.controlCoordinates.initialOffsetY = _this6.controlCoordinates.targetOffsetY; 990 } 991 } else { 992 _this6.controlCoordinates.targetScale = _this6.controlCoordinates.initialScale; 993 _this6.controlCoordinates.limitOffsetX = (_this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerWidth) / 2; 994 _this6.controlCoordinates.limitOffsetY = (_this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerHeight) / 2; 995 _this6.controlCoordinates.targetOffsetX = _this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerWidth ? 0 : _this6.minMax(_this6.controlCoordinates.pointerOffsetX - (_this6.controlCoordinates.initialPointerOffsetX - _this6.controlCoordinates.initialOffsetX), _this6.controlCoordinates.limitOffsetX * -1, _this6.controlCoordinates.limitOffsetX); 996 _this6.controlCoordinates.targetOffsetY = _this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerHeight ? 0 : _this6.minMax(_this6.controlCoordinates.pointerOffsetY - (_this6.controlCoordinates.initialPointerOffsetY - _this6.controlCoordinates.initialOffsetY), _this6.controlCoordinates.limitOffsetY * -1, _this6.controlCoordinates.limitOffsetY); 997 998 if (Math.abs(_this6.controlCoordinates.targetOffsetX) === Math.abs(_this6.controlCoordinates.limitOffsetX)) { 999 _this6.controlCoordinates.initialOffsetX = _this6.controlCoordinates.targetOffsetX; 1000 _this6.controlCoordinates.initialPointerOffsetX = _this6.controlCoordinates.pointerOffsetX; 1001 } 1002 1003 if (Math.abs(_this6.controlCoordinates.targetOffsetY) === Math.abs(_this6.controlCoordinates.limitOffsetY)) { 1004 _this6.controlCoordinates.initialOffsetY = _this6.controlCoordinates.targetOffsetY; 1005 _this6.controlCoordinates.initialPointerOffsetY = _this6.controlCoordinates.pointerOffsetY; 1006 } 1007 1008 _this6.setZoomData(_this6.controlCoordinates.initialScale, _this6.controlCoordinates.targetOffsetX, _this6.controlCoordinates.targetOffsetY); 1009 1010 _this6.zoomPanElement(_this6.controlCoordinates.targetOffsetX + "px", _this6.controlCoordinates.targetOffsetY + "px", _this6.controlCoordinates.targetScale); 1011 } 1012 } 1013 /* Mouse Move implementation */ 1014 1015 1016 if (event.type === 'mousemove' && _this6.controlCoordinates.mousedown) { 1017 if (event.type == 'touchmove') return true; 1018 event.preventDefault(); 1019 if (_this6.controlCoordinates.capture === false) return false; 1020 _this6.controlCoordinates.pointerOffsetX = event.clientX; 1021 _this6.controlCoordinates.pointerOffsetY = event.clientY; 1022 _this6.controlCoordinates.targetScale = _this6.controlCoordinates.initialScale; 1023 _this6.controlCoordinates.limitOffsetX = (_this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerWidth) / 2; 1024 _this6.controlCoordinates.limitOffsetY = (_this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale - _this6.controlCoordinates.containerHeight) / 2; 1025 _this6.controlCoordinates.targetOffsetX = _this6.controlCoordinates.imgWidth * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerWidth ? 0 : _this6.minMax(_this6.controlCoordinates.pointerOffsetX - (_this6.controlCoordinates.initialPointerOffsetX - _this6.controlCoordinates.initialOffsetX), _this6.controlCoordinates.limitOffsetX * -1, _this6.controlCoordinates.limitOffsetX); 1026 _this6.controlCoordinates.targetOffsetY = _this6.controlCoordinates.imgHeight * _this6.controlCoordinates.targetScale <= _this6.controlCoordinates.containerHeight ? 0 : _this6.minMax(_this6.controlCoordinates.pointerOffsetY - (_this6.controlCoordinates.initialPointerOffsetY - _this6.controlCoordinates.initialOffsetY), _this6.controlCoordinates.limitOffsetY * -1, _this6.controlCoordinates.limitOffsetY); 1027 1028 if (Math.abs(_this6.controlCoordinates.targetOffsetX) === Math.abs(_this6.controlCoordinates.limitOffsetX)) { 1029 _this6.controlCoordinates.initialOffsetX = _this6.controlCoordinates.targetOffsetX; 1030 _this6.controlCoordinates.initialPointerOffsetX = _this6.controlCoordinates.pointerOffsetX; 1031 } 1032 1033 if (Math.abs(_this6.controlCoordinates.targetOffsetY) === Math.abs(_this6.controlCoordinates.limitOffsetY)) { 1034 _this6.controlCoordinates.initialOffsetY = _this6.controlCoordinates.targetOffsetY; 1035 _this6.controlCoordinates.initialPointerOffsetY = _this6.controlCoordinates.pointerOffsetY; 1036 } 1037 1038 _this6.setZoomData(_this6.controlCoordinates.initialScale, _this6.controlCoordinates.targetOffsetX, _this6.controlCoordinates.targetOffsetY); 1039 1040 _this6.zoomPanElement(_this6.controlCoordinates.targetOffsetX + "px", _this6.controlCoordinates.targetOffsetY + "px", _this6.controlCoordinates.targetScale); 1041 } 1042 1043 if (!_this6.controlCoordinates.zoomed) { 1044 _this6.controlCoordinates.swipeEnd = event.pageX || event.touches[0].pageX; 1045 _this6.controlCoordinates.swipeYEnd = event.pageY || event.touches[0].pageY; 1046 _this6.controlCoordinates.swipeDiff = _this6.controlCoordinates.swipeStart - _this6.controlCoordinates.swipeEnd; 1047 _this6.controlCoordinates.swipeYDiff = _this6.controlCoordinates.swipeYStart - _this6.controlCoordinates.swipeYEnd; 1048 1049 if (_this6.options.animationSlide) { 1050 _this6.slide(0, -_this6.controlCoordinates.swipeDiff + 'px'); 1051 } 1052 } 1053 }); 1054 this.addEventListener(this.domNodes.image, ['touchend.' + this.eventNamespace, 'mouseup.' + this.eventNamespace, 'touchcancel.' + this.eventNamespace, 'mouseleave.' + this.eventNamespace, 'pointerup', 'pointercancel', 'MSPointerUp', 'MSPointerCancel'], function (event) { 1055 if (_this6.isTouchDevice && event.type === 'touchend') { 1056 _this6.controlCoordinates.touchCount = event.touches.length; 1057 1058 if (_this6.controlCoordinates.touchCount === 0) 1059 /* No touch */ 1060 { 1061 /* Set attributes */ 1062 if (_this6.currentImage) { 1063 _this6.setZoomData(_this6.controlCoordinates.initialScale, _this6.controlCoordinates.targetOffsetX, _this6.controlCoordinates.targetOffsetY); 1064 } 1065 1066 if (_this6.controlCoordinates.initialScale === 1) { 1067 _this6.controlCoordinates.zoomed = false; 1068 1069 if (_this6.domNodes.caption.style.display === 'none') { 1070 _this6.fadeIn(_this6.domNodes.caption, _this6.options.fadeSpeed); 1071 } 1072 } 1073 1074 _this6.controlCoordinates.initialPinchDistance = null; 1075 _this6.controlCoordinates.capture = false; 1076 } else if (_this6.controlCoordinates.touchCount === 1) 1077 /* Single touch */ 1078 { 1079 _this6.controlCoordinates.initialPointerOffsetX = event.touches[0].clientX; 1080 _this6.controlCoordinates.initialPointerOffsetY = event.touches[0].clientY; 1081 } else if (_this6.controlCoordinates.touchCount > 1) 1082 /* Pinch */ 1083 { 1084 _this6.controlCoordinates.initialPinchDistance = null; 1085 } 1086 } 1087 1088 if (_this6.controlCoordinates.mousedown) { 1089 _this6.controlCoordinates.mousedown = false; 1090 var possibleDir = true; 1091 1092 if (!_this6.options.loop) { 1093 if (_this6.currentImageIndex === 0 && _this6.controlCoordinates.swipeDiff < 0) { 1094 possibleDir = false; 1095 } 1096 1097 if (_this6.currentImageIndex >= _this6.relatedElements.length - 1 && _this6.controlCoordinates.swipeDiff > 0) { 1098 possibleDir = false; 1099 } 1100 } 1101 1102 if (Math.abs(_this6.controlCoordinates.swipeDiff) > _this6.options.swipeTolerance && possibleDir) { 1103 _this6.loadImage(_this6.controlCoordinates.swipeDiff > 0 ? 1 : -1); 1104 } else if (_this6.options.animationSlide) { 1105 _this6.slide(_this6.options.animationSpeed / 1000, 0 + 'px'); 1106 } 1107 1108 if (_this6.options.swipeClose && Math.abs(_this6.controlCoordinates.swipeYDiff) > 50 && Math.abs(_this6.controlCoordinates.swipeDiff) < _this6.options.swipeTolerance) { 1109 _this6.close(); 1110 } 1111 } 1112 }); 1113 this.addEventListener(this.domNodes.image, ['dblclick'], function (event) { 1114 if (_this6.isTouchDevice) return; 1115 _this6.controlCoordinates.initialPointerOffsetX = event.clientX; 1116 _this6.controlCoordinates.initialPointerOffsetY = event.clientY; 1117 _this6.controlCoordinates.containerHeight = _this6.getDimensions(_this6.domNodes.image).height; 1118 _this6.controlCoordinates.containerWidth = _this6.getDimensions(_this6.domNodes.image).width; 1119 _this6.controlCoordinates.imgHeight = _this6.getDimensions(_this6.currentImage).height; 1120 _this6.controlCoordinates.imgWidth = _this6.getDimensions(_this6.currentImage).width; 1121 _this6.controlCoordinates.containerOffsetX = _this6.domNodes.image.offsetLeft; 1122 _this6.controlCoordinates.containerOffsetY = _this6.domNodes.image.offsetTop; 1123 1124 _this6.currentImage.classList.add('sl-transition'); 1125 1126 if (!_this6.controlCoordinates.zoomed) { 1127 _this6.controlCoordinates.initialScale = _this6.options.doubleTapZoom; 1128 1129 _this6.setZoomData(_this6.controlCoordinates.initialScale, 0, 0); 1130 1131 _this6.zoomPanElement(0 + "px", 0 + "px", _this6.controlCoordinates.initialScale); 1132 1133 if ((!_this6.domNodes.caption.style.opacity || _this6.domNodes.caption.style.opacity > 0) && _this6.domNodes.caption.style.display !== 'none') { 1134 _this6.fadeOut(_this6.domNodes.caption, _this6.options.fadeSpeed); 1135 } 1136 1137 _this6.controlCoordinates.zoomed = true; 1138 } else { 1139 _this6.controlCoordinates.initialScale = 1; 1140 1141 _this6.setZoomData(_this6.controlCoordinates.initialScale, 0, 0); 1142 1143 _this6.zoomPanElement(0 + "px", 0 + "px", _this6.controlCoordinates.initialScale); 1144 1145 _this6.controlCoordinates.zoomed = false; 1146 1147 if (_this6.domNodes.caption.style.display === 'none') { 1148 _this6.fadeIn(_this6.domNodes.caption, _this6.options.fadeSpeed); 1149 } 1150 } 1151 1152 setTimeout(function () { 1153 if (_this6.currentImage) { 1154 _this6.currentImage.classList.remove('sl-transition'); 1155 1156 _this6.currentImage.style[_this6.transitionPrefix + 'transform-origin'] = null; 1157 } 1158 }, 200); 1159 _this6.controlCoordinates.capture = true; 1160 return false; 1161 }); 1162 } 1163 }, { 1164 key: "getDimensions", 1165 value: function getDimensions(element) { 1166 var styles = window.getComputedStyle(element), 1167 height = element.offsetHeight, 1168 width = element.offsetWidth, 1169 borderTopWidth = parseFloat(styles.borderTopWidth), 1170 borderBottomWidth = parseFloat(styles.borderBottomWidth), 1171 paddingTop = parseFloat(styles.paddingTop), 1172 paddingBottom = parseFloat(styles.paddingBottom), 1173 borderLeftWidth = parseFloat(styles.borderLeftWidth), 1174 borderRightWidth = parseFloat(styles.borderRightWidth), 1175 paddingLeft = parseFloat(styles.paddingLeft), 1176 paddingRight = parseFloat(styles.paddingRight); 1177 return { 1178 height: height - borderBottomWidth - borderTopWidth - paddingTop - paddingBottom, 1179 width: width - borderLeftWidth - borderRightWidth - paddingLeft - paddingRight 1180 }; 1181 } 1182 }, { 1183 key: "updateHash", 1184 value: function updateHash() { 1185 var newHash = 'pid=' + (this.currentImageIndex + 1), 1186 newURL = window.location.href.split('#')[0] + '#' + newHash; 1187 this.hashReseted = false; 1188 1189 if (this.pushStateSupport) { 1190 window.history[this.historyHasChanges ? 'replaceState' : 'pushState']('', document.title, newURL); 1191 } else { 1192 // what is the browser target of this? 1193 if (this.historyHasChanges) { 1194 window.location.replace(newURL); 1195 } else { 1196 window.location.hash = newHash; 1197 } 1198 } 1199 1200 if (!this.historyHasChanges) { 1201 this.urlChangedOnce = true; 1202 } 1203 1204 this.historyHasChanges = true; 1205 } 1206 }, { 1207 key: "resetHash", 1208 value: function resetHash() { 1209 this.hashReseted = true; 1210 1211 if (this.urlChangedOnce) { 1212 history.back(); 1213 } else { 1214 if (this.pushStateSupport) { 1215 history.pushState('', document.title, window.location.pathname + window.location.search); 1216 } else { 1217 window.location.hash = ''; 1218 } 1219 } // 1220 //in case an history operation is still pending 1221 1222 1223 clearTimeout(this.historyUpdateTimeout); 1224 } 1225 }, { 1226 key: "updateURL", 1227 value: function updateURL() { 1228 clearTimeout(this.historyUpdateTimeout); 1229 1230 if (!this.historyHasChanges) { 1231 this.updateHash(); // first time 1232 } else { 1233 this.historyUpdateTimeout = setTimeout(this.updateHash.bind(this), 800); 1234 } 1235 } 1236 }, { 1237 key: "setCaption", 1238 value: function setCaption(captionText, imageWidth) { 1239 var _this7 = this; 1240 1241 if (this.options.captions && captionText && captionText !== '' && typeof captionText !== "undefined") { 1242 this.hide(this.domNodes.caption); 1243 this.domNodes.caption.style.width = imageWidth + 'px'; 1244 this.domNodes.caption.innerHTML = captionText; 1245 this.domNodes.image.appendChild(this.domNodes.caption); 1246 setTimeout(function () { 1247 _this7.fadeIn(_this7.domNodes.caption, _this7.options.fadeSpeed); 1248 }, this.options.captionDelay); 1249 } 1250 } 1251 }, { 1252 key: "slide", 1253 value: function slide(speed, pos) { 1254 if (!this.transitionCapable) { 1255 return this.domNodes.image.style.left = pos; 1256 } 1257 1258 this.domNodes.image.style[this.transitionPrefix + 'transform'] = 'translateX(' + pos + ')'; 1259 this.domNodes.image.style[this.transitionPrefix + 'transition'] = this.transitionPrefix + 'transform ' + speed + 's linear'; 1260 } 1261 }, { 1262 key: "getRelated", 1263 value: function getRelated(rel) { 1264 var elems; 1265 1266 if (rel && rel !== false && rel !== 'nofollow') { 1267 elems = Array.from(this.elements).filter(function (element) { 1268 return element.getAttribute('rel') === rel; 1269 }); 1270 } else { 1271 elems = this.elements; 1272 } 1273 1274 return elems; 1275 } 1276 }, { 1277 key: "openImage", 1278 value: function openImage(element) { 1279 var _this8 = this; 1280 1281 element.dispatchEvent(new Event('show.' + this.eventNamespace)); 1282 1283 if (this.options.disableScroll) { 1284 this.globalScrollbarWidth = this.toggleScrollbar('hide'); 1285 } 1286 1287 if (this.options.htmlClass && this.options.htmlClass !== '') { 1288 document.querySelector('html').classList.add(this.options.htmlClass); 1289 } 1290 1291 document.body.appendChild(this.domNodes.wrapper); 1292 this.domNodes.wrapper.appendChild(this.domNodes.image); 1293 1294 if (this.options.overlay) { 1295 document.body.appendChild(this.domNodes.overlay); 1296 } 1297 1298 this.relatedElements = this.getRelated(element.rel); 1299 1300 if (this.options.showCounter) { 1301 if (this.relatedElements.length == 1 && this.domNodes.wrapper.contains(this.domNodes.counter)) { 1302 this.domNodes.wrapper.removeChild(this.domNodes.counter); 1303 } else if (this.relatedElements.length > 1 && !this.domNodes.wrapper.contains(this.domNodes.counter)) { 1304 this.domNodes.wrapper.appendChild(this.domNodes.counter); 1305 } 1306 } 1307 1308 this.isAnimating = true; 1309 this.currentImageIndex = this.relatedElements.indexOf(element); 1310 var targetURL = element.getAttribute(this.options.sourceAttr); 1311 this.currentImage = document.createElement('img'); 1312 this.currentImage.style.display = 'none'; 1313 this.currentImage.setAttribute('src', targetURL); 1314 this.currentImage.dataset.scale = 1; 1315 this.currentImage.dataset.translateX = 0; 1316 this.currentImage.dataset.translateY = 0; 1317 1318 if (this.loadedImages.indexOf(targetURL) === -1) { 1319 this.loadedImages.push(targetURL); 1320 } 1321 1322 this.domNodes.image.innerHTML = ''; 1323 this.domNodes.image.setAttribute('style', ''); 1324 this.domNodes.image.appendChild(this.currentImage); 1325 this.fadeIn(this.domNodes.overlay, this.options.fadeSpeed); 1326 this.fadeIn([this.domNodes.counter, this.domNodes.navigation, this.domNodes.closeButton], this.options.fadeSpeed); 1327 this.show(this.domNodes.spinner); 1328 this.domNodes.counter.querySelector('.sl-current').innerHTML = this.currentImageIndex + 1; 1329 this.domNodes.counter.querySelector('.sl-total').innerHTML = this.relatedElements.length; 1330 this.adjustImage(); 1331 1332 if (this.options.preloading) { 1333 this.preload(); 1334 } 1335 1336 setTimeout(function () { 1337 element.dispatchEvent(new Event('shown.' + _this8.eventNamespace)); 1338 }, this.options.animationSpeed); 1339 } 1340 }, { 1341 key: "forceFocus", 1342 value: function forceFocus() { 1343 var _this9 = this; 1344 1345 this.removeEventListener(document, 'focusin.' + this.eventNamespace); 1346 this.addEventListener(document, 'focusin.' + this.eventNamespace, function (event) { 1347 if (document !== event.target && _this9.domNodes.wrapper !== event.target && !_this9.domNodes.wrapper.contains(event.target)) { 1348 _this9.domNodes.wrapper.focus(); 1349 } 1350 }); 1351 } // utility 1352 1353 }, { 1354 key: "addEventListener", 1355 value: function addEventListener(elements, events, callback, opts) { 1356 elements = this.wrap(elements); 1357 events = this.wrap(events); 1358 1359 var _iterator = _createForOfIteratorHelper(elements), 1360 _step; 1361 1362 try { 1363 for (_iterator.s(); !(_step = _iterator.n()).done;) { 1364 var element = _step.value; 1365 1366 if (!element.namespaces) { 1367 element.namespaces = {}; 1368 } // save the namespaces addEventListener the DOM element itself 1369 1370 1371 var _iterator2 = _createForOfIteratorHelper(events), 1372 _step2; 1373 1374 try { 1375 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { 1376 var event = _step2.value; 1377 var options = opts || false; 1378 var needsPassiveFix = ['touchstart', 'touchmove'].indexOf(event.split('.')[0]) >= 0; 1379 1380 if (needsPassiveFix && this.isPassiveEventsSupported) { 1381 if (_typeof(options) === 'object') { 1382 options.passive = true; 1383 } else { 1384 options = { 1385 passive: true 1386 }; 1387 } 1388 } 1389 1390 element.namespaces[event] = callback; 1391 element.addEventListener(event.split('.')[0], callback, options); 1392 } 1393 } catch (err) { 1394 _iterator2.e(err); 1395 } finally { 1396 _iterator2.f(); 1397 } 1398 } 1399 } catch (err) { 1400 _iterator.e(err); 1401 } finally { 1402 _iterator.f(); 1403 } 1404 } 1405 }, { 1406 key: "removeEventListener", 1407 value: function removeEventListener(elements, events) { 1408 elements = this.wrap(elements); 1409 events = this.wrap(events); 1410 1411 var _iterator3 = _createForOfIteratorHelper(elements), 1412 _step3; 1413 1414 try { 1415 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { 1416 var element = _step3.value; 1417 1418 var _iterator4 = _createForOfIteratorHelper(events), 1419 _step4; 1420 1421 try { 1422 for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { 1423 var event = _step4.value; 1424 1425 if (element.namespaces && element.namespaces[event]) { 1426 element.removeEventListener(event.split('.')[0], element.namespaces[event]); 1427 delete element.namespaces[event]; 1428 } 1429 } 1430 } catch (err) { 1431 _iterator4.e(err); 1432 } finally { 1433 _iterator4.f(); 1434 } 1435 } 1436 } catch (err) { 1437 _iterator3.e(err); 1438 } finally { 1439 _iterator3.f(); 1440 } 1441 } 1442 }, { 1443 key: "fadeOut", 1444 value: function fadeOut(elements, duration, callback) { 1445 var _this10 = this; 1446 1447 elements = this.wrap(elements); 1448 1449 var _iterator5 = _createForOfIteratorHelper(elements), 1450 _step5; 1451 1452 try { 1453 for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { 1454 var element = _step5.value; 1455 element.style.opacity = parseFloat(element) || window.getComputedStyle(element).getPropertyValue("opacity"); 1456 } 1457 } catch (err) { 1458 _iterator5.e(err); 1459 } finally { 1460 _iterator5.f(); 1461 } 1462 1463 this.isFadeIn = false; 1464 1465 var step = 16.66666 / (duration || this.options.fadeSpeed), 1466 fade = function fade() { 1467 var currentOpacity = parseFloat(elements[0].style.opacity); 1468 1469 if ((currentOpacity -= step) < 0) { 1470 var _iterator6 = _createForOfIteratorHelper(elements), 1471 _step6; 1472 1473 try { 1474 for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { 1475 var element = _step6.value; 1476 element.style.display = "none"; // element.style.opacity = ''; 1477 1478 element.style.opacity = 1; 1479 } 1480 } catch (err) { 1481 _iterator6.e(err); 1482 } finally { 1483 _iterator6.f(); 1484 } 1485 1486 callback && callback.call(_this10, elements); 1487 } else { 1488 var _iterator7 = _createForOfIteratorHelper(elements), 1489 _step7; 1490 1491 try { 1492 for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { 1493 var _element = _step7.value; 1494 _element.style.opacity = currentOpacity; 1495 } 1496 } catch (err) { 1497 _iterator7.e(err); 1498 } finally { 1499 _iterator7.f(); 1500 } 1501 1502 requestAnimationFrame(fade); 1503 } 1504 }; 1505 1506 fade(); 1507 } 1508 }, { 1509 key: "fadeIn", 1510 value: function fadeIn(elements, duration, callback, display) { 1511 var _this11 = this; 1512 1513 elements = this.wrap(elements); 1514 1515 var _iterator8 = _createForOfIteratorHelper(elements), 1516 _step8; 1517 1518 try { 1519 for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { 1520 var element = _step8.value; 1521 element.style.opacity = 0; 1522 element.style.display = display || "block"; 1523 } 1524 } catch (err) { 1525 _iterator8.e(err); 1526 } finally { 1527 _iterator8.f(); 1528 } 1529 1530 this.isFadeIn = true; 1531 1532 var opacityTarget = parseFloat(elements[0].dataset.opacityTarget || 1), 1533 step = 16.66666 * opacityTarget / (duration || this.options.fadeSpeed), 1534 fade = function fade() { 1535 var currentOpacity = parseFloat(elements[0].style.opacity); 1536 1537 if (!((currentOpacity += step) > opacityTarget)) { 1538 var _iterator9 = _createForOfIteratorHelper(elements), 1539 _step9; 1540 1541 try { 1542 for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { 1543 var element = _step9.value; 1544 element.style.opacity = currentOpacity; 1545 } 1546 } catch (err) { 1547 _iterator9.e(err); 1548 } finally { 1549 _iterator9.f(); 1550 } 1551 1552 if (!_this11.isFadeIn) return; 1553 requestAnimationFrame(fade); 1554 } else { 1555 var _iterator10 = _createForOfIteratorHelper(elements), 1556 _step10; 1557 1558 try { 1559 for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { 1560 var _element2 = _step10.value; 1561 _element2.style.opacity = opacityTarget; 1562 } 1563 } catch (err) { 1564 _iterator10.e(err); 1565 } finally { 1566 _iterator10.f(); 1567 } 1568 1569 callback && callback.call(_this11, elements); 1570 } 1571 }; 1572 1573 fade(); 1574 } 1575 }, { 1576 key: "hide", 1577 value: function hide(elements) { 1578 elements = this.wrap(elements); 1579 1580 var _iterator11 = _createForOfIteratorHelper(elements), 1581 _step11; 1582 1583 try { 1584 for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { 1585 var element = _step11.value; 1586 1587 if (element.style.display != 'none') { 1588 element.dataset.initialDisplay = element.style.display; 1589 } 1590 1591 element.style.display = 'none'; 1592 } 1593 } catch (err) { 1594 _iterator11.e(err); 1595 } finally { 1596 _iterator11.f(); 1597 } 1598 } 1599 }, { 1600 key: "show", 1601 value: function show(elements, display) { 1602 elements = this.wrap(elements); 1603 1604 var _iterator12 = _createForOfIteratorHelper(elements), 1605 _step12; 1606 1607 try { 1608 for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { 1609 var element = _step12.value; 1610 element.style.display = element.dataset.initialDisplay || display || 'block'; 1611 } 1612 } catch (err) { 1613 _iterator12.e(err); 1614 } finally { 1615 _iterator12.f(); 1616 } 1617 } 1618 }, { 1619 key: "wrap", 1620 value: function wrap(input) { 1621 return typeof input[Symbol.iterator] === 'function' && typeof input !== 'string' ? input : [input]; 1622 } 1623 }, { 1624 key: "on", 1625 value: function on(events, callback) { 1626 events = this.wrap(events); 1627 1628 var _iterator13 = _createForOfIteratorHelper(this.elements), 1629 _step13; 1630 1631 try { 1632 for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) { 1633 var element = _step13.value; 1634 1635 if (!element.fullyNamespacedEvents) { 1636 element.fullyNamespacedEvents = {}; 1637 } 1638 1639 var _iterator14 = _createForOfIteratorHelper(events), 1640 _step14; 1641 1642 try { 1643 for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) { 1644 var event = _step14.value; 1645 element.fullyNamespacedEvents[event] = callback; 1646 element.addEventListener(event, callback); 1647 } 1648 } catch (err) { 1649 _iterator14.e(err); 1650 } finally { 1651 _iterator14.f(); 1652 } 1653 } 1654 } catch (err) { 1655 _iterator13.e(err); 1656 } finally { 1657 _iterator13.f(); 1658 } 1659 1660 return this; 1661 } 1662 }, { 1663 key: "off", 1664 value: function off(events) { 1665 events = this.wrap(events); 1666 1667 var _iterator15 = _createForOfIteratorHelper(this.elements), 1668 _step15; 1669 1670 try { 1671 for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) { 1672 var element = _step15.value; 1673 1674 var _iterator16 = _createForOfIteratorHelper(events), 1675 _step16; 1676 1677 try { 1678 for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) { 1679 var event = _step16.value; 1680 1681 if (typeof element.fullyNamespacedEvents !== 'undefined' && event in element.fullyNamespacedEvents) { 1682 element.removeEventListener(event, element.fullyNamespacedEvents[event]); 1683 } 1684 } 1685 } catch (err) { 1686 _iterator16.e(err); 1687 } finally { 1688 _iterator16.f(); 1689 } 1690 } 1691 } catch (err) { 1692 _iterator15.e(err); 1693 } finally { 1694 _iterator15.f(); 1695 } 1696 1697 return this; 1698 } // api 1699 1700 }, { 1701 key: "open", 1702 value: function open(elem) { 1703 elem = elem || this.elements[0]; 1704 1705 if (typeof jQuery !== "undefined" && elem instanceof jQuery) { 1706 elem = elem.get(0); 1707 } 1708 1709 this.initialImageIndex = this.elements.indexOf(elem); 1710 1711 if (this.initialImageIndex > -1) { 1712 this.openImage(elem); 1713 } 1714 } 1715 }, { 1716 key: "next", 1717 value: function next() { 1718 this.loadImage(1); 1719 } 1720 }, { 1721 key: "prev", 1722 value: function prev() { 1723 this.loadImage(-1); 1724 } // get some useful data 1725 1726 }, { 1727 key: "getLighboxData", 1728 value: function getLighboxData() { 1729 return { 1730 currentImageIndex: this.currentImageIndex, 1731 currentImage: this.currentImage, 1732 globalScrollbarWidth: this.globalScrollbarWidth 1733 }; 1734 } //close is exposed anyways.. 1735 1736 }, { 1737 key: "destroy", 1738 value: function destroy() { 1739 //remove all custom event listeners from elements 1740 this.off(['close.' + this.eventNamespace, 'closed.' + this.eventNamespace, 'nextImageLoaded.' + this.eventNamespace, 'prevImageLoaded.' + this.eventNamespace, 'change.' + this.eventNamespace, 'nextDone.' + this.eventNamespace, 'prevDone.' + this.eventNamespace, 'error.' + this.eventNamespace, 'changed.' + this.eventNamespace, 'next.' + this.eventNamespace, 'prev.' + this.eventNamespace, 'show.' + this.eventNamespace, 'shown.' + this.eventNamespace]); 1741 this.removeEventListener(this.elements, 'click.' + this.eventNamespace); 1742 this.removeEventListener(document, 'focusin.' + this.eventNamespace); 1743 this.removeEventListener(document.body, 'contextmenu.' + this.eventNamespace); 1744 this.removeEventListener(document.body, 'keyup.' + this.eventNamespace); 1745 this.removeEventListener(this.domNodes.navigation.getElementsByTagName('button'), 'click.' + this.eventNamespace); 1746 this.removeEventListener(this.domNodes.closeButton, 'click.' + this.eventNamespace); 1747 this.removeEventListener(window, 'resize.' + this.eventNamespace); 1748 this.removeEventListener(window, 'hashchange.' + this.eventNamespace); 1749 this.close(); 1750 1751 if (this.isOpen) { 1752 document.body.removeChild(this.domNodes.wrapper); 1753 document.body.removeChild(this.domNodes.overlay); 1754 } 1755 1756 this.elements = null; 1757 } 1758 }, { 1759 key: "refresh", 1760 value: function refresh() { 1761 if (!this.initialSelector) { 1762 throw 'refreshing only works when you initialize using a selector!'; 1763 } 1764 1765 var options = this.options, 1766 selector = this.initialSelector; 1767 this.destroy(); 1768 this.constructor(selector, options); 1769 return this; 1770 } 1771 }]); 1772 1773 return SimpleLightbox; 1774}(); 1775 1776var _default = SimpleLightbox; 1777exports["default"] = _default; 1778global.SimpleLightbox = SimpleLightbox; 1779 1780}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 1781},{}]},{},[1]);
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.