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