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