vendor: 166,784 bytes, lines 1-5635
1// ================================================== 2// nfancyBox v3.5.8 3// 4// Licensed GPLv3 for open source use 5// or nfancyBox Commercial License for commercial use 6// 7// http://fancyapps.com/nfancybox/ 8// Copyright 2019 fancyApps 9// 10// ================================================== 11(function (window, document, $, undefined) { 12 "use strict"; 13 14 window.console = window.console || { 15 info: function (stuff) {} 16 }; 17 18 // If there's no jQuery, nfancyBox can't work 19 // ========================================= 20 21 if (!$) { 22 return; 23 } 24 25 // Check if nfancyBox is already initialized 26 // ======================================== 27 28 if ($.fn.nfancybox) { 29 console.info("nfancyBox already initialized"); 30 31 return; 32 } 33 34 // Private default settings 35 // ======================== 36 37 var defaults = { 38 // Close existing modals 39 // Set this to false if you do not need to stack multiple instances 40 closeExisting: false, 41 42 // Enable infinite gallery navigation 43 loop: false, 44 45 // Horizontal space between slides 46 gutter: 50, 47 48 // Enable keyboard navigation 49 keyboard: true, 50 51 // Should allow caption to overlap the content 52 preventCaptionOverlap: true, 53 54 // Should display navigation arrows at the screen edges 55 arrows: true, 56 57 // Should display counter at the top left corner 58 infobar: true, 59 60 // Should display close button (using `btnTpl.smallBtn` template) over the content 61 // Can be true, false, "auto" 62 // If "auto" - will be automatically enabled for "html", "inline" or "ajax" items 63 smallBtn: "auto", 64 65 // Should display toolbar (buttons at the top) 66 // Can be true, false, "auto" 67 // If "auto" - will be automatically hidden if "smallBtn" is enabled 68 toolbar: "auto", 69 70 // What buttons should appear in the top right corner. 71 // Buttons will be created using templates from `btnTpl` option 72 // and they will be placed into toolbar (class="nfancybox-toolbar"` element) 73 buttons: [ 74 "zoom", 75 //"share", 76 "slideShow", 77 //"fullScreen", 78 //"download", 79 "thumbs", 80 "close" 81 ], 82 83 // Detect "idle" time in seconds 84 idleTime: 3, 85 86 // Disable right-click and use simple image protection for images 87 protect: false, 88 89 // Shortcut to make content "modal" - disable keyboard navigtion, hide buttons, etc 90 modal: false, 91 92 image: { 93 // Wait for images to load before displaying 94 // true - wait for image to load and then display; 95 // false - display thumbnail and load the full-sized image over top, 96 // requires predefined image dimensions (`data-width` and `data-height` attributes) 97 preload: false 98 }, 99 100 ajax: { 101 // Object containing settings for ajax request 102 settings: { 103 // This helps to indicate that request comes from the modal 104 // Feel free to change naming 105 data: { 106 nfancybox: true 107 } 108 } 109 }, 110 111 iframe: { 112 // Iframe template 113 tpl: '<iframe id="nfancybox-frame{rnd}" name="nfancybox-frame{rnd}" class="nfancybox-iframe" allowfullscreen="allowfullscreen" allow="autoplay; fullscreen" src="" referrerpolicy="strict-origin-when-cross-origin"></iframe>', 114 115 // Preload iframe before displaying it 116 // This allows to calculate iframe content width and height 117 // (note: Due to "Same Origin Policy", you can't get cross domain data). 118 preload: true, 119 120 // Custom CSS styling for iframe wrapping element 121 // You can use this to set custom iframe dimensions 122 css: {}, 123 124 // Iframe tag attributes 125 attr: { 126 scrolling: "auto" 127 } 128 }, 129 130 // For HTML5 video only 131 video: { 132 tpl: '<video class="nfancybox-video" controls controlsList="nodownload" poster="{{poster}}" src="{{src}}">' + 133 '<source src="{{src}}" type="{{format}}" />' + 134 'Sorry, your browser doesn\'t support embedded videos, <a href="{{src}}">download</a> and watch with your favorite video player!' + 135 "</video>", 136 format: "", // custom video format 137 autoStart: true 138 }, 139 140 // Default content type if cannot be detected automatically 141 defaultType: "image", 142 143 // Open/close animation type 144 // Possible values: 145 // false - disable 146 // "zoom" - zoom images from/to thumbnail 147 // "fade" 148 // "zoom-in-out" 149 // 150 animationEffect: "zoom", 151 152 // Duration in ms for open/close animation 153 animationDuration: 366, 154 155 // Should image change opacity while zooming 156 // If opacity is "auto", then opacity will be changed if image and thumbnail have different aspect ratios 157 zoomOpacity: "auto", 158 159 // Transition effect between slides 160 // 161 // Possible values: 162 // false - disable 163 // "fade' 164 // "slide' 165 // "circular' 166 // "tube' 167 // "zoom-in-out' 168 // "rotate' 169 // 170 transitionEffect: "fade", 171 172 // Duration in ms for transition animation 173 transitionDuration: 366, 174 175 // Custom CSS class for slide element 176 slideClass: "", 177 178 // Custom CSS class for layout 179 baseClass: "", 180 181 // Base template for layout 182 baseTpl: '<div class="nfancybox-container" role="dialog" tabindex="-1">' + 183 '<div class="nfancybox-bg"></div>' + 184 '<div class="nfancybox-inner">' + 185 '<div class="nfancybox-infobar"><span data-nfancybox-index></span> / <span data-nfancybox-count></span></div>' + 186 '<div class="nfancybox-toolbar">{{buttons}}</div>' + 187 '<div class="nfancybox-navigation">{{arrows}}</div>' + 188 '<div class="nfancybox-stage"></div>' + 189 '<div class="nfancybox-caption"><div class="nfancybox-caption__body"></div></div>' + 190 "</div>" + 191 "</div>", 192 193 // Loading indicator template 194 spinnerTpl: '<div class="nfancybox-loading"></div>', 195 196 // Error message template 197 errorTpl: '<div class="nfancybox-error"><p>{{ERROR}}</p></div>', 198 199 btnTpl: { 200 download: '<a download data-nfancybox-download class="nfancybox-button nfancybox-button--download" title="{{DOWNLOAD}}" href="javascript:;">' + 201 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.62 17.09V19H5.38v-1.91zm-2.97-6.96L17 11.45l-5 4.87-5-4.87 1.36-1.32 2.68 2.64V5h1.92v7.77z"/></svg>' + 202 "</a>", 203 204 zoom: '<button data-nfancybox-zoom class="nfancybox-button nfancybox-button--zoom" title="{{ZOOM}}">' + 205 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.7 17.3l-3-3a5.9 5.9 0 0 0-.6-7.6 5.9 5.9 0 0 0-8.4 0 5.9 5.9 0 0 0 0 8.4 5.9 5.9 0 0 0 7.7.7l3 3a1 1 0 0 0 1.3 0c.4-.5.4-1 0-1.5zM8.1 13.8a4 4 0 0 1 0-5.7 4 4 0 0 1 5.7 0 4 4 0 0 1 0 5.7 4 4 0 0 1-5.7 0z"/></svg>' + 206 "</button>", 207 208 close: '<button data-nfancybox-close class="nfancybox-button nfancybox-button--close" title="{{CLOSE}}">' + 209 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 10.6L6.6 5.2 5.2 6.6l5.4 5.4-5.4 5.4 1.4 1.4 5.4-5.4 5.4 5.4 1.4-1.4-5.4-5.4 5.4-5.4-1.4-1.4-5.4 5.4z"/></svg>' + 210 "</button>", 211 212 // Arrows 213 arrowLeft: '<button data-nfancybox-prev class="nfancybox-button nfancybox-button--arrow_left" title="{{PREV}}">' + 214 '<div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11.28 15.7l-1.34 1.37L5 12l4.94-5.07 1.34 1.38-2.68 2.72H19v1.94H8.6z"/></svg></div>' + 215 "</button>", 216 217 arrowRight: '<button data-nfancybox-next class="nfancybox-button nfancybox-button--arrow_right" title="{{NEXT}}">' + 218 '<div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 12.97l-2.68 2.72 1.34 1.38L19 12l-4.94-5.07-1.34 1.38 2.68 2.72H5v1.94z"/></svg></div>' + 219 "</button>", 220 221 // This small close button will be appended to your html/inline/ajax content by default, 222 // if "smallBtn" option is not set to false 223 smallBtn: '<button type="button" data-nfancybox-close class="nfancybox-button nfancybox-close-small" title="{{CLOSE}}">' + 224 '<svg xmlns="http://www.w3.org/2000/svg" version="1" viewBox="0 0 24 24"><path d="M13 12l5-5-1-1-5 5-5-5-1 1 5 5-5 5 1 1 5-5 5 5 1-1z"/></svg>' + 225 "</button>" 226 }, 227 228 // Container is injected into this element 229 parentEl: "body", 230 231 // Hide browser vertical scrollbars; use at your own risk 232 hideScrollbar: true, 233 234 // Focus handling 235 // ============== 236 237 // Try to focus on the first focusable element after opening 238 autoFocus: true, 239 240 // Put focus back to active element after closing 241 backFocus: true, 242 243 // Do not let user to focus on element outside modal content 244 trapFocus: true, 245 246 // Module specific options 247 // ======================= 248 249 fullScreen: { 250 autoStart: false 251 }, 252 253 // Set `touch: false` to disable panning/swiping 254 touch: { 255 vertical: true, // Allow to drag content vertically 256 momentum: true // Continue movement after releasing mouse/touch when panning 257 }, 258 259 // Hash value when initializing manually, 260 // set `false` to disable hash change 261 hash: false, 262 263 // Customize or add new media types 264 // Example: 265 /* 266 media : { 267 youtube : { 268 params : { 269 autoplay : 0 270 } 271 } 272 } 273 */ 274 media: {}, 275 276 slideShow: { 277 autoStart: false, 278 speed: 3000 279 }, 280 281 thumbs: { 282 autoStart: false, // Display thumbnails on opening 283 hideOnClose: true, // Hide thumbnail grid when closing animation starts 284 parentEl: ".nfancybox-container", // Container is injected into this element 285 axis: "y" // Vertical (y) or horizontal (x) scrolling 286 }, 287 288 // Use mousewheel to navigate gallery 289 // If 'auto' - enabled for images only 290 wheel: "auto", 291 292 // Callbacks 293 //========== 294 295 // See Documentation/API/Events for more information 296 // Example: 297 /* 298 afterShow: function( instance, current ) { 299 console.info( 'Clicked element:' ); 300 console.info( current.opts.$orig ); 301 } 302 */ 303 304 onInit: $.noop, // When instance has been initialized 305 306 beforeLoad: $.noop, // Before the content of a slide is being loaded 307 afterLoad: $.noop, // When the content of a slide is done loading 308 309 beforeShow: $.noop, // Before open animation starts 310 afterShow: $.noop, // When content is done loading and animating 311 312 beforeClose: $.noop, // Before the instance attempts to close. Return false to cancel the close. 313 afterClose: $.noop, // After instance has been closed 314 315 onActivate: $.noop, // When instance is brought to front 316 onDeactivate: $.noop, // When other instance has been activated 317 318 // Interaction 319 // =========== 320 321 // Use options below to customize taken action when user clicks or double clicks on the nfancyBox area, 322 // each option can be string or method that returns value. 323 // 324 // Possible values: 325 // "close" - close instance 326 // "next" - move to next gallery item 327 // "nextOrClose" - move to next gallery item or close if gallery has only one item 328 // "toggleControls" - show/hide controls 329 // "zoom" - zoom image (if loaded) 330 // false - do nothing 331 332 // Clicked on the content 333 clickContent: function (current, event) { 334 return current.type === "image" ? "zoom" : false; 335 }, 336 337 // Clicked on the slide 338 clickSlide: "close", 339 340 // Clicked on the background (backdrop) element; 341 // if you have not changed the layout, then most likely you need to use `clickSlide` option 342 clickOutside: "close", 343 344 // Same as previous two, but for double click 345 dblclickContent: false, 346 dblclickSlide: false, 347 dblclickOutside: false, 348 349 // Custom options when mobile device is detected 350 // ============================================= 351 352 mobile: { 353 preventCaptionOverlap: false, 354 idleTime: false, 355 clickContent: function (current, event) { 356 return current.type === "image" ? "toggleControls" : false; 357 }, 358 clickSlide: function (current, event) { 359 return current.type === "image" ? "toggleControls" : "close"; 360 }, 361 dblclickContent: function (current, event) { 362 return current.type === "image" ? "zoom" : false; 363 }, 364 dblclickSlide: function (current, event) { 365 return current.type === "image" ? "zoom" : false; 366 } 367 }, 368 369 // Internationalization 370 // ==================== 371 372 lang: "en", 373 i18n: { 374 en: { 375 CLOSE: "Close", 376 NEXT: "Next", 377 PREV: "Previous", 378 ERROR: "The requested content cannot be loaded. <br/> Please try again later.", 379 PLAY_START: "Start slideshow", 380 PLAY_STOP: "Pause slideshow", 381 FULL_SCREEN: "Full screen", 382 THUMBS: "Thumbnails", 383 DOWNLOAD: "Download", 384 SHARE: "Share", 385 ZOOM: "Zoom" 386 }, 387 de: { 388 CLOSE: "Schließen", 389 NEXT: "Weiter", 390 PREV: "Zurück", 391 ERROR: "Die angeforderten Daten konnten nicht geladen werden. <br/> Bitte versuchen Sie es später nochmal.", 392 PLAY_START: "Diaschau starten", 393 PLAY_STOP: "Diaschau beenden", 394 FULL_SCREEN: "Vollbild", 395 THUMBS: "Vorschaubilder", 396 DOWNLOAD: "Herunterladen", 397 SHARE: "Teilen", 398 ZOOM: "Vergrößern" 399 } 400 } 401 }; 402 403 // Few useful variables and methods 404 // ================================ 405 406 var $W = $(window); 407 var $D = $(document); 408 409 var called = 0; 410 411 // Check if an object is a jQuery object and not a native JavaScript object 412 // ======================================================================== 413 var isQuery = function (obj) { 414 return obj && obj.hasOwnProperty && obj instanceof $; 415 }; 416 417 // Handle multiple browsers for "requestAnimationFrame" and "cancelAnimationFrame" 418 // =============================================================================== 419 var requestAFrame = (function () { 420 return ( 421 window.requestAnimationFrame || 422 window.webkitRequestAnimationFrame || 423 window.mozRequestAnimationFrame || 424 window.oRequestAnimationFrame || 425 // if all else fails, use setTimeout 426 function (callback) { 427 return window.setTimeout(callback, 1000 / 60); 428 } 429 ); 430 })(); 431 432 var cancelAFrame = (function () { 433 return ( 434 window.cancelAnimationFrame || 435 window.webkitCancelAnimationFrame || 436 window.mozCancelAnimationFrame || 437 window.oCancelAnimationFrame || 438 function (id) { 439 window.clearTimeout(id); 440 } 441 ); 442 })(); 443 444 // Detect the supported transition-end event property name 445 // ======================================================= 446 var transitionEnd = (function () { 447 var el = document.createElement("fakeelement"), 448 t; 449 450 var transitions = { 451 transition: "transitionend", 452 OTransition: "oTransitionEnd", 453 MozTransition: "transitionend", 454 WebkitTransition: "webkitTransitionEnd" 455 }; 456 457 for (t in transitions) { 458 if (el.style[t] !== undefined) { 459 return transitions[t]; 460 } 461 } 462 463 return "transitionend"; 464 })(); 465 466 // Force redraw on an element. 467 // This helps in cases where the browser doesn't redraw an updated element properly 468 // ================================================================================ 469 var forceRedraw = function ($el) { 470 return $el && $el.length && $el[0].offsetHeight; 471 }; 472 473 // Exclude array (`buttons`) options from deep merging 474 // =================================================== 475 var mergeOpts = function (opts1, opts2) { 476 var rez = $.extend(true, {}, opts1, opts2); 477 478 $.each(opts2, function (key, value) { 479 if ($.isArray(value)) { 480 rez[key] = value; 481 } 482 }); 483 484 return rez; 485 }; 486 487 // How much of an element is visible in viewport 488 // ============================================= 489 490 var inViewport = function (elem) { 491 var elemCenter, rez; 492 493 if (!elem || elem.ownerDocument !== document) { 494 return false; 495 } 496 497 $(".nfancybox-container").css("pointer-events", "none"); 498 499 elemCenter = { 500 x: elem.getBoundingClientRect().left + elem.offsetWidth / 2, 501 y: elem.getBoundingClientRect().top + elem.offsetHeight / 2 502 }; 503 504 rez = document.elementFromPoint(elemCenter.x, elemCenter.y) === elem; 505 506 $(".nfancybox-container").css("pointer-events", ""); 507 508 return rez; 509 }; 510 511 // Class definition 512 // ================ 513 514 var nFancyBox = function (content, opts, index) { 515 var self = this; 516 517 self.opts = mergeOpts({ 518 index: index 519 }, $.nfancybox.defaults); 520 521 if ($.isPlainObject(opts)) { 522 self.opts = mergeOpts(self.opts, opts); 523 } 524 525 if ($.nfancybox.isMobile) { 526 self.opts = mergeOpts(self.opts, self.opts.mobile); 527 } 528 529 self.id = self.opts.id || ++called; 530 531 self.currIndex = parseInt(self.opts.index, 10) || 0; 532 self.prevIndex = null; 533 534 self.prevPos = null; 535 self.currPos = 0; 536 537 self.firstRun = true; 538 539 // All group items 540 self.group = []; 541 542 // Existing slides (for current, next and previous gallery items) 543 self.slides = {}; 544 545 // Create group elements 546 self.addContent(content); 547 548 if (!self.group.length) { 549 return; 550 } 551 552 self.init(); 553 }; 554 555 $.extend(nFancyBox.prototype, { 556 // Create DOM structure 557 // ==================== 558 559 init: function () { 560 var self = this, 561 firstItem = self.group[self.currIndex], 562 firstItemOpts = firstItem.opts, 563 $container, 564 buttonStr; 565 566 if (firstItemOpts.closeExisting) { 567 $.nfancybox.close(true); 568 } 569 570 // Hide scrollbars 571 // =============== 572 573 $("body").addClass("nfancybox-active"); 574 575 if ( 576 !$.nfancybox.getInstance() && 577 firstItemOpts.hideScrollbar !== false && 578 !$.nfancybox.isMobile && 579 document.body.scrollHeight > window.innerHeight 580 ) { 581 $("head").append( 582 '<style id="nfancybox-style-noscroll" type="text/css">.compensate-for-scrollbar{margin-right:' + 583 (window.innerWidth - document.documentElement.clientWidth) + 584 "px;}</style>" 585 ); 586 587 $("body").addClass("compensate-for-scrollbar"); 588 } 589 590 // Build html markup and set references 591 // ==================================== 592 593 // Build html code for buttons and insert into main template 594 buttonStr = ""; 595 596 $.each(firstItemOpts.buttons, function (index, value) { 597 buttonStr += firstItemOpts.btnTpl[value] || ""; 598 }); 599 600 // Create markup from base template, it will be initially hidden to 601 // avoid unnecessary work like painting while initializing is not complete 602 $container = $( 603 self.translate( 604 self, 605 firstItemOpts.baseTpl 606 .replace("{{buttons}}", buttonStr) 607 .replace("{{arrows}}", firstItemOpts.btnTpl.arrowLeft + firstItemOpts.btnTpl.arrowRight) 608 ) 609 ) 610 .attr("id", "nfancybox-container-" + self.id) 611 .addClass(firstItemOpts.baseClass) 612 .data("nFancyBox", self) 613 .appendTo(firstItemOpts.parentEl); 614 615 // Create object holding references to jQuery wrapped nodes 616 self.$refs = { 617 container: $container 618 }; 619 620 ["bg", "inner", "infobar", "toolbar", "stage", "caption", "navigation"].forEach(function (item) { 621 self.$refs[item] = $container.find(".nfancybox-" + item); 622 }); 623 624 self.trigger("onInit"); 625 626 // Enable events, deactive previous instances 627 self.activate(); 628 629 // Build slides, load and reveal content 630 self.jumpTo(self.currIndex); 631 }, 632 633 // Simple i18n support - replaces object keys found in template 634 // with corresponding values 635 // ============================================================ 636 637 translate: function (obj, str) { 638 var arr = obj.opts.i18n[obj.opts.lang] || obj.opts.i18n.en; 639 640 return str.replace(/\{\{(\w+)\}\}/g, function (match, n) { 641 return arr[n] === undefined ? match : arr[n]; 642 }); 643 }, 644 645 // Populate current group with fresh content 646 // Check if each object has valid type and content 647 // =============================================== 648 649 addContent: function (content) { 650 var self = this, 651 items = $.makeArray(content), 652 thumbs; 653 654 $.each(items, function (i, item) { 655 var obj = {}, 656 opts = {}, 657 $item, 658 type, 659 found, 660 src, 661 srcParts; 662 663 // Step 1 - Make sure we have an object 664 // ==================================== 665 666 if ($.isPlainObject(item)) { 667 // We probably have manual usage here, something like 668 // $.nfancybox.open( [ { src : "image.jpg", type : "image" } ] ) 669 670 obj = item; 671 opts = item.opts || item; 672 } else if ($.type(item) === "object" && $(item).length) { 673 // Here we probably have jQuery collection returned by some selector 674 $item = $(item); 675 676 // Support attributes like `data-options='{"touch" : false}'` and `data-touch='false'` 677 opts = $item.data() || {}; 678 opts = $.extend(true, {}, opts, opts.options); 679 680 // Here we store clicked element 681 opts.$orig = $item; 682 683 obj.src = self.opts.src || opts.src || $item.attr("href"); 684 685 // Assume that simple syntax is used, for example: 686 // `$.nfancybox.open( $("#test"), {} );` 687 if (!obj.type && !obj.src) { 688 obj.type = "inline"; 689 obj.src = item; 690 } 691 } else { 692 // Assume we have a simple html code, for example: 693 // $.nfancybox.open( '<div><h1>Hi!</h1></div>' ); 694 obj = { 695 type: "html", 696 src: item + "" 697 }; 698 } 699 700 // Each gallery object has full collection of options 701 obj.opts = $.extend(true, {}, self.opts, opts); 702 703 // Do not merge buttons array 704 if ($.isArray(opts.buttons)) { 705 obj.opts.buttons = opts.buttons; 706 } 707 708 if ($.nfancybox.isMobile && obj.opts.mobile) { 709 obj.opts = mergeOpts(obj.opts, obj.opts.mobile); 710 } 711 712 // Step 2 - Make sure we have content type, if not - try to guess 713 // ============================================================== 714 715 type = obj.type || obj.opts.type; 716 src = obj.src || ""; 717 718 if (!type && src) { 719 if ((found = src.match(/\.(mp4|mov|ogv|webm)((\?|#).*)?$/i))) { 720 type = "video"; 721 722 if (!obj.opts.video.format) { 723 obj.opts.video.format = "video/" + (found[1] === "ogv" ? "ogg" : found[1]); 724 } 725 } else if (src.match(/(^data:image\/[a-z0-9+\/=]*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg|ico)((\?|#).*)?$)/i)) { 726 type = "image"; 727 } else if (src.match(/\.(pdf)((\?|#).*)?$/i)) { 728 type = "iframe"; 729 obj = $.extend(true, obj, { 730 contentType: "pdf", 731 opts: { 732 iframe: { 733 preload: false 734 } 735 } 736 }); 737 } else if (src.charAt(0) === "#") { 738 type = "inline"; 739 } 740 } 741 742 if (type) { 743 obj.type = type; 744 } else { 745 self.trigger("objectNeedsType", obj); 746 } 747 748 if (!obj.contentType) { 749 obj.contentType = $.inArray(obj.type, ["html", "inline", "ajax"]) > -1 ? "html" : obj.type; 750 } 751 752 // Step 3 - Some adjustments 753 // ========================= 754 755 obj.index = self.group.length; 756 757 if (obj.opts.smallBtn == "auto") { 758 obj.opts.smallBtn = $.inArray(obj.type, ["html", "inline", "ajax"]) > -1; 759 } 760 761 if (obj.opts.toolbar === "auto") { 762 obj.opts.toolbar = !obj.opts.smallBtn; 763 } 764 765 // Find thumbnail image, check if exists and if is in the viewport 766 obj.$thumb = obj.opts.$thumb || null; 767 768 if (obj.opts.$trigger && obj.index === self.opts.index) { 769 obj.$thumb = obj.opts.$trigger.find("img:first"); 770 771 if (obj.$thumb.length) { 772 obj.opts.$orig = obj.opts.$trigger; 773 } 774 } 775 776 if (!(obj.$thumb && obj.$thumb.length) && obj.opts.$orig) { 777 obj.$thumb = obj.opts.$orig.find("img:first"); 778 } 779 780 if (obj.$thumb && !obj.$thumb.length) { 781 obj.$thumb = null; 782 } 783 784 obj.thumb = obj.opts.thumb || (obj.$thumb ? obj.$thumb[0].src : null); 785 786 // "caption" is a "special" option, it can be used to customize caption per gallery item 787 if ($.type(obj.opts.caption) === "function") { 788 obj.opts.caption = obj.opts.caption.apply(item, [self, obj]); 789 } 790 791 if ($.type(self.opts.caption) === "function") { 792 obj.opts.caption = self.opts.caption.apply(item, [self, obj]); 793 } 794 795 // Make sure we have caption as a string or jQuery object 796 if (!(obj.opts.caption instanceof $)) { 797 obj.opts.caption = obj.opts.caption === undefined ? "" : obj.opts.caption + ""; 798 } 799 800 // Check if url contains "filter" used to filter the content 801 // Example: "ajax.html #something" 802 if (obj.type === "ajax") { 803 srcParts = src.split(/\s+/, 2); 804 805 if (srcParts.length > 1) { 806 obj.src = srcParts.shift(); 807 808 obj.opts.filter = srcParts.shift(); 809 } 810 } 811 812 // Hide all buttons and disable interactivity for modal items 813 if (obj.opts.modal) { 814 obj.opts = $.extend(true, obj.opts, { 815 trapFocus: true, 816 // Remove buttons 817 infobar: 0, 818 toolbar: 0, 819 820 smallBtn: 0, 821 822 // Disable keyboard navigation 823 keyboard: 0, 824 825 // Disable some modules 826 slideShow: 0, 827 fullScreen: 0, 828 thumbs: 0, 829 touch: 0, 830 831 // Disable click event handlers 832 clickContent: false, 833 clickSlide: false, 834 clickOutside: false, 835 dblclickContent: false, 836 dblclickSlide: false, 837 dblclickOutside: false 838 }); 839 } 840 841 // Step 4 - Add processed object to group 842 // ====================================== 843 844 self.group.push(obj); 845 }); 846 847 // Update controls if gallery is already opened 848 if (Object.keys(self.slides).length) { 849 self.updateControls(); 850 851 // Update thumbnails, if needed 852 thumbs = self.Thumbs; 853 854 if (thumbs && thumbs.isActive) { 855 thumbs.create(); 856 857 thumbs.focus(); 858 } 859 } 860 }, 861 862 // Attach an event handler functions for: 863 // - navigation buttons 864 // - browser scrolling, resizing; 865 // - focusing 866 // - keyboard 867 // - detecting inactivity 868 // ====================================== 869 870 addEvents: function () { 871 var self = this; 872 873 self.removeEvents(); 874 875 // Make navigation elements clickable 876 // ================================== 877 878 self.$refs.container 879 .on("click.fb-close", "[data-nfancybox-close]", function (e) { 880 e.stopPropagation(); 881 e.preventDefault(); 882 883 self.close(e); 884 }) 885 .on("touchstart.fb-prev click.fb-prev", "[data-nfancybox-prev]", function (e) { 886 e.stopPropagation(); 887 e.preventDefault(); 888 889 self.previous(); 890 }) 891 .on("touchstart.fb-next click.fb-next", "[data-nfancybox-next]", function (e) { 892 e.stopPropagation(); 893 e.preventDefault(); 894 895 self.next(); 896 }) 897 .on("click.fb", "[data-nfancybox-zoom]", function (e) { 898 // Click handler for zoom button 899 self[self.isScaledDown() ? "scaleToActual" : "scaleToFit"](); 900 }); 901 902 // Handle page scrolling and browser resizing 903 // ========================================== 904 905 $W.on("orientationchange.fb resize.fb", function (e) { 906 if (e && e.originalEvent && e.originalEvent.type === "resize") { 907 if (self.requestId) { 908 cancelAFrame(self.requestId); 909 } 910 911 self.requestId = requestAFrame(function () { 912 self.update(e); 913 }); 914 } else { 915 if (self.current && self.current.type === "iframe") { 916 self.$refs.stage.hide(); 917 } 918 919 setTimeout( 920 function () { 921 self.$refs.stage.show(); 922 923 self.update(e); 924 }, 925 $.nfancybox.isMobile ? 600 : 250 926 ); 927 } 928 }); 929 930 $D.on("keydown.fb", function (e) { 931 var instance = $.nfancybox ? $.nfancybox.getInstance() : null, 932 current = instance.current, 933 keycode = e.keyCode || e.which; 934 935 // Trap keyboard focus inside of the modal 936 // ======================================= 937 938 if (keycode == 9) { 939 if (current.opts.trapFocus) { 940 self.focus(e); 941 } 942 943 return; 944 } 945 946 // Enable keyboard navigation 947 // ========================== 948 949 if (!current.opts.keyboard || e.ctrlKey || e.altKey || e.shiftKey || $(e.target).is("input,textarea,video,audio,select")) { 950 return; 951 } 952 953 // Backspace and Esc keys 954 if (keycode === 8 || keycode === 27) { 955 e.preventDefault(); 956 957 self.close(e); 958 959 return; 960 } 961 962 // Left arrow and Up arrow 963 if (keycode === 37 || keycode === 38) { 964 e.preventDefault(); 965 966 self.previous(); 967 968 return; 969 } 970 971 // Righ arrow and Down arrow 972 if (keycode === 39 || keycode === 40) { 973 e.preventDefault(); 974 975 self.next(); 976 977 return; 978 } 979 980 self.trigger("afterKeydown", e, keycode); 981 }); 982 983 // Hide controls after some inactivity period 984 if (self.group[self.currIndex].opts.idleTime) { 985 self.idleSecondsCounter = 0; 986 987 $D.on( 988 "mousemove.fb-idle mouseleave.fb-idle mousedown.fb-idle touchstart.fb-idle touchmove.fb-idle scroll.fb-idle keydown.fb-idle", 989 function (e) { 990 self.idleSecondsCounter = 0; 991 992 if (self.isIdle) { 993 self.showControls(); 994 } 995 996 self.isIdle = false; 997 } 998 ); 999 1000 self.idleInterval = window.setInterval(function () { 1001 self.idleSecondsCounter++; 1002 1003 if (self.idleSecondsCounter >= self.group[self.currIndex].opts.idleTime && !self.isDragging) { 1004 self.isIdle = true; 1005 self.idleSecondsCounter = 0; 1006 1007 self.hideControls(); 1008 } 1009 }, 1000); 1010 } 1011 }, 1012 1013 // Remove events added by the core 1014 // =============================== 1015 1016 removeEvents: function () { 1017 var self = this; 1018 1019 $W.off("orientationchange.fb resize.fb"); 1020 $D.off("keydown.fb .fb-idle"); 1021 1022 this.$refs.container.off(".fb-close .fb-prev .fb-next"); 1023 1024 if (self.idleInterval) { 1025 window.clearInterval(self.idleInterval); 1026 1027 self.idleInterval = null; 1028 } 1029 }, 1030 1031 // Change to previous gallery item 1032 // =============================== 1033 1034 previous: function (duration) { 1035 return this.jumpTo(this.currPos - 1, duration); 1036 }, 1037 1038 // Change to next gallery item 1039 // =========================== 1040 1041 next: function (duration) { 1042 return this.jumpTo(this.currPos + 1, duration); 1043 }, 1044 1045 // Switch to selected gallery item 1046 // =============================== 1047 1048 jumpTo: function (pos, duration) { 1049 var self = this, 1050 groupLen = self.group.length, 1051 firstRun, 1052 isMoved, 1053 loop, 1054 current, 1055 previous, 1056 slidePos, 1057 stagePos, 1058 prop, 1059 diff; 1060 1061 if (self.isDragging || self.isClosing || (self.isAnimating && self.firstRun)) { 1062 return; 1063 } 1064 1065 // Should loop? 1066 pos = parseInt(pos, 10); 1067 loop = self.current ? self.current.opts.loop : self.opts.loop; 1068 1069 if (!loop && (pos < 0 || pos >= groupLen)) { 1070 return false; 1071 } 1072 1073 // Check if opening for the first time; this helps to speed things up 1074 firstRun = self.firstRun = !Object.keys(self.slides).length; 1075 1076 // Create slides 1077 previous = self.current; 1078 1079 self.prevIndex = self.currIndex; 1080 self.prevPos = self.currPos; 1081 1082 current = self.createSlide(pos); 1083 1084 if (groupLen > 1) { 1085 if (loop || current.index < groupLen - 1) { 1086 self.createSlide(pos + 1); 1087 } 1088 1089 if (loop || current.index > 0) { 1090 self.createSlide(pos - 1); 1091 } 1092 } 1093 1094 self.current = current; 1095 self.currIndex = current.index; 1096 self.currPos = current.pos; 1097 1098 self.trigger("beforeShow", firstRun); 1099 1100 self.updateControls(); 1101 1102 // Validate duration length 1103 current.forcedDuration = undefined; 1104 1105 if ($.isNumeric(duration)) { 1106 current.forcedDuration = duration; 1107 } else { 1108 duration = current.opts[firstRun ? "animationDuration" : "transitionDuration"]; 1109 } 1110 1111 duration = parseInt(duration, 10); 1112 1113 // Check if user has swiped the slides or if still animating 1114 isMoved = self.isMoved(current); 1115 1116 // Make sure current slide is visible 1117 current.$slide.addClass("nfancybox-slide--current"); 1118 1119 // Fresh start - reveal container, current slide and start loading content 1120 if (firstRun) { 1121 if (current.opts.animationEffect && duration) { 1122 self.$refs.container.css("transition-duration", duration + "ms"); 1123 } 1124 1125 self.$refs.container.addClass("nfancybox-is-open").trigger("focus"); 1126 1127 // Attempt to load content into slide 1128 // This will later call `afterLoad` -> `revealContent` 1129 self.loadSlide(current); 1130 1131 self.preload("image"); 1132 1133 return; 1134 } 1135 1136 // Get actual slide/stage positions (before cleaning up) 1137 slidePos = $.nfancybox.getTranslate(previous.$slide); 1138 stagePos = $.nfancybox.getTranslate(self.$refs.stage); 1139 1140 // Clean up all slides 1141 $.each(self.slides, function (index, slide) { 1142 $.nfancybox.stop(slide.$slide, true); 1143 }); 1144 1145 if (previous.pos !== current.pos) { 1146 previous.isComplete = false; 1147 } 1148 1149 previous.$slide.removeClass("nfancybox-slide--complete nfancybox-slide--current"); 1150 1151 // If slides are out of place, then animate them to correct position 1152 if (isMoved) { 1153 // Calculate horizontal swipe distance 1154 diff = slidePos.left - (previous.pos * slidePos.width + previous.pos * previous.opts.gutter); 1155 1156 $.each(self.slides, function (index, slide) { 1157 slide.$slide.removeClass("nfancybox-animated").removeClass(function (index, className) { 1158 return (className.match(/(^|\s)nfancybox-fx-\S+/g) || []).join(" "); 1159 }); 1160 1161 // Make sure that each slide is in equal distance 1162 // This is mostly needed for freshly added slides, because they are not yet positioned 1163 var leftPos = slide.pos * slidePos.width + slide.pos * slide.opts.gutter; 1164 1165 $.nfancybox.setTranslate(slide.$slide, { 1166 top: 0, 1167 left: leftPos - stagePos.left + diff 1168 }); 1169 1170 if (slide.pos !== current.pos) { 1171 slide.$slide.addClass("nfancybox-slide--" + (slide.pos > current.pos ? "next" : "previous")); 1172 } 1173 1174 // Redraw to make sure that transition will start 1175 forceRedraw(slide.$slide); 1176 1177 // Animate the slide 1178 $.nfancybox.animate( 1179 slide.$slide, { 1180 top: 0, 1181 left: (slide.pos - current.pos) * slidePos.width + (slide.pos - current.pos) * slide.opts.gutter 1182 }, 1183 duration, 1184 function () { 1185 slide.$slide 1186 .css({ 1187 transform: "", 1188 opacity: "" 1189 }) 1190 .removeClass("nfancybox-slide--next nfancybox-slide--previous"); 1191 1192 if (slide.pos === self.currPos) { 1193 self.complete(); 1194 } 1195 } 1196 ); 1197 }); 1198 } else if (duration && current.opts.transitionEffect) { 1199 // Set transition effect for previously active slide 1200 prop = "nfancybox-animated nfancybox-fx-" + current.opts.transitionEffect; 1201 1202 previous.$slide.addClass("nfancybox-slide--" + (previous.pos > current.pos ? "next" : "previous")); 1203 1204 $.nfancybox.animate( 1205 previous.$slide, 1206 prop, 1207 duration, 1208 function () { 1209 previous.$slide.removeClass(prop).removeClass("nfancybox-slide--next nfancybox-slide--previous"); 1210 }, 1211 false 1212 ); 1213 } 1214 1215 if (current.isLoaded) { 1216 self.revealContent(current); 1217 } else { 1218 self.loadSlide(current); 1219 } 1220 1221 self.preload("image"); 1222 }, 1223 1224 // Create new "slide" element 1225 // These are gallery items that are actually added to DOM 1226 // ======================================================= 1227 1228 createSlide: function (pos) { 1229 var self = this, 1230 $slide, 1231 index; 1232 1233 index = pos % self.group.length; 1234 index = index < 0 ? self.group.length + index : index; 1235 1236 if (!self.slides[pos] && self.group[index]) { 1237 $slide = $('<div class="nfancybox-slide"></div>').appendTo(self.$refs.stage); 1238 1239 self.slides[pos] = $.extend(true, {}, self.group[index], { 1240 pos: pos, 1241 $slide: $slide, 1242 isLoaded: false 1243 }); 1244 1245 self.updateSlide(self.slides[pos]); 1246 } 1247 1248 return self.slides[pos]; 1249 }, 1250 1251 // Scale image to the actual size of the image; 1252 // x and y values should be relative to the slide 1253 // ============================================== 1254 1255 scaleToActual: function (x, y, duration) { 1256 var self = this, 1257 current = self.current, 1258 $content = current.$content, 1259 canvasWidth = $.nfancybox.getTranslate(current.$slide).width, 1260 canvasHeight = $.nfancybox.getTranslate(current.$slide).height, 1261 newImgWidth = current.width, 1262 newImgHeight = current.height, 1263 imgPos, 1264 posX, 1265 posY, 1266 scaleX, 1267 scaleY; 1268 1269 if (self.isAnimating || self.isMoved() || !$content || !(current.type == "image" && current.isLoaded && !current.hasError)) { 1270 return; 1271 } 1272 1273 self.isAnimating = true; 1274 1275 $.nfancybox.stop($content); 1276 1277 x = x === undefined ? canvasWidth * 0.5 : x; 1278 y = y === undefined ? canvasHeight * 0.5 : y; 1279 1280 imgPos = $.nfancybox.getTranslate($content); 1281 1282 imgPos.top -= $.nfancybox.getTranslate(current.$slide).top; 1283 imgPos.left -= $.nfancybox.getTranslate(current.$slide).left; 1284 1285 scaleX = newImgWidth / imgPos.width; 1286 scaleY = newImgHeight / imgPos.height; 1287 1288 // Get center position for original image 1289 posX = canvasWidth * 0.5 - newImgWidth * 0.5; 1290 posY = canvasHeight * 0.5 - newImgHeight * 0.5; 1291 1292 // Make sure image does not move away from edges 1293 if (newImgWidth > canvasWidth) { 1294 posX = imgPos.left * scaleX - (x * scaleX - x); 1295 1296 if (posX > 0) { 1297 posX = 0; 1298 } 1299 1300 if (posX < canvasWidth - newImgWidth) { 1301 posX = canvasWidth - newImgWidth; 1302 } 1303 } 1304 1305 if (newImgHeight > canvasHeight) { 1306 posY = imgPos.top * scaleY - (y * scaleY - y); 1307 1308 if (posY > 0) { 1309 posY = 0; 1310 } 1311 1312 if (posY < canvasHeight - newImgHeight) { 1313 posY = canvasHeight - newImgHeight; 1314 } 1315 } 1316 1317 self.updateCursor(newImgWidth, newImgHeight); 1318 1319 $.nfancybox.animate( 1320 $content, { 1321 top: posY, 1322 left: posX, 1323 scaleX: scaleX, 1324 scaleY: scaleY 1325 }, 1326 duration || 366, 1327 function () { 1328 self.isAnimating = false; 1329 } 1330 ); 1331 1332 // Stop slideshow 1333 if (self.SlideShow && self.SlideShow.isActive) { 1334 self.SlideShow.stop(); 1335 } 1336 }, 1337 1338 // Scale image to fit inside parent element 1339 // ======================================== 1340 1341 scaleToFit: function (duration) { 1342 var self = this, 1343 current = self.current, 1344 $content = current.$content, 1345 end; 1346 1347 if (self.isAnimating || self.isMoved() || !$content || !(current.type == "image" && current.isLoaded && !current.hasError)) { 1348 return; 1349 } 1350 1351 self.isAnimating = true; 1352 1353 $.nfancybox.stop($content); 1354 1355 end = self.getFitPos(current); 1356 1357 self.updateCursor(end.width, end.height); 1358 1359 $.nfancybox.animate( 1360 $content, { 1361 top: end.top, 1362 left: end.left, 1363 scaleX: end.width / $content.width(), 1364 scaleY: end.height / $content.height() 1365 }, 1366 duration || 366, 1367 function () { 1368 self.isAnimating = false; 1369 } 1370 ); 1371 }, 1372 1373 // Calculate image size to fit inside viewport 1374 // =========================================== 1375 1376 getFitPos: function (slide) { 1377 var self = this, 1378 $content = slide.$content, 1379 $slide = slide.$slide, 1380 width = slide.width || slide.opts.width, 1381 height = slide.height || slide.opts.height, 1382 maxWidth, 1383 maxHeight, 1384 minRatio, 1385 aspectRatio, 1386 rez = {}; 1387 1388 if (!slide.isLoaded || !$content || !$content.length) { 1389 return false; 1390 } 1391 1392 maxWidth = $.nfancybox.getTranslate(self.$refs.stage).width; 1393 maxHeight = $.nfancybox.getTranslate(self.$refs.stage).height; 1394 1395 maxWidth -= 1396 parseFloat($slide.css("paddingLeft")) + 1397 parseFloat($slide.css("paddingRight")) + 1398 parseFloat($content.css("marginLeft")) + 1399 parseFloat($content.css("marginRight")); 1400 1401 maxHeight -= 1402 parseFloat($slide.css("paddingTop")) + 1403 parseFloat($slide.css("paddingBottom")) + 1404 parseFloat($content.css("marginTop")) + 1405 parseFloat($content.css("marginBottom")); 1406 1407 if (!width || !height) { 1408 width = maxWidth; 1409 height = maxHeight; 1410 } 1411 1412 minRatio = Math.min(1, maxWidth / width, maxHeight / height); 1413 1414 width = minRatio * width; 1415 height = minRatio * height; 1416 1417 // Adjust width/height to precisely fit into container 1418 if (width > maxWidth - 0.5) { 1419 width = maxWidth; 1420 } 1421 1422 if (height > maxHeight - 0.5) { 1423 height = maxHeight; 1424 } 1425 1426 if (slide.type === "image") { 1427 rez.top = Math.floor((maxHeight - height) * 0.5) + parseFloat($slide.css("paddingTop")); 1428 rez.left = Math.floor((maxWidth - width) * 0.5) + parseFloat($slide.css("paddingLeft")); 1429 } else if (slide.contentType === "video") { 1430 // Force aspect ratio for the video 1431 // "I say the whole world must learn of our peaceful ways… by force!" 1432 aspectRatio = slide.opts.width && slide.opts.height ? width / height : slide.opts.ratio || 16 / 9; 1433 1434 if (height > width / aspectRatio) { 1435 height = width / aspectRatio; 1436 } else if (width > height * aspectRatio) { 1437 width = height * aspectRatio; 1438 } 1439 } 1440 1441 rez.width = width; 1442 rez.height = height; 1443 1444 return rez; 1445 }, 1446 1447 // Update content size and position for all slides 1448 // ============================================== 1449 1450 update: function (e) { 1451 var self = this; 1452 1453 $.each(self.slides, function (key, slide) { 1454 self.updateSlide(slide, e); 1455 }); 1456 }, 1457 1458 // Update slide content position and size 1459 // ====================================== 1460 1461 updateSlide: function (slide, e) { 1462 var self = this, 1463 $content = slide && slide.$content, 1464 width = slide.width || slide.opts.width, 1465 height = slide.height || slide.opts.height, 1466 $slide = slide.$slide; 1467 1468 // First, prevent caption overlap, if needed 1469 self.adjustCaption(slide); 1470 1471 // Then resize content to fit inside the slide 1472 if ($content && (width || height || slide.contentType === "video") && !slide.hasError) { 1473 $.nfancybox.stop($content); 1474 1475 $.nfancybox.setTranslate($content, self.getFitPos(slide)); 1476 1477 if (slide.pos === self.currPos) { 1478 self.isAnimating = false; 1479 1480 self.updateCursor(); 1481 } 1482 } 1483 1484 // Then some adjustments 1485 self.adjustLayout(slide); 1486 1487 if ($slide.length) { 1488 $slide.trigger("refresh"); 1489 1490 if (slide.pos === self.currPos) { 1491 self.$refs.toolbar 1492 .add(self.$refs.navigation.find(".nfancybox-button--arrow_right")) 1493 .toggleClass("compensate-for-scrollbar", $slide.get(0).scrollHeight > $slide.get(0).clientHeight); 1494 } 1495 } 1496 1497 self.trigger("onUpdate", slide, e); 1498 }, 1499 1500 // Horizontally center slide 1501 // ========================= 1502 1503 centerSlide: function (duration) { 1504 var self = this, 1505 current = self.current, 1506 $slide = current.$slide; 1507 1508 if (self.isClosing || !current) { 1509 return; 1510 } 1511 1512 $slide.siblings().css({ 1513 transform: "", 1514 opacity: "" 1515 }); 1516 1517 $slide 1518 .parent() 1519 .children() 1520 .removeClass("nfancybox-slide--previous nfancybox-slide--next"); 1521 1522 $.nfancybox.animate( 1523 $slide, { 1524 top: 0, 1525 left: 0, 1526 opacity: 1 1527 }, 1528 duration === undefined ? 0 : duration, 1529 function () { 1530 // Clean up 1531 $slide.css({ 1532 transform: "", 1533 opacity: "" 1534 }); 1535 1536 if (!current.isComplete) { 1537 self.complete(); 1538 } 1539 }, 1540 false 1541 ); 1542 }, 1543 1544 // Check if current slide is moved (swiped) 1545 // ======================================== 1546 1547 isMoved: function (slide) { 1548 var current = slide || this.current, 1549 slidePos, 1550 stagePos; 1551 1552 if (!current) { 1553 return false; 1554 } 1555 1556 stagePos = $.nfancybox.getTranslate(this.$refs.stage); 1557 slidePos = $.nfancybox.getTranslate(current.$slide); 1558 1559 return ( 1560 !current.$slide.hasClass("nfancybox-animated") && 1561 (Math.abs(slidePos.top - stagePos.top) > 0.5 || Math.abs(slidePos.left - stagePos.left) > 0.5) 1562 ); 1563 }, 1564 1565 // Update cursor style depending if content can be zoomed 1566 // ====================================================== 1567 1568 updateCursor: function (nextWidth, nextHeight) { 1569 var self = this, 1570 current = self.current, 1571 $container = self.$refs.container, 1572 canPan, 1573 isZoomable; 1574 1575 if (!current || self.isClosing || !self.Guestures) { 1576 return; 1577 } 1578 1579 $container.removeClass("nfancybox-is-zoomable nfancybox-can-zoomIn nfancybox-can-zoomOut nfancybox-can-swipe nfancybox-can-pan"); 1580 1581 canPan = self.canPan(nextWidth, nextHeight); 1582 1583 isZoomable = canPan ? true : self.isZoomable(); 1584 1585 $container.toggleClass("nfancybox-is-zoomable", isZoomable); 1586 1587 $("[data-nfancybox-zoom]").prop("disabled", !isZoomable); 1588 1589 if (canPan) { 1590 $container.addClass("nfancybox-can-pan"); 1591 } else if ( 1592 isZoomable && 1593 (current.opts.clickContent === "zoom" || ($.isFunction(current.opts.clickContent) && current.opts.clickContent(current) == "zoom")) 1594 ) { 1595 $container.addClass("nfancybox-can-zoomIn"); 1596 } else if (current.opts.touch && (current.opts.touch.vertical || self.group.length > 1) && current.contentType !== "video") { 1597 $container.addClass("nfancybox-can-swipe"); 1598 } 1599 }, 1600 1601 // Check if current slide is zoomable 1602 // ================================== 1603 1604 isZoomable: function () { 1605 var self = this, 1606 current = self.current, 1607 fitPos; 1608 1609 // Assume that slide is zoomable if: 1610 // - image is still loading 1611 // - actual size of the image is smaller than available area 1612 if (current && !self.isClosing && current.type === "image" && !current.hasError) { 1613 if (!current.isLoaded) { 1614 return true; 1615 } 1616 1617 fitPos = self.getFitPos(current); 1618 1619 if (fitPos && (current.width > fitPos.width || current.height > fitPos.height)) { 1620 return true; 1621 } 1622 } 1623 1624 return false; 1625 }, 1626 1627 // Check if current image dimensions are smaller than actual 1628 // ========================================================= 1629 1630 isScaledDown: function (nextWidth, nextHeight) { 1631 var self = this, 1632 rez = false, 1633 current = self.current, 1634 $content = current.$content; 1635 1636 if (nextWidth !== undefined && nextHeight !== undefined) { 1637 rez = nextWidth < current.width && nextHeight < current.height; 1638 } else if ($content) { 1639 rez = $.nfancybox.getTranslate($content); 1640 rez = rez.width < current.width && rez.height < current.height; 1641 } 1642 1643 return rez; 1644 }, 1645 1646 // Check if image dimensions exceed parent element 1647 // =============================================== 1648 1649 canPan: function (nextWidth, nextHeight) { 1650 var self = this, 1651 current = self.current, 1652 pos = null, 1653 rez = false; 1654 1655 if (current.type === "image" && (current.isComplete || (nextWidth && nextHeight)) && !current.hasError) { 1656 rez = self.getFitPos(current); 1657 1658 if (nextWidth !== undefined && nextHeight !== undefined) { 1659 pos = { 1660 width: nextWidth, 1661 height: nextHeight 1662 }; 1663 } else if (current.isComplete) { 1664 pos = $.nfancybox.getTranslate(current.$content); 1665 } 1666 1667 if (pos && rez) { 1668 rez = Math.abs(pos.width - rez.width) > 1.5 || Math.abs(pos.height - rez.height) > 1.5; 1669 } 1670 } 1671 1672 return rez; 1673 }, 1674 1675 // Load content into the slide 1676 // =========================== 1677 1678 loadSlide: function (slide) { 1679 var self = this, 1680 type, 1681 $slide, 1682 ajaxLoad; 1683 1684 if (slide.isLoading || slide.isLoaded) { 1685 return; 1686 } 1687 1688 slide.isLoading = true; 1689 1690 if (self.trigger("beforeLoad", slide) === false) { 1691 slide.isLoading = false; 1692 1693 return false; 1694 } 1695 1696 type = slide.type; 1697 $slide = slide.$slide; 1698 1699 $slide 1700 .off("refresh") 1701 .trigger("onReset") 1702 .addClass(slide.opts.slideClass); 1703 1704 // Create content depending on the type 1705 switch (type) { 1706 case "image": 1707 self.setImage(slide); 1708 1709 break; 1710 1711 case "iframe": 1712 self.setIframe(slide); 1713 1714 break; 1715 1716 case "html": 1717 self.setContent(slide, slide.src || slide.content); 1718 1719 break; 1720 1721 case "video": 1722 self.setContent( 1723 slide, 1724 slide.opts.video.tpl 1725 .replace(/\{\{src\}\}/gi, slide.src) 1726 .replace("{{format}}", slide.opts.videoFormat || slide.opts.video.format || "") 1727 .replace("{{poster}}", slide.thumb || "") 1728 ); 1729 1730 break; 1731 1732 case "inline": 1733 if ($(slide.src).length) { 1734 self.setContent(slide, $(slide.src)); 1735 } else { 1736 self.setError(slide); 1737 } 1738 1739 break; 1740 1741 case "ajax": 1742 self.showLoading(slide); 1743 1744 ajaxLoad = $.ajax( 1745 $.extend({}, slide.opts.ajax.settings, { 1746 url: slide.src, 1747 success: function (data, textStatus) { 1748 if (textStatus === "success") { 1749 self.setContent(slide, data); 1750 } 1751 }, 1752 error: function (jqXHR, textStatus) { 1753 if (jqXHR && textStatus !== "abort") { 1754 self.setError(slide); 1755 } 1756 } 1757 }) 1758 ); 1759 1760 $slide.one("onReset", function () { 1761 ajaxLoad.abort(); 1762 }); 1763 1764 break; 1765 1766 default: 1767 self.setError(slide); 1768 1769 break; 1770 } 1771 1772 return true; 1773 }, 1774 1775 // Use thumbnail image, if possible 1776 // ================================ 1777 1778 setImage: function (slide) { 1779 var self = this, 1780 ghost; 1781 1782 // Check if need to show loading icon 1783 setTimeout(function () { 1784 var $img = slide.$image; 1785 1786 if (!self.isClosing && slide.isLoading && (!$img || !$img.length || !$img[0].complete) && !slide.hasError) { 1787 self.showLoading(slide); 1788 } 1789 }, 50); 1790 1791 //Check if image has srcset 1792 self.checkSrcset(slide); 1793 1794 // This will be wrapper containing both ghost and actual image 1795 slide.$content = $('<div class="nfancybox-content"></div>') 1796 .addClass("nfancybox-is-hidden") 1797 .appendTo(slide.$slide.addClass("nfancybox-slide--image")); 1798 1799 // If we have a thumbnail, we can display it while actual image is loading 1800 // Users will not stare at black screen and actual image will appear gradually 1801 if (slide.opts.preload !== false && slide.opts.width && slide.opts.height && slide.thumb) { 1802 slide.width = slide.opts.width; 1803 slide.height = slide.opts.height; 1804 1805 ghost = document.createElement("img"); 1806 1807 ghost.onerror = function () { 1808 $(this).remove(); 1809 1810 slide.$ghost = null; 1811 }; 1812 1813 ghost.onload = function () { 1814 self.afterLoad(slide); 1815 }; 1816 1817 slide.$ghost = $(ghost) 1818 .addClass("nfancybox-image") 1819 .appendTo(slide.$content) 1820 .attr("src", slide.thumb); 1821 } 1822 1823 // Start loading actual image 1824 self.setBigImage(slide); 1825 }, 1826 1827 // Check if image has srcset and get the source 1828 // ============================================ 1829 checkSrcset: function (slide) { 1830 var srcset = slide.opts.srcset || slide.opts.image.srcset, 1831 found, 1832 temp, 1833 pxRatio, 1834 windowWidth; 1835 1836 // If we have "srcset", then we need to find first matching "src" value. 1837 // This is necessary, because when you set an src attribute, the browser will preload the image 1838 // before any javascript or even CSS is applied. 1839 if (srcset) { 1840 pxRatio = window.devicePixelRatio || 1; 1841 windowWidth = window.innerWidth * pxRatio; 1842 1843 temp = srcset.split(",").map(function (el) { 1844 var ret = {}; 1845 1846 el.trim() 1847 .split(/\s+/) 1848 .forEach(function (el, i) { 1849 var value = parseInt(el.substring(0, el.length - 1), 10); 1850 1851 if (i === 0) { 1852 return (ret.url = el); 1853 } 1854 1855 if (value) { 1856 ret.value = value; 1857 ret.postfix = el[el.length - 1]; 1858 } 1859 }); 1860 1861 return ret; 1862 }); 1863 1864 // Sort by value 1865 temp.sort(function (a, b) { 1866 return a.value - b.value; 1867 }); 1868 1869 // Ok, now we have an array of all srcset values 1870 for (var j = 0; j < temp.length; j++) { 1871 var el = temp[j]; 1872 1873 if ((el.postfix === "w" && el.value >= windowWidth) || (el.postfix === "x" && el.value >= pxRatio)) { 1874 found = el; 1875 break; 1876 } 1877 } 1878 1879 // If not found, take the last one 1880 if (!found && temp.length) { 1881 found = temp[temp.length - 1]; 1882 } 1883 1884 if (found) { 1885 slide.src = found.url; 1886 1887 // If we have default width/height values, we can calculate height for matching source 1888 if (slide.width && slide.height && found.postfix == "w") { 1889 slide.height = (slide.width / slide.height) * found.value; 1890 slide.width = found.value; 1891 } 1892 1893 slide.opts.srcset = srcset; 1894 } 1895 } 1896 }, 1897 1898 // Create full-size image 1899 // ====================== 1900 1901 setBigImage: function (slide) { 1902 var self = this, 1903 img = document.createElement("img"), 1904 $img = $(img); 1905 1906 slide.$image = $img 1907 .one("error", function () { 1908 self.setError(slide); 1909 }) 1910 .one("load", function () { 1911 var sizes; 1912 1913 if (!slide.$ghost) { 1914 self.resolveImageSlideSize(slide, this.naturalWidth, this.naturalHeight); 1915 1916 self.afterLoad(slide); 1917 } 1918 1919 if (self.isClosing) { 1920 return; 1921 } 1922 1923 if (slide.opts.srcset) { 1924 sizes = slide.opts.sizes; 1925 1926 if (!sizes || sizes === "auto") { 1927 sizes = 1928 (slide.width / slide.height > 1 && $W.width() / $W.height() > 1 ? "100" : Math.round((slide.width / slide.height) * 100)) + 1929 "vw"; 1930 } 1931 1932 $img.attr("sizes", sizes).attr("srcset", slide.opts.srcset); 1933 } 1934 1935 // Hide temporary image after some delay 1936 if (slide.$ghost) { 1937 setTimeout(function () { 1938 if (slide.$ghost && !self.isClosing) { 1939 slide.$ghost.hide(); 1940 } 1941 }, Math.min(300, Math.max(1000, slide.height / 1600))); 1942 } 1943 1944 self.hideLoading(slide); 1945 }) 1946 .addClass("nfancybox-image") 1947 .attr("src", slide.src) 1948 .appendTo(slide.$content); 1949 1950 if ((img.complete || img.readyState == "complete") && $img.naturalWidth && $img.naturalHeight) { 1951 $img.trigger("load"); 1952 } else if (img.error) { 1953 $img.trigger("error"); 1954 } 1955 }, 1956 1957 // Computes the slide size from image size and maxWidth/maxHeight 1958 // ============================================================== 1959 1960 resolveImageSlideSize: function (slide, imgWidth, imgHeight) { 1961 var maxWidth = parseInt(slide.opts.width, 10), 1962 maxHeight = parseInt(slide.opts.height, 10); 1963 1964 // Sets the default values from the image 1965 slide.width = imgWidth; 1966 slide.height = imgHeight; 1967 1968 if (maxWidth > 0) { 1969 slide.width = maxWidth; 1970 slide.height = Math.floor((maxWidth * imgHeight) / imgWidth); 1971 } 1972 1973 if (maxHeight > 0) { 1974 slide.width = Math.floor((maxHeight * imgWidth) / imgHeight); 1975 slide.height = maxHeight; 1976 } 1977 }, 1978 1979 // Create iframe wrapper, iframe and bindings 1980 // ========================================== 1981 1982 setIframe: function (slide) { 1983 var self = this, 1984 opts = slide.opts.iframe, 1985 $slide = slide.$slide, 1986 $iframe; 1987 1988 slide.$content = $('<div class="nfancybox-content' + (opts.preload ? " nfancybox-is-hidden" : "") + '"></div>') 1989 .css(opts.css) 1990 .appendTo($slide); 1991 1992 $slide.addClass("nfancybox-slide--" + slide.contentType); 1993 1994 slide.$iframe = $iframe = $(opts.tpl.replace(/\{rnd\}/g, new Date().getTime())) 1995 .attr(opts.attr) 1996 .appendTo(slide.$content); 1997 1998 if (opts.preload) { 1999 self.showLoading(slide); 2000 2001 // Unfortunately, it is not always possible to determine if iframe is successfully loaded 2002 // (due to browser security policy) 2003 2004 $iframe.on("load.fb error.fb", function (e) { 2005 this.isReady = 1; 2006 2007 slide.$slide.trigger("refresh"); 2008 2009 self.afterLoad(slide); 2010 }); 2011 2012 // Recalculate iframe content size 2013 // =============================== 2014 2015 $slide.on("refresh.fb", function () { 2016 var $content = slide.$content, 2017 frameWidth = opts.css.width, 2018 frameHeight = opts.css.height, 2019 $contents, 2020 $body; 2021 2022 if ($iframe[0].isReady !== 1) { 2023 return; 2024 } 2025 2026 try { 2027 $contents = $iframe.contents(); 2028 $body = $contents.find("body"); 2029 } catch (ignore) {} 2030 2031 // Calculate content dimensions, if it is accessible 2032 if ($body && $body.length && $body.children().length) { 2033 // Avoid scrolling to top (if multiple instances) 2034 $slide.css("overflow", "visible"); 2035 2036 $content.css({ 2037 width: "100%", 2038 "max-width": "100%", 2039 height: "9999px" 2040 }); 2041 2042 if (frameWidth === undefined) { 2043 frameWidth = Math.ceil(Math.max($body[0].clientWidth, $body.outerWidth(true))); 2044 } 2045 2046 $content.css("width", frameWidth ? frameWidth : "").css("max-width", ""); 2047 2048 if (frameHeight === undefined) { 2049 frameHeight = Math.ceil(Math.max($body[0].clientHeight, $body.outerHeight(true))); 2050 } 2051 2052 $content.css("height", frameHeight ? frameHeight : ""); 2053 2054 $slide.css("overflow", "auto"); 2055 } 2056 2057 $content.removeClass("nfancybox-is-hidden"); 2058 }); 2059 } else { 2060 self.afterLoad(slide); 2061 } 2062 2063 $iframe.attr("src", slide.src); 2064 2065 // Remove iframe if closing or changing gallery item 2066 $slide.one("onReset", function () { 2067 // This helps IE not to throw errors when closing 2068 try { 2069 $(this) 2070 .find("iframe") 2071 .hide() 2072 .unbind() 2073 .attr("src", "//about:blank"); 2074 } catch (ignore) {} 2075 2076 $(this) 2077 .off("refresh.fb") 2078 .empty(); 2079 2080 slide.isLoaded = false; 2081 slide.isRevealed = false; 2082 }); 2083 }, 2084 2085 // Wrap and append content to the slide 2086 // ====================================== 2087 2088 setContent: function (slide, content) { 2089 var self = this; 2090 2091 if (self.isClosing) { 2092 return; 2093 } 2094 2095 self.hideLoading(slide); 2096 2097 if (slide.$content) { 2098 $.nfancybox.stop(slide.$content); 2099 } 2100 2101 slide.$slide.empty(); 2102 2103 // If content is a jQuery object, then it will be moved to the slide. 2104 // The placeholder is created so we will know where to put it back. 2105 if (isQuery(content) && content.parent().length) { 2106 // Make sure content is not already moved to nfancyBox 2107 if (content.hasClass("nfancybox-content") || content.parent().hasClass("nfancybox-content")) { 2108 content.parents(".nfancybox-slide").trigger("onReset"); 2109 } 2110 2111 // Create temporary element marking original place of the content 2112 slide.$placeholder = $("<div>") 2113 .hide() 2114 .insertAfter(content); 2115 2116 // Make sure content is visible 2117 content.css("display", "inline-block"); 2118 } else if (!slide.hasError) { 2119 // If content is just a plain text, try to convert it to html 2120 if ($.type(content) === "string") { 2121 content = $("<div>") 2122 .append($.trim(content)) 2123 .contents(); 2124 } 2125 2126 // If "filter" option is provided, then filter content 2127 if (slide.opts.filter) { 2128 content = $("<div>") 2129 .html(content) 2130 .find(slide.opts.filter); 2131 } 2132 } 2133 2134 slide.$slide.one("onReset", function () { 2135 // Pause all html5 video/audio 2136 $(this) 2137 .find("video,audio") 2138 .trigger("pause"); 2139 2140 // Put content back 2141 if (slide.$placeholder) { 2142 slide.$placeholder.after(content.removeClass("nfancybox-content").hide()).remove(); 2143 2144 slide.$placeholder = null; 2145 } 2146 2147 // Remove custom close button 2148 if (slide.$smallBtn) { 2149 slide.$smallBtn.remove(); 2150 2151 slide.$smallBtn = null; 2152 } 2153 2154 // Remove content and mark slide as not loaded 2155 if (!slide.hasError) { 2156 $(this).empty(); 2157 2158 slide.isLoaded = false; 2159 slide.isRevealed = false; 2160 } 2161 }); 2162 2163 $(content).appendTo(slide.$slide); 2164 2165 if ($(content).is("video,audio")) { 2166 $(content).addClass("nfancybox-video"); 2167 2168 $(content).wrap("<div></div>"); 2169 2170 slide.contentType = "video"; 2171 2172 slide.opts.width = slide.opts.width || $(content).attr("width"); 2173 slide.opts.height = slide.opts.height || $(content).attr("height"); 2174 } 2175 2176 slide.$content = slide.$slide 2177 .children() 2178 .filter("div,form,main,video,audio,article,.nfancybox-content") 2179 .first(); 2180 2181 slide.$content.siblings().hide(); 2182 2183 // Re-check if there is a valid content 2184 // (in some cases, ajax response can contain various elements or plain text) 2185 if (!slide.$content.length) { 2186 slide.$content = slide.$slide 2187 .wrapInner("<div></div>") 2188 .children() 2189 .first(); 2190 } 2191 2192 slide.$content.addClass("nfancybox-content"); 2193 2194 slide.$slide.addClass("nfancybox-slide--" + slide.contentType); 2195 2196 self.afterLoad(slide); 2197 }, 2198 2199 // Display error message 2200 // ===================== 2201 2202 setError: function (slide) { 2203 slide.hasError = true; 2204 2205 slide.$slide 2206 .trigger("onReset") 2207 .removeClass("nfancybox-slide--" + slide.contentType) 2208 .addClass("nfancybox-slide--error"); 2209 2210 slide.contentType = "html"; 2211 2212 this.setContent(slide, this.translate(slide, slide.opts.errorTpl)); 2213 2214 if (slide.pos === this.currPos) { 2215 this.isAnimating = false; 2216 } 2217 }, 2218 2219 // Show loading icon inside the slide 2220 // ================================== 2221 2222 showLoading: function (slide) { 2223 var self = this; 2224 2225 slide = slide || self.current; 2226 2227 if (slide && !slide.$spinner) { 2228 slide.$spinner = $(self.translate(self, self.opts.spinnerTpl)) 2229 .appendTo(slide.$slide) 2230 .hide() 2231 .fadeIn("fast"); 2232 } 2233 }, 2234 2235 // Remove loading icon from the slide 2236 // ================================== 2237 2238 hideLoading: function (slide) { 2239 var self = this; 2240 2241 slide = slide || self.current; 2242 2243 if (slide && slide.$spinner) { 2244 slide.$spinner.stop().remove(); 2245 2246 delete slide.$spinner; 2247 } 2248 }, 2249 2250 // Adjustments after slide content has been loaded 2251 // =============================================== 2252 2253 afterLoad: function (slide) { 2254 var self = this; 2255 2256 if (self.isClosing) { 2257 return; 2258 } 2259 2260 slide.isLoading = false; 2261 slide.isLoaded = true; 2262 2263 self.trigger("afterLoad", slide); 2264 2265 self.hideLoading(slide); 2266 2267 // Add small close button 2268 if (slide.opts.smallBtn && (!slide.$smallBtn || !slide.$smallBtn.length)) { 2269 slide.$smallBtn = $(self.translate(slide, slide.opts.btnTpl.smallBtn)).appendTo(slide.$content); 2270 } 2271 2272 // Disable right click 2273 if (slide.opts.protect && slide.$content && !slide.hasError) { 2274 slide.$content.on("contextmenu.fb", function (e) { 2275 if (e.button == 2) { 2276 e.preventDefault(); 2277 } 2278 2279 return true; 2280 }); 2281 2282 // Add fake element on top of the image 2283 // This makes a bit harder for user to select image 2284 if (slide.type === "image") { 2285 $('<div class="nfancybox-spaceball"></div>').appendTo(slide.$content); 2286 } 2287 } 2288 2289 self.adjustCaption(slide); 2290 2291 self.adjustLayout(slide); 2292 2293 if (slide.pos === self.currPos) { 2294 self.updateCursor(); 2295 } 2296 2297 self.revealContent(slide); 2298 }, 2299 2300 // Prevent caption overlap, 2301 // fix css inconsistency across browsers 2302 // ===================================== 2303 2304 adjustCaption: function (slide) { 2305 var self = this, 2306 current = slide || self.current, 2307 caption = current.opts.caption, 2308 preventOverlap = current.opts.preventCaptionOverlap, 2309 $caption = self.$refs.caption, 2310 $clone, 2311 captionH = false; 2312 2313 $caption.toggleClass("nfancybox-caption--separate", preventOverlap); 2314 2315 if (preventOverlap && caption && caption.length) { 2316 if (current.pos !== self.currPos) { 2317 $clone = $caption.clone().appendTo($caption.parent()); 2318 2319 $clone 2320 .children() 2321 .eq(0) 2322 .empty() 2323 .html(caption); 2324 2325 captionH = $clone.outerHeight(true); 2326 2327 $clone.empty().remove(); 2328 } else if (self.$caption) { 2329 captionH = self.$caption.outerHeight(true); 2330 } 2331 2332 current.$slide.css("padding-bottom", captionH || ""); 2333 } 2334 }, 2335 2336 // Simple hack to fix inconsistency across browsers, described here (affects Edge, too): 2337 // https://bugzilla.mozilla.org/show_bug.cgi?id=748518 2338 // ==================================================================================== 2339 2340 adjustLayout: function (slide) { 2341 var self = this, 2342 current = slide || self.current, 2343 scrollHeight, 2344 marginBottom, 2345 inlinePadding, 2346 actualPadding; 2347 2348 if (current.isLoaded && current.opts.disableLayoutFix !== true) { 2349 current.$content.css("margin-bottom", ""); 2350 2351 // If we would always set margin-bottom for the content, 2352 // then it would potentially break vertical align 2353 if (current.$content.outerHeight() > current.$slide.height() + 0.5) { 2354 inlinePadding = current.$slide[0].style["padding-bottom"]; 2355 actualPadding = current.$slide.css("padding-bottom"); 2356 2357 if (parseFloat(actualPadding) > 0) { 2358 scrollHeight = current.$slide[0].scrollHeight; 2359 2360 current.$slide.css("padding-bottom", 0); 2361 2362 if (Math.abs(scrollHeight - current.$slide[0].scrollHeight) < 1) { 2363 marginBottom = actualPadding; 2364 } 2365 2366 current.$slide.css("padding-bottom", inlinePadding); 2367 } 2368 } 2369 2370 current.$content.css("margin-bottom", marginBottom); 2371 } 2372 }, 2373 2374 // Make content visible 2375 // This method is called right after content has been loaded or 2376 // user navigates gallery and transition should start 2377 // ============================================================ 2378 2379 revealContent: function (slide) { 2380 var self = this, 2381 $slide = slide.$slide, 2382 end = false, 2383 start = false, 2384 isMoved = self.isMoved(slide), 2385 isRevealed = slide.isRevealed, 2386 effect, 2387 effectClassName, 2388 duration, 2389 opacity; 2390 2391 slide.isRevealed = true; 2392 2393 effect = slide.opts[self.firstRun ? "animationEffect" : "transitionEffect"]; 2394 duration = slide.opts[self.firstRun ? "animationDuration" : "transitionDuration"]; 2395 2396 duration = parseInt(slide.forcedDuration === undefined ? duration : slide.forcedDuration, 10); 2397 2398 if (isMoved || slide.pos !== self.currPos || !duration) { 2399 effect = false; 2400 } 2401 2402 // Check if can zoom 2403 if (effect === "zoom") { 2404 if (slide.pos === self.currPos && duration && slide.type === "image" && !slide.hasError && (start = self.getThumbPos(slide))) { 2405 end = self.getFitPos(slide); 2406 } else { 2407 effect = "fade"; 2408 } 2409 } 2410 2411 // Zoom animation 2412 // ============== 2413 if (effect === "zoom") { 2414 self.isAnimating = true; 2415 2416 end.scaleX = end.width / start.width; 2417 end.scaleY = end.height / start.height; 2418 2419 // Check if we need to animate opacity 2420 opacity = slide.opts.zoomOpacity; 2421 2422 if (opacity == "auto") { 2423 opacity = Math.abs(slide.width / slide.height - start.width / start.height) > 0.1; 2424 } 2425 2426 if (opacity) { 2427 start.opacity = 0.1; 2428 end.opacity = 1; 2429 } 2430 2431 // Draw image at start position 2432 $.nfancybox.setTranslate(slide.$content.removeClass("nfancybox-is-hidden"), start); 2433 2434 forceRedraw(slide.$content); 2435 2436 // Start animation 2437 $.nfancybox.animate(slide.$content, end, duration, function () { 2438 self.isAnimating = false; 2439 2440 self.complete(); 2441 }); 2442 2443 return; 2444 } 2445 2446 self.updateSlide(slide); 2447 2448 // Simply show content if no effect 2449 // ================================ 2450 if (!effect) { 2451 slide.$content.removeClass("nfancybox-is-hidden"); 2452 2453 if (!isRevealed && isMoved && slide.type === "image" && !slide.hasError) { 2454 slide.$content.hide().fadeIn("fast"); 2455 } 2456 2457 if (slide.pos === self.currPos) { 2458 self.complete(); 2459 } 2460 2461 return; 2462 } 2463 2464 // Prepare for CSS transiton 2465 // ========================= 2466 $.nfancybox.stop($slide); 2467 2468 //effectClassName = "nfancybox-animated nfancybox-slide--" + (slide.pos >= self.prevPos ? "next" : "previous") + " nfancybox-fx-" + effect; 2469 effectClassName = "nfancybox-slide--" + (slide.pos >= self.prevPos ? "next" : "previous") + " nfancybox-animated nfancybox-fx-" + effect; 2470 2471 $slide.addClass(effectClassName).removeClass("nfancybox-slide--current"); //.addClass(effectClassName); 2472 2473 slide.$content.removeClass("nfancybox-is-hidden"); 2474 2475 // Force reflow 2476 forceRedraw($slide); 2477 2478 if (slide.type !== "image") { 2479 slide.$content.hide().show(0); 2480 } 2481 2482 $.nfancybox.animate( 2483 $slide, 2484 "nfancybox-slide--current", 2485 duration, 2486 function () { 2487 $slide.removeClass(effectClassName).css({ 2488 transform: "", 2489 opacity: "" 2490 }); 2491 2492 if (slide.pos === self.currPos) { 2493 self.complete(); 2494 } 2495 }, 2496 true 2497 ); 2498 }, 2499 2500 // Check if we can and have to zoom from thumbnail 2501 //================================================ 2502 2503 getThumbPos: function (slide) { 2504 var rez = false, 2505 $thumb = slide.$thumb, 2506 thumbPos, 2507 btw, 2508 brw, 2509 bbw, 2510 blw; 2511 2512 if (!$thumb || !inViewport($thumb[0])) { 2513 return false; 2514 } 2515 2516 thumbPos = $.nfancybox.getTranslate($thumb); 2517 2518 btw = parseFloat($thumb.css("border-top-width") || 0); 2519 brw = parseFloat($thumb.css("border-right-width") || 0); 2520 bbw = parseFloat($thumb.css("border-bottom-width") || 0); 2521 blw = parseFloat($thumb.css("border-left-width") || 0); 2522 2523 rez = { 2524 top: thumbPos.top + btw, 2525 left: thumbPos.left + blw, 2526 width: thumbPos.width - brw - blw, 2527 height: thumbPos.height - btw - bbw, 2528 scaleX: 1, 2529 scaleY: 1 2530 }; 2531 2532 return thumbPos.width > 0 && thumbPos.height > 0 ? rez : false; 2533 }, 2534 2535 // Final adjustments after current gallery item is moved to position 2536 // and it`s content is loaded 2537 // ================================================================== 2538 2539 complete: function () { 2540 var self = this, 2541 current = self.current, 2542 slides = {}, 2543 $el; 2544 2545 if (self.isMoved() || !current.isLoaded) { 2546 return; 2547 } 2548 2549 if (!current.isComplete) { 2550 current.isComplete = true; 2551 2552 current.$slide.siblings().trigger("onReset"); 2553 2554 self.preload("inline"); 2555 2556 // Trigger any CSS transiton inside the slide 2557 forceRedraw(current.$slide); 2558 2559 current.$slide.addClass("nfancybox-slide--complete"); 2560 2561 // Remove unnecessary slides 2562 $.each(self.slides, function (key, slide) { 2563 if (slide.pos >= self.currPos - 1 && slide.pos <= self.currPos + 1) { 2564 slides[slide.pos] = slide; 2565 } else if (slide) { 2566 $.nfancybox.stop(slide.$slide); 2567 2568 slide.$slide.off().remove(); 2569 } 2570 }); 2571 2572 self.slides = slides; 2573 } 2574 2575 self.isAnimating = false; 2576 2577 self.updateCursor(); 2578 2579 self.trigger("afterShow"); 2580 2581 // Autoplay first html5 video/audio 2582 if (!!current.opts.video.autoStart) { 2583 current.$slide 2584 .find("video,audio") 2585 .filter(":visible:first") 2586 .trigger("play") 2587 .one("ended", function () { 2588 if (Document.exitFullscreen) { 2589 Document.exitFullscreen(); 2590 } else if (this.webkitExitFullscreen) { 2591 this.webkitExitFullscreen(); 2592 } 2593 2594 self.next(); 2595 }); 2596 } 2597 2598 // Try to focus on the first focusable element 2599 if (current.opts.autoFocus && current.contentType === "html") { 2600 // Look for the first input with autofocus attribute 2601 $el = current.$content.find("input[autofocus]:enabled:visible:first"); 2602 2603 if ($el.length) { 2604 $el.trigger("focus"); 2605 } else { 2606 self.focus(null, true); 2607 } 2608 } 2609 2610 // Avoid jumping 2611 current.$slide.scrollTop(0).scrollLeft(0); 2612 }, 2613 2614 // Preload next and previous slides 2615 // ================================ 2616 2617 preload: function (type) { 2618 var self = this, 2619 prev, 2620 next; 2621 2622 if (self.group.length < 2) { 2623 return; 2624 } 2625 2626 next = self.slides[self.currPos + 1]; 2627 prev = self.slides[self.currPos - 1]; 2628 2629 if (prev && prev.type === type) { 2630 self.loadSlide(prev); 2631 } 2632 2633 if (next && next.type === type) { 2634 self.loadSlide(next); 2635 } 2636 }, 2637 2638 // Try to find and focus on the first focusable element 2639 // ==================================================== 2640 2641 focus: function (e, firstRun) { 2642 var self = this, 2643 focusableStr = [ 2644 "a[href]", 2645 "area[href]", 2646 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])', 2647 "select:not([disabled]):not([aria-hidden])", 2648 "textarea:not([disabled]):not([aria-hidden])", 2649 "button:not([disabled]):not([aria-hidden])", 2650 "iframe", 2651 "object", 2652 "embed", 2653 "video", 2654 "audio", 2655 "[contenteditable]", 2656 '[tabindex]:not([tabindex^="-"])' 2657 ].join(","), 2658 focusableItems, 2659 focusedItemIndex; 2660 2661 if (self.isClosing) { 2662 return; 2663 } 2664 2665 if (e || !self.current || !self.current.isComplete) { 2666 // Focus on any element inside nfancybox 2667 focusableItems = self.$refs.container.find("*:visible"); 2668 } else { 2669 // Focus inside current slide 2670 focusableItems = self.current.$slide.find("*:visible" + (firstRun ? ":not(.nfancybox-close-small)" : "")); 2671 } 2672 2673 focusableItems = focusableItems.filter(focusableStr).filter(function () { 2674 return $(this).css("visibility") !== "hidden" && !$(this).hasClass("disabled"); 2675 }); 2676 2677 if (focusableItems.length) { 2678 focusedItemIndex = focusableItems.index(document.activeElement); 2679 2680 if (e && e.shiftKey) { 2681 // Back tab 2682 if (focusedItemIndex < 0 || focusedItemIndex == 0) { 2683 e.preventDefault(); 2684 2685 focusableItems.eq(focusableItems.length - 1).trigger("focus"); 2686 } 2687 } else { 2688 // Outside or Forward tab 2689 if (focusedItemIndex < 0 || focusedItemIndex == focusableItems.length - 1) { 2690 if (e) { 2691 e.preventDefault(); 2692 } 2693 2694 focusableItems.eq(0).trigger("focus"); 2695 } 2696 } 2697 } else { 2698 self.$refs.container.trigger("focus"); 2699 } 2700 }, 2701 2702 // Activates current instance - brings container to the front and enables keyboard, 2703 // notifies other instances about deactivating 2704 // ================================================================================= 2705 2706 activate: function () { 2707 var self = this; 2708 2709 // Deactivate all instances 2710 $(".nfancybox-container").each(function () { 2711 var instance = $(this).data("nFancyBox"); 2712 2713 // Skip self and closing instances 2714 if (instance && instance.id !== self.id && !instance.isClosing) { 2715 instance.trigger("onDeactivate"); 2716 2717 instance.removeEvents(); 2718 2719 instance.isVisible = false; 2720 } 2721 }); 2722 2723 self.isVisible = true; 2724 2725 if (self.current || self.isIdle) { 2726 self.update(); 2727 2728 self.updateControls(); 2729 } 2730 2731 self.trigger("onActivate"); 2732 2733 self.addEvents(); 2734 }, 2735 2736 // Start closing procedure 2737 // This will start "zoom-out" animation if needed and clean everything up afterwards 2738 // ================================================================================= 2739 2740 close: function (e, d) { 2741 var self = this, 2742 current = self.current, 2743 effect, 2744 duration, 2745 $content, 2746 domRect, 2747 opacity, 2748 start, 2749 end; 2750 2751 var done = function () { 2752 self.cleanUp(e); 2753 }; 2754 2755 if (self.isClosing) { 2756 return false; 2757 } 2758 2759 self.isClosing = true; 2760 2761 // If beforeClose callback prevents closing, make sure content is centered 2762 if (self.trigger("beforeClose", e) === false) { 2763 self.isClosing = false; 2764 2765 requestAFrame(function () { 2766 self.update(); 2767 }); 2768 2769 return false; 2770 } 2771 2772 // Remove all events 2773 // If there are multiple instances, they will be set again by "activate" method 2774 self.removeEvents(); 2775 2776 $content = current.$content; 2777 effect = current.opts.animationEffect; 2778 duration = $.isNumeric(d) ? d : effect ? current.opts.animationDuration : 0; 2779 2780 current.$slide.removeClass("nfancybox-slide--complete nfancybox-slide--next nfancybox-slide--previous nfancybox-animated"); 2781 2782 if (e !== true) { 2783 $.nfancybox.stop(current.$slide); 2784 } else { 2785 effect = false; 2786 } 2787 2788 // Remove other slides 2789 current.$slide 2790 .siblings() 2791 .trigger("onReset") 2792 .remove(); 2793 2794 // Trigger animations 2795 if (duration) { 2796 self.$refs.container 2797 .removeClass("nfancybox-is-open") 2798 .addClass("nfancybox-is-closing") 2799 .css("transition-duration", duration + "ms"); 2800 } 2801 2802 // Clean up 2803 self.hideLoading(current); 2804 2805 self.hideControls(true); 2806 2807 self.updateCursor(); 2808 2809 // Check if possible to zoom-out 2810 if ( 2811 effect === "zoom" && 2812 !($content && duration && current.type === "image" && !self.isMoved() && !current.hasError && (end = self.getThumbPos(current))) 2813 ) { 2814 effect = "fade"; 2815 } 2816 2817 if (effect === "zoom") { 2818 $.nfancybox.stop($content); 2819 2820 domRect = $.nfancybox.getTranslate($content); 2821 2822 start = { 2823 top: domRect.top, 2824 left: domRect.left, 2825 scaleX: domRect.width / end.width, 2826 scaleY: domRect.height / end.height, 2827 width: end.width, 2828 height: end.height 2829 }; 2830 2831 // Check if we need to animate opacity 2832 opacity = current.opts.zoomOpacity; 2833 2834 if (opacity == "auto") { 2835 opacity = Math.abs(current.width / current.height - end.width / end.height) > 0.1; 2836 } 2837 2838 if (opacity) { 2839 end.opacity = 0; 2840 } 2841 2842 $.nfancybox.setTranslate($content, start); 2843 2844 forceRedraw($content); 2845 2846 $.nfancybox.animate($content, end, duration, done); 2847 2848 return true; 2849 } 2850 2851 if (effect && duration) { 2852 $.nfancybox.animate( 2853 current.$slide.addClass("nfancybox-slide--previous").removeClass("nfancybox-slide--current"), 2854 "nfancybox-animated nfancybox-fx-" + effect, 2855 duration, 2856 done 2857 ); 2858 } else { 2859 // If skip animation 2860 if (e === true) { 2861 setTimeout(done, duration); 2862 } else { 2863 done(); 2864 } 2865 } 2866 2867 return true; 2868 }, 2869 2870 // Final adjustments after removing the instance 2871 // ============================================= 2872 2873 cleanUp: function (e) { 2874 var self = this, 2875 instance, 2876 $focus = self.current.opts.$orig, 2877 x, 2878 y; 2879 2880 self.current.$slide.trigger("onReset"); 2881 2882 self.$refs.container.empty().remove(); 2883 2884 self.trigger("afterClose", e); 2885 2886 // Place back focus 2887 if (!!self.current.opts.backFocus) { 2888 if (!$focus || !$focus.length || !$focus.is(":visible")) { 2889 $focus = self.$trigger; 2890 } 2891 2892 if ($focus && $focus.length) { 2893 x = window.scrollX; 2894 y = window.scrollY; 2895 2896 $focus.trigger("focus"); 2897 2898 $("html, body") 2899 .scrollTop(y) 2900 .scrollLeft(x); 2901 } 2902 } 2903 2904 self.current = null; 2905 2906 // Check if there are other instances 2907 instance = $.nfancybox.getInstance(); 2908 2909 if (instance) { 2910 instance.activate(); 2911 } else { 2912 $("body").removeClass("nfancybox-active compensate-for-scrollbar"); 2913 2914 $("#nfancybox-style-noscroll").remove(); 2915 } 2916 }, 2917 2918 // Call callback and trigger an event 2919 // ================================== 2920 2921 trigger: function (name, slide) { 2922 var args = Array.prototype.slice.call(arguments, 1), 2923 self = this, 2924 obj = slide && slide.opts ? slide : self.current, 2925 rez; 2926 2927 if (obj) { 2928 args.unshift(obj); 2929 } else { 2930 obj = self; 2931 } 2932 2933 args.unshift(self); 2934 2935 if ($.isFunction(obj.opts[name])) { 2936 rez = obj.opts[name].apply(obj, args); 2937 } 2938 2939 if (rez === false) { 2940 return rez; 2941 } 2942 2943 if (name === "afterClose" || !self.$refs) { 2944 $D.trigger(name + ".fb", args); 2945 } else { 2946 self.$refs.container.trigger(name + ".fb", args); 2947 } 2948 }, 2949 2950 // Update infobar values, navigation button states and reveal caption 2951 // ================================================================== 2952 2953 updateControls: function () { 2954 var self = this, 2955 current = self.current, 2956 index = current.index, 2957 $container = self.$refs.container, 2958 $caption = self.$refs.caption, 2959 caption = current.opts.caption; 2960 2961 // Recalculate content dimensions 2962 current.$slide.trigger("refresh"); 2963 2964 // Set caption 2965 if (caption && caption.length) { 2966 self.$caption = $caption; 2967 2968 $caption 2969 .children() 2970 .eq(0) 2971 .html(caption); 2972 } else { 2973 self.$caption = null; 2974 } 2975 2976 if (!self.hasHiddenControls && !self.isIdle) { 2977 self.showControls(); 2978 } 2979 2980 // Update info and navigation elements 2981 $container.find("[data-nfancybox-count]").html(self.group.length); 2982 $container.find("[data-nfancybox-index]").html(index + 1); 2983 2984 $container.find("[data-nfancybox-prev]").prop("disabled", !current.opts.loop && index <= 0); 2985 $container.find("[data-nfancybox-next]").prop("disabled", !current.opts.loop && index >= self.group.length - 1); 2986 2987 if (current.type === "image") { 2988 // Re-enable buttons; update download button source 2989 $container 2990 .find("[data-nfancybox-zoom]") 2991 .show() 2992 .end() 2993 .find("[data-nfancybox-download]") 2994 .attr("href", current.opts.image.src || current.src) 2995 .show(); 2996 } else if (current.opts.toolbar) { 2997 $container.find("[data-nfancybox-download],[data-nfancybox-zoom]").hide(); 2998 } 2999 3000 // Make sure focus is not on disabled button/element 3001 if ($(document.activeElement).is(":hidden,[disabled]")) { 3002 self.$refs.container.trigger("focus"); 3003 } 3004 }, 3005 3006 // Hide toolbar and caption 3007 // ======================== 3008 3009 hideControls: function (andCaption) { 3010 var self = this, 3011 arr = ["infobar", "toolbar", "nav"]; 3012 3013 if (andCaption || !self.current.opts.preventCaptionOverlap) { 3014 arr.push("caption"); 3015 } 3016 3017 this.$refs.container.removeClass( 3018 arr 3019 .map(function (i) { 3020 return "nfancybox-show-" + i; 3021 }) 3022 .join(" ") 3023 ); 3024 3025 this.hasHiddenControls = true; 3026 }, 3027 3028 showControls: function () { 3029 var self = this, 3030 opts = self.current ? self.current.opts : self.opts, 3031 $container = self.$refs.container; 3032 3033 self.hasHiddenControls = false; 3034 self.idleSecondsCounter = 0; 3035 3036 $container 3037 .toggleClass("nfancybox-show-toolbar", !!(opts.toolbar && opts.buttons)) 3038 .toggleClass("nfancybox-show-infobar", !!(opts.infobar && self.group.length > 1)) 3039 .toggleClass("nfancybox-show-caption", !!self.$caption) 3040 .toggleClass("nfancybox-show-nav", !!(opts.arrows && self.group.length > 1)) 3041 .toggleClass("nfancybox-is-modal", !!opts.modal); 3042 }, 3043 3044 // Toggle toolbar and caption 3045 // ========================== 3046 3047 toggleControls: function () { 3048 if (this.hasHiddenControls) { 3049 this.showControls(); 3050 } else { 3051 this.hideControls(); 3052 } 3053 } 3054 }); 3055 3056 $.nfancybox = { 3057 version: "3.5.7", 3058 defaults: defaults, 3059 3060 // Get current instance and execute a command. 3061 // 3062 // Examples of usage: 3063 // 3064 // $instance = $.nfancybox.getInstance(); 3065 // $.nfancybox.getInstance().jumpTo( 1 ); 3066 // $.nfancybox.getInstance( 'jumpTo', 1 ); 3067 // $.nfancybox.getInstance( function() { 3068 // console.info( this.currIndex ); 3069 // }); 3070 // ====================================================== 3071 3072 getInstance: function (command) { 3073 var instance = $('.nfancybox-container:not(".nfancybox-is-closing"):last').data("nFancyBox"), 3074 args = Array.prototype.slice.call(arguments, 1); 3075 3076 if (instance instanceof nFancyBox) { 3077 if ($.type(command) === "string") { 3078 instance[command].apply(instance, args); 3079 } else if ($.type(command) === "function") { 3080 command.apply(instance, args); 3081 } 3082 3083 return instance; 3084 } 3085 3086 return false; 3087 }, 3088 3089 // Create new instance 3090 // =================== 3091 3092 open: function (items, opts, index) { 3093 setTimeout(function(e){ 3094 playPauseVideo("pause"); 3095 },500); 3096 return new nFancyBox(items, opts, index); 3097 }, 3098 3099 // Close current or all instances 3100 // ============================== 3101 3102 close: function (all) { 3103 var instance = this.getInstance(); 3104 3105 if (instance) { 3106 instance.close(); 3107 3108 // Try to find and close next instance 3109 if (all === true) { 3110 this.close(all); 3111 } 3112 } 3113 }, 3114 3115 // Close all instances and unbind all events 3116 // ========================================= 3117 3118 destroy: function () { 3119 this.close(true); 3120 3121 $D.add("body").off("click.fb-start", "**"); 3122 }, 3123 3124 // Try to detect mobile devices 3125 // ============================ 3126 3127 isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), 3128 3129 // Detect if 'translate3d' support is available 3130 // ============================================ 3131 3132 use3d: (function () { 3133 var div = document.createElement("div"); 3134 3135 return ( 3136 window.getComputedStyle && 3137 window.getComputedStyle(div) && 3138 window.getComputedStyle(div).getPropertyValue("transform") && 3139 !(document.documentMode && document.documentMode < 11) 3140 ); 3141 })(), 3142 3143 // Helper function to get current visual state of an element 3144 // returns array[ top, left, horizontal-scale, vertical-scale, opacity ] 3145 // ===================================================================== 3146 3147 getTranslate: function ($el) { 3148 var domRect; 3149 3150 if (!$el || !$el.length) { 3151 return false; 3152 } 3153 3154 domRect = $el[0].getBoundingClientRect(); 3155 3156 return { 3157 top: domRect.top || 0, 3158 left: domRect.left || 0, 3159 width: domRect.width, 3160 height: domRect.height, 3161 opacity: parseFloat($el.css("opacity")) 3162 }; 3163 }, 3164 3165 // Shortcut for setting "translate3d" properties for element 3166 // Can set be used to set opacity, too 3167 // ======================================================== 3168 3169 setTranslate: function ($el, props) { 3170 var str = "", 3171 css = {}; 3172 3173 if (!$el || !props) { 3174 return; 3175 } 3176 3177 if (props.left !== undefined || props.top !== undefined) { 3178 str = 3179 (props.left === undefined ? $el.position().left : props.left) + 3180 "px, " + 3181 (props.top === undefined ? $el.position().top : props.top) + 3182 "px"; 3183 3184 if (this.use3d) { 3185 str = "translate3d(" + str + ", 0px)"; 3186 } else { 3187 str = "translate(" + str + ")"; 3188 } 3189 } 3190 3191 if (props.scaleX !== undefined && props.scaleY !== undefined) { 3192 str += " scale(" + props.scaleX + ", " + props.scaleY + ")"; 3193 } else if (props.scaleX !== undefined) { 3194 str += " scaleX(" + props.scaleX + ")"; 3195 } 3196 3197 if (str.length) { 3198 css.transform = str; 3199 } 3200 3201 if (props.opacity !== undefined) { 3202 css.opacity = props.opacity; 3203 } 3204 3205 if (props.width !== undefined) { 3206 css.width = props.width; 3207 } 3208 3209 if (props.height !== undefined) { 3210 css.height = props.height; 3211 } 3212 3213 return $el.css(css); 3214 }, 3215 3216 // Simple CSS transition handler 3217 // ============================= 3218 3219 animate: function ($el, to, duration, callback, leaveAnimationName) { 3220 var self = this, 3221 from; 3222 3223 if ($.isFunction(duration)) { 3224 callback = duration; 3225 duration = null; 3226 } 3227 3228 self.stop($el); 3229 3230 from = self.getTranslate($el); 3231 3232 $el.on(transitionEnd, function (e) { 3233 // Skip events from child elements and z-index change 3234 if (e && e.originalEvent && (!$el.is(e.originalEvent.target) || e.originalEvent.propertyName == "z-index")) { 3235 return; 3236 } 3237 3238 self.stop($el); 3239 3240 if ($.isNumeric(duration)) { 3241 $el.css("transition-duration", ""); 3242 } 3243 3244 if ($.isPlainObject(to)) { 3245 if (to.scaleX !== undefined && to.scaleY !== undefined) { 3246 self.setTranslate($el, { 3247 top: to.top, 3248 left: to.left, 3249 width: from.width * to.scaleX, 3250 height: from.height * to.scaleY, 3251 scaleX: 1, 3252 scaleY: 1 3253 }); 3254 } 3255 } else if (leaveAnimationName !== true) { 3256 $el.removeClass(to); 3257 } 3258 3259 if ($.isFunction(callback)) { 3260 callback(e); 3261 } 3262 }); 3263 3264 if ($.isNumeric(duration)) { 3265 $el.css("transition-duration", duration + "ms"); 3266 } 3267 3268 // Start animation by changing CSS properties or class name 3269 if ($.isPlainObject(to)) { 3270 if (to.scaleX !== undefined && to.scaleY !== undefined) { 3271 delete to.width; 3272 delete to.height; 3273 3274 if ($el.parent().hasClass("nfancybox-slide--image")) { 3275 $el.parent().addClass("nfancybox-is-scaling"); 3276 } 3277 } 3278 3279 $.nfancybox.setTranslate($el, to); 3280 } else { 3281 $el.addClass(to); 3282 } 3283 3284 // Make sure that `transitionend` callback gets fired 3285 $el.data( 3286 "timer", 3287 setTimeout(function () { 3288 $el.trigger(transitionEnd); 3289 }, duration + 33) 3290 ); 3291 }, 3292 3293 stop: function ($el, callCallback) { 3294 if ($el && $el.length) { 3295 clearTimeout($el.data("timer")); 3296 3297 if (callCallback) { 3298 $el.trigger(transitionEnd); 3299 } 3300 3301 $el.off(transitionEnd).css("transition-duration", ""); 3302 3303 $el.parent().removeClass("nfancybox-is-scaling"); 3304 } 3305 } 3306 }; 3307 3308 // Default click handler for "nfancyboxed" links 3309 // ============================================ 3310 3311 function _run(e, opts) { 3312 var items = [], 3313 index = 0, 3314 $target, 3315 value, 3316 instance; 3317 3318 // Avoid opening multiple times 3319 if (e && e.isDefaultPrevented()) { 3320 return; 3321 } 3322 3323 e.preventDefault(); 3324 3325 opts = opts || {}; 3326 3327 if (e && e.data) { 3328 opts = mergeOpts(e.data.options, opts); 3329 } 3330 3331 $target = opts.$target || $(e.currentTarget).trigger("blur"); 3332 instance = $.nfancybox.getInstance(); 3333 3334 if (instance && instance.$trigger && instance.$trigger.is($target)) { 3335 return; 3336 } 3337 3338 if (opts.selector) { 3339 items = $(opts.selector); 3340 } else { 3341 // Get all related items and find index for clicked one 3342 value = $target.attr("data-nfancybox") || ""; 3343 3344 if (value) { 3345 items = e.data ? e.data.items : []; 3346 items = items.length ? items.filter('[data-nfancybox="' + value + '"]') : $('[data-nfancybox="' + value + '"]'); 3347 } else { 3348 items = [$target]; 3349 } 3350 } 3351 3352 index = $(items).index($target); 3353 3354 // Sometimes current item can not be found 3355 if (index < 0) { 3356 index = 0; 3357 } 3358 3359 instance = $.nfancybox.open(items, opts, index); 3360 3361 // Save last active element 3362 instance.$trigger = $target; 3363 } 3364 3365 // Create a jQuery plugin 3366 // ====================== 3367 3368 $.fn.nfancybox = function (options) { 3369 var selector; 3370 3371 options = options || {}; 3372 selector = options.selector || false; 3373 3374 if (selector) { 3375 // Use body element instead of document so it executes first 3376 $("body") 3377 .off("click.fb-start", selector) 3378 .on("click.fb-start", selector, { 3379 options: options 3380 }, _run); 3381 } else { 3382 this.off("click.fb-start").on( 3383 "click.fb-start", { 3384 items: this, 3385 options: options 3386 }, 3387 _run 3388 ); 3389 } 3390 3391 return this; 3392 }; 3393 3394 // Self initializing plugin for all elements having `data-nfancybox` attribute 3395 // ========================================================================== 3396 3397 $D.on("click.fb-start", "[data-nfancybox]", _run); 3398 3399 // Enable "trigger elements" 3400 // ========================= 3401 3402 $D.on("click.fb-start", "[data-nfancybox-trigger]", function (e) { 3403 $('[data-nfancybox="' + $(this).attr("data-nfancybox-trigger") + '"]') 3404 .eq($(this).attr("data-nfancybox-index") || 0) 3405 .trigger("click.fb-start", { 3406 $trigger: $(this) 3407 }); 3408 }); 3409 3410 // Track focus event for better accessibility styling 3411 // ================================================== 3412 (function () { 3413 var buttonStr = ".nfancybox-button", 3414 focusStr = "nfancybox-focus", 3415 $pressed = null; 3416 3417 $D.on("mousedown mouseup focus blur", buttonStr, function (e) { 3418 switch (e.type) { 3419 case "mousedown": 3420 $pressed = $(this); 3421 break; 3422 case "mouseup": 3423 $pressed = null; 3424 break; 3425 case "focusin": 3426 $(buttonStr).removeClass(focusStr); 3427 3428 if (!$(this).is($pressed) && !$(this).is("[disabled]")) { 3429 $(this).addClass(focusStr); 3430 } 3431 break; 3432 case "focusout": 3433 $(buttonStr).removeClass(focusStr); 3434 break; 3435 } 3436 }); 3437 })(); 3438})(window, document, jQuery); 3439// ========================================================================== 3440// 3441// Media 3442// Adds additional media type support 3443// 3444// ========================================================================== 3445(function ($) { 3446 "use strict"; 3447 3448 // Object containing properties for each media type 3449 var defaults = { 3450 youtube: { 3451 matcher: /(youtube\.com|youtu\.be|youtube\-nocookie\.com)\/(watch\?(.*&)?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*))(.*)/i, 3452 params: { 3453 autoplay: 1, 3454 autohide: 1, 3455 fs: 1, 3456 rel: 0, 3457 hd: 1, 3458 wmode: "transparent", 3459 enablejsapi: 1, 3460 html5: 1 3461 }, 3462 paramPlace: 8, 3463 type: "iframe", 3464 url: "https://www.youtube-nocookie.com/embed/$4", 3465 thumb: "https://img.youtube.com/vi/$4/hqdefault.jpg" 3466 }, 3467 3468 vimeo: { 3469 matcher: /^.+vimeo.com\/(.*\/)?([\d]+)(.*)?/, 3470 params: { 3471 autoplay: 1, 3472 hd: 1, 3473 show_title: 1, 3474 show_byline: 1, 3475 show_portrait: 0, 3476 fullscreen: 1 3477 }, 3478 paramPlace: 3, 3479 type: "iframe", 3480 url: "//player.vimeo.com/video/$2" 3481 }, 3482 3483 instagram: { 3484 matcher: /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i, 3485 type: "image", 3486 url: "//$1/p/$2/media/?size=l" 3487 }, 3488 3489 // Examples: 3490 // http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16 3491 // https://www.google.com/maps/@37.7852006,-122.4146355,14.65z 3492 // https://www.google.com/maps/@52.2111123,2.9237542,6.61z?hl=en 3493 // https://www.google.com/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572 3494 gmap_place: { 3495 matcher: /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i, 3496 type: "iframe", 3497 url: function (rez) { 3498 return ( 3499 "//maps.google." + 3500 rez[2] + 3501 "/?ll=" + 3502 (rez[9] ? rez[9] + "&z=" + Math.floor(rez[10]) + (rez[12] ? rez[12].replace(/^\//, "&") : "") : rez[12] + "").replace(/\?/, "&") + 3503 "&output=" + 3504 (rez[12] && rez[12].indexOf("layer=c") > 0 ? "svembed" : "embed") 3505 ); 3506 } 3507 }, 3508 3509 // Examples: 3510 // https://www.google.com/maps/search/Empire+State+Building/ 3511 // https://www.google.com/maps/search/?api=1&query=centurylink+field 3512 // https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393 3513 gmap_search: { 3514 matcher: /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(maps\/search\/)(.*)/i, 3515 type: "iframe", 3516 url: function (rez) { 3517 return "//maps.google." + rez[2] + "/maps?q=" + rez[5].replace("query=", "q=").replace("api=1", "") + "&output=embed"; 3518 } 3519 } 3520 }; 3521 3522 // Formats matching url to final form 3523 var format = function (url, rez, params) { 3524 if (!url) { 3525 return; 3526 } 3527 3528 params = params || ""; 3529 3530 if ($.type(params) === "object") { 3531 params = $.param(params, true); 3532 } 3533 3534 $.each(rez, function (key, value) { 3535 url = url.replace("$" + key, value || ""); 3536 }); 3537 3538 if (params.length) { 3539 url += (url.indexOf("?") > 0 ? "&" : "?") + params; 3540 } 3541 3542 return url; 3543 }; 3544 3545 $(document).on("objectNeedsType.fb", function (e, instance, item) { 3546 var url = item.src || "", 3547 type = false, 3548 media, 3549 thumb, 3550 rez, 3551 params, 3552 urlParams, 3553 paramObj, 3554 provider; 3555 3556 media = $.extend(true, {}, defaults, item.opts.media); 3557 3558 // Look for any matching media type 3559 $.each(media, function (providerName, providerOpts) { 3560 rez = url.match(providerOpts.matcher); 3561 3562 if (!rez) { 3563 return; 3564 } 3565 3566 type = providerOpts.type; 3567 provider = providerName; 3568 paramObj = {}; 3569 3570 if (providerOpts.paramPlace && rez[providerOpts.paramPlace]) { 3571 urlParams = rez[providerOpts.paramPlace]; 3572 3573 if (urlParams[0] == "?") { 3574 urlParams = urlParams.substring(1); 3575 } 3576 3577 urlParams = urlParams.split("&"); 3578 3579 for (var m = 0; m < urlParams.length; ++m) { 3580 var p = urlParams[m].split("=", 2); 3581 3582 if (p.length == 2) { 3583 paramObj[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); 3584 } 3585 } 3586 } 3587 3588 params = $.extend(true, {}, providerOpts.params, item.opts[providerName], paramObj); 3589 3590 url = 3591 $.type(providerOpts.url) === "function" ? providerOpts.url.call(this, rez, params, item) : format(providerOpts.url, rez, params); 3592 3593 thumb = 3594 $.type(providerOpts.thumb) === "function" ? providerOpts.thumb.call(this, rez, params, item) : format(providerOpts.thumb, rez); 3595 3596 if (providerName === "youtube") { 3597 url = url.replace(/&t=((\d+)m)?(\d+)s/, function (match, p1, m, s) { 3598 return "&start=" + ((m ? parseInt(m, 10) * 60 : 0) + parseInt(s, 10)); 3599 }); 3600 } else if (providerName === "vimeo") { 3601 url = url.replace("&%23", "#"); 3602 } 3603 3604 return false; 3605 }); 3606 3607 // If it is found, then change content type and update the url 3608 3609 if (type) { 3610 if (!item.opts.thumb && !(item.opts.$thumb && item.opts.$thumb.length)) { 3611 item.opts.thumb = thumb; 3612 } 3613 3614 if (type === "iframe") { 3615 item.opts = $.extend(true, item.opts, { 3616 iframe: { 3617 preload: false, 3618 attr: { 3619 scrolling: "no" 3620 } 3621 } 3622 }); 3623 } 3624 3625 $.extend(item, { 3626 type: type, 3627 src: url, 3628 origSrc: item.src, 3629 contentSource: provider, 3630 contentType: type === "image" ? "image" : provider == "gmap_place" || provider == "gmap_search" ? "map" : "video" 3631 }); 3632 } else if (url) { 3633 item.type = item.opts.defaultType; 3634 } 3635 }); 3636 3637 // Load YouTube/Video API on request to detect when video finished playing 3638 var VideoAPILoader = { 3639 youtube: { 3640 src: "https://www.youtube.com/iframe_api", 3641 class: "YT", 3642 loading: false, 3643 loaded: false 3644 }, 3645 3646 vimeo: { 3647 src: "https://player.vimeo.com/api/player.js", 3648 class: "Vimeo", 3649 loading: false, 3650 loaded: false 3651 }, 3652 3653 load: function (vendor) { 3654 var _this = this, 3655 script; 3656 3657 if (this[vendor].loaded) { 3658 setTimeout(function () { 3659 _this.done(vendor); 3660 }); 3661 return; 3662 } 3663 3664 if (this[vendor].loading) { 3665 return; 3666 } 3667 3668 this[vendor].loading = true; 3669 3670 script = document.createElement("script"); 3671 script.type = "text/javascript"; 3672 script.src = this[vendor].src; 3673 3674 if (vendor === "youtube") { 3675 window.onYouTubeIframeAPIReady = function () { 3676 _this[vendor].loaded = true; 3677 _this.done(vendor); 3678 }; 3679 } else { 3680 script.onload = function () { 3681 _this[vendor].loaded = true; 3682 _this.done(vendor); 3683 }; 3684 } 3685 3686 document.body.appendChild(script); 3687 }, 3688 done: function (vendor) { 3689 var instance, $el, player; 3690 3691 if (vendor === "youtube") { 3692 // delete window.onYouTubeIframeAPIReady; 3693 } 3694 3695 instance = $.nfancybox.getInstance(); 3696 3697 if (instance) { 3698 $el = instance.current.$content.find("iframe"); 3699 3700 if (vendor === "youtube" && YT !== undefined && YT) { 3701 player = new YT.Player($el.attr("id"), { 3702 events: { 3703 onStateChange: function (e) { 3704 if (e.data == 0) { 3705 instance.next(); 3706 } 3707 } 3708 } 3709 }); 3710 } else if (vendor === "vimeo" && Vimeo !== undefined && Vimeo) { 3711 player = new Vimeo.Player($el); 3712 3713 player.on("ended", function () { 3714 instance.next(); 3715 }); 3716 } 3717 } 3718 } 3719 }; 3720 3721 $(document).on({ 3722 "afterShow.fb": function (e, instance, current) { 3723 if (instance.group.length > 1 && (current.contentSource === "youtube" || current.contentSource === "vimeo")) { 3724 VideoAPILoader.load(current.contentSource); 3725 } 3726 } 3727 }); 3728})(jQuery); 3729// ========================================================================== 3730// 3731// Guestures 3732// Adds touch guestures, handles click and tap events 3733// 3734// ========================================================================== 3735(function (window, document, $) { 3736 "use strict"; 3737 3738 var requestAFrame = (function () { 3739 return ( 3740 window.requestAnimationFrame || 3741 window.webkitRequestAnimationFrame || 3742 window.mozRequestAnimationFrame || 3743 window.oRequestAnimationFrame || 3744 // if all else fails, use setTimeout 3745 function (callback) { 3746 return window.setTimeout(callback, 1000 / 60); 3747 } 3748 ); 3749 })(); 3750 3751 var cancelAFrame = (function () { 3752 return ( 3753 window.cancelAnimationFrame || 3754 window.webkitCancelAnimationFrame || 3755 window.mozCancelAnimationFrame || 3756 window.oCancelAnimationFrame || 3757 function (id) { 3758 window.clearTimeout(id); 3759 } 3760 ); 3761 })(); 3762 3763 var getPointerXY = function (e) { 3764 var result = []; 3765 3766 e = e.originalEvent || e || window.e; 3767 e = e.touches && e.touches.length ? e.touches : e.changedTouches && e.changedTouches.length ? e.changedTouches : [e]; 3768 3769 for (var key in e) { 3770 if (e[key].pageX) { 3771 result.push({ 3772 x: e[key].pageX, 3773 y: e[key].pageY 3774 }); 3775 } else if (e[key].clientX) { 3776 result.push({ 3777 x: e[key].clientX, 3778 y: e[key].clientY 3779 }); 3780 } 3781 } 3782 3783 return result; 3784 }; 3785 3786 var distance = function (point2, point1, what) { 3787 if (!point1 || !point2) { 3788 return 0; 3789 } 3790 3791 if (what === "x") { 3792 return point2.x - point1.x; 3793 } else if (what === "y") { 3794 return point2.y - point1.y; 3795 } 3796 3797 return Math.sqrt(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2)); 3798 }; 3799 3800 var isClickable = function ($el) { 3801 if ( 3802 $el.is('a,area,button,[role="button"],input,label,select,summary,textarea,video,audio,iframe') || 3803 $.isFunction($el.get(0).onclick) || 3804 $el.data("selectable") 3805 ) { 3806 return true; 3807 } 3808 3809 // Check for attributes like data-nfancybox-next or data-nfancybox-close 3810 for (var i = 0, atts = $el[0].attributes, n = atts.length; i < n; i++) { 3811 if (atts[i].nodeName.substr(0, 14) === "data-nfancybox-") { 3812 return true; 3813 } 3814 } 3815 3816 return false; 3817 }; 3818 3819 var hasScrollbars = function (el) { 3820 var overflowY = window.getComputedStyle(el)["overflow-y"], 3821 overflowX = window.getComputedStyle(el)["overflow-x"], 3822 vertical = (overflowY === "scroll" || overflowY === "auto") && el.scrollHeight > el.clientHeight, 3823 horizontal = (overflowX === "scroll" || overflowX === "auto") && el.scrollWidth > el.clientWidth; 3824 3825 return vertical || horizontal; 3826 }; 3827 3828 var isScrollable = function ($el) { 3829 var rez = false; 3830 3831 while (true) { 3832 rez = hasScrollbars($el.get(0)); 3833 3834 if (rez) { 3835 break; 3836 } 3837 3838 $el = $el.parent(); 3839 3840 if (!$el.length || $el.hasClass("nfancybox-stage") || $el.is("body")) { 3841 break; 3842 } 3843 } 3844 3845 return rez; 3846 }; 3847 3848 var Guestures = function (instance) { 3849 var self = this; 3850 3851 self.instance = instance; 3852 3853 self.$bg = instance.$refs.bg; 3854 self.$stage = instance.$refs.stage; 3855 self.$container = instance.$refs.container; 3856 3857 self.destroy(); 3858 3859 self.$container.on("touchstart.fb.touch mousedown.fb.touch", $.proxy(self, "ontouchstart")); 3860 }; 3861 3862 Guestures.prototype.destroy = function () { 3863 var self = this; 3864 3865 self.$container.off(".fb.touch"); 3866 3867 $(document).off(".fb.touch"); 3868 3869 if (self.requestId) { 3870 cancelAFrame(self.requestId); 3871 self.requestId = null; 3872 } 3873 3874 if (self.tapped) { 3875 clearTimeout(self.tapped); 3876 self.tapped = null; 3877 } 3878 }; 3879 3880 Guestures.prototype.ontouchstart = function (e) { 3881 var self = this, 3882 $target = $(e.target), 3883 instance = self.instance, 3884 current = instance.current, 3885 $slide = current.$slide, 3886 $content = current.$content, 3887 isTouchDevice = e.type == "touchstart"; 3888 3889 // Do not respond to both (touch and mouse) events 3890 if (isTouchDevice) { 3891 self.$container.off("mousedown.fb.touch"); 3892 } 3893 3894 // Ignore right click 3895 if (e.originalEvent && e.originalEvent.button == 2) { 3896 return; 3897 } 3898 3899 // Ignore taping on links, buttons, input elements 3900 if (!$slide.length || !$target.length || isClickable($target) || isClickable($target.parent())) { 3901 return; 3902 } 3903 // Ignore clicks on the scrollbar 3904 if (!$target.is("img") && e.originalEvent.clientX > $target[0].clientWidth + $target.offset().left) { 3905 return; 3906 } 3907 3908 // Ignore clicks while zooming or closing 3909 if (!current || instance.isAnimating || current.$slide.hasClass("nfancybox-animated")) { 3910 e.stopPropagation(); 3911 e.preventDefault(); 3912 3913 return; 3914 } 3915 3916 self.realPoints = self.startPoints = getPointerXY(e); 3917 3918 if (!self.startPoints.length) { 3919 return; 3920 } 3921 3922 // Allow other scripts to catch touch event if "touch" is set to false 3923 if (current.touch) { 3924 e.stopPropagation(); 3925 } 3926 3927 self.startEvent = e; 3928 3929 self.canTap = true; 3930 self.$target = $target; 3931 self.$content = $content; 3932 self.opts = current.opts.touch; 3933 3934 self.isPanning = false; 3935 self.isSwiping = false; 3936 self.isZooming = false; 3937 self.isScrolling = false; 3938 self.canPan = instance.canPan(); 3939 3940 self.startTime = new Date().getTime(); 3941 self.distanceX = self.distanceY = self.distance = 0; 3942 3943 self.canvasWidth = Math.round($slide[0].clientWidth); 3944 self.canvasHeight = Math.round($slide[0].clientHeight); 3945 3946 self.contentLastPos = null; 3947 self.contentStartPos = $.nfancybox.getTranslate(self.$content) || { 3948 top: 0, 3949 left: 0 3950 }; 3951 self.sliderStartPos = $.nfancybox.getTranslate($slide); 3952 3953 // Since position will be absolute, but we need to make it relative to the stage 3954 self.stagePos = $.nfancybox.getTranslate(instance.$refs.stage); 3955 3956 self.sliderStartPos.top -= self.stagePos.top; 3957 self.sliderStartPos.left -= self.stagePos.left; 3958 3959 self.contentStartPos.top -= self.stagePos.top; 3960 self.contentStartPos.left -= self.stagePos.left; 3961 3962 $(document) 3963 .off(".fb.touch") 3964 .on(isTouchDevice ? "touchend.fb.touch touchcancel.fb.touch" : "mouseup.fb.touch mouseleave.fb.touch", $.proxy(self, "ontouchend")) 3965 .on(isTouchDevice ? "touchmove.fb.touch" : "mousemove.fb.touch", $.proxy(self, "ontouchmove")); 3966 3967 if ($.nfancybox.isMobile) { 3968 document.addEventListener("scroll", self.onscroll, true); 3969 } 3970 3971 // Skip if clicked outside the sliding area 3972 if (!(self.opts || self.canPan) || !($target.is(self.$stage) || self.$stage.find($target).length)) { 3973 if ($target.is(".nfancybox-image")) { 3974 e.preventDefault(); 3975 } 3976 3977 if (!($.nfancybox.isMobile && $target.parents(".nfancybox-caption").length)) { 3978 return; 3979 } 3980 } 3981 3982 self.isScrollable = isScrollable($target) || isScrollable($target.parent()); 3983 3984 // Check if element is scrollable and try to prevent default behavior (scrolling) 3985 if (!($.nfancybox.isMobile && self.isScrollable)) { 3986 e.preventDefault(); 3987 } 3988 3989 // One finger or mouse click - swipe or pan an image 3990 if (self.startPoints.length === 1 || current.hasError) { 3991 if (self.canPan) { 3992 $.nfancybox.stop(self.$content); 3993 3994 self.isPanning = true; 3995 } else { 3996 self.isSwiping = true; 3997 } 3998 3999 self.$container.addClass("nfancybox-is-grabbing"); 4000 } 4001 4002 // Two fingers - zoom image 4003 if (self.startPoints.length === 2 && current.type === "image" && (current.isLoaded || current.$ghost)) { 4004 self.canTap = false; 4005 self.isSwiping = false; 4006 self.isPanning = false; 4007 4008 self.isZooming = true; 4009 4010 $.nfancybox.stop(self.$content); 4011 4012 self.centerPointStartX = (self.startPoints[0].x + self.startPoints[1].x) * 0.5 - $(window).scrollLeft(); 4013 self.centerPointStartY = (self.startPoints[0].y + self.startPoints[1].y) * 0.5 - $(window).scrollTop(); 4014 4015 self.percentageOfImageAtPinchPointX = (self.centerPointStartX - self.contentStartPos.left) / self.contentStartPos.width; 4016 self.percentageOfImageAtPinchPointY = (self.centerPointStartY - self.contentStartPos.top) / self.contentStartPos.height; 4017 4018 self.startDistanceBetweenFingers = distance(self.startPoints[0], self.startPoints[1]); 4019 } 4020 }; 4021 4022 Guestures.prototype.onscroll = function (e) { 4023 var self = this; 4024 4025 self.isScrolling = true; 4026 4027 document.removeEventListener("scroll", self.onscroll, true); 4028 }; 4029 4030 Guestures.prototype.ontouchmove = function (e) { 4031 var self = this; 4032 4033 // Make sure user has not released over iframe or disabled element 4034 if (e.originalEvent.buttons !== undefined && e.originalEvent.buttons === 0) { 4035 self.ontouchend(e); 4036 return; 4037 } 4038 4039 if (self.isScrolling) { 4040 self.canTap = false; 4041 return; 4042 } 4043 4044 self.newPoints = getPointerXY(e); 4045 4046 if (!(self.opts || self.canPan) || !self.newPoints.length || !self.newPoints.length) { 4047 return; 4048 } 4049 4050 if (!(self.isSwiping && self.isSwiping === true)) { 4051 e.preventDefault(); 4052 } 4053 4054 self.distanceX = distance(self.newPoints[0], self.startPoints[0], "x"); 4055 self.distanceY = distance(self.newPoints[0], self.startPoints[0], "y"); 4056 4057 self.distance = distance(self.newPoints[0], self.startPoints[0]); 4058 4059 // Skip false ontouchmove events (Chrome) 4060 if (self.distance > 0) { 4061 if (self.isSwiping) { 4062 self.onSwipe(e); 4063 } else if (self.isPanning) { 4064 self.onPan(); 4065 } else if (self.isZooming) { 4066 self.onZoom(); 4067 } 4068 } 4069 }; 4070 4071 Guestures.prototype.onSwipe = function (e) { 4072 var self = this, 4073 instance = self.instance, 4074 swiping = self.isSwiping, 4075 left = self.sliderStartPos.left || 0, 4076 angle; 4077 4078 // If direction is not yet determined 4079 if (swiping === true) { 4080 // We need at least 10px distance to correctly calculate an angle 4081 if (Math.abs(self.distance) > 10) { 4082 self.canTap = false; 4083 4084 if (instance.group.length < 2 && self.opts.vertical) { 4085 self.isSwiping = "y"; 4086 } else if (instance.isDragging || self.opts.vertical === false || (self.opts.vertical === "auto" && $(window).width() > 800)) { 4087 self.isSwiping = "x"; 4088 } else { 4089 angle = Math.abs((Math.atan2(self.distanceY, self.distanceX) * 180) / Math.PI); 4090 4091 self.isSwiping = angle > 45 && angle < 135 ? "y" : "x"; 4092 } 4093 4094 if (self.isSwiping === "y" && $.nfancybox.isMobile && self.isScrollable) { 4095 self.isScrolling = true; 4096 4097 return; 4098 } 4099 4100 instance.isDragging = self.isSwiping; 4101 4102 // Reset points to avoid jumping, because we dropped first swipes to calculate the angle 4103 self.startPoints = self.newPoints; 4104 4105 $.each(instance.slides, function (index, slide) { 4106 var slidePos, stagePos; 4107 4108 $.nfancybox.stop(slide.$slide); 4109 4110 slidePos = $.nfancybox.getTranslate(slide.$slide); 4111 stagePos = $.nfancybox.getTranslate(instance.$refs.stage); 4112 4113 slide.$slide 4114 .css({ 4115 transform: "", 4116 opacity: "", 4117 "transition-duration": "" 4118 }) 4119 .removeClass("nfancybox-animated") 4120 .removeClass(function (index, className) { 4121 return (className.match(/(^|\s)nfancybox-fx-\S+/g) || []).join(" "); 4122 }); 4123 4124 if (slide.pos === instance.current.pos) { 4125 self.sliderStartPos.top = slidePos.top - stagePos.top; 4126 self.sliderStartPos.left = slidePos.left - stagePos.left; 4127 } 4128 4129 $.nfancybox.setTranslate(slide.$slide, { 4130 top: slidePos.top - stagePos.top, 4131 left: slidePos.left - stagePos.left 4132 }); 4133 }); 4134 4135 // Stop slideshow 4136 if (instance.SlideShow && instance.SlideShow.isActive) { 4137 instance.SlideShow.stop(); 4138 } 4139 } 4140 4141 return; 4142 } 4143 4144 // Sticky edges 4145 if (swiping == "x") { 4146 if ( 4147 self.distanceX > 0 && 4148 (self.instance.group.length < 2 || (self.instance.current.index === 0 && !self.instance.current.opts.loop)) 4149 ) { 4150 left = left + Math.pow(self.distanceX, 0.8); 4151 } else if ( 4152 self.distanceX < 0 && 4153 (self.instance.group.length < 2 || 4154 (self.instance.current.index === self.instance.group.length - 1 && !self.instance.current.opts.loop)) 4155 ) { 4156 left = left - Math.pow(-self.distanceX, 0.8); 4157 } else { 4158 left = left + self.distanceX; 4159 } 4160 } 4161 4162 self.sliderLastPos = { 4163 top: swiping == "x" ? 0 : self.sliderStartPos.top + self.distanceY, 4164 left: left 4165 }; 4166 4167 if (self.requestId) { 4168 cancelAFrame(self.requestId); 4169 4170 self.requestId = null; 4171 } 4172 4173 self.requestId = requestAFrame(function () { 4174 if (self.sliderLastPos) { 4175 $.each(self.instance.slides, function (index, slide) { 4176 var pos = slide.pos - self.instance.currPos; 4177 4178 $.nfancybox.setTranslate(slide.$slide, { 4179 top: self.sliderLastPos.top, 4180 left: self.sliderLastPos.left + pos * self.canvasWidth + pos * slide.opts.gutter 4181 }); 4182 }); 4183 4184 self.$container.addClass("nfancybox-is-sliding"); 4185 } 4186 }); 4187 }; 4188 4189 Guestures.prototype.onPan = function () { 4190 var self = this; 4191 4192 // Prevent accidental movement (sometimes, when tapping casually, finger can move a bit) 4193 if (distance(self.newPoints[0], self.realPoints[0]) < ($.nfancybox.isMobile ? 10 : 5)) { 4194 self.startPoints = self.newPoints; 4195 return; 4196 } 4197 4198 self.canTap = false; 4199 4200 self.contentLastPos = self.limitMovement(); 4201 4202 if (self.requestId) { 4203 cancelAFrame(self.requestId); 4204 } 4205 4206 self.requestId = requestAFrame(function () { 4207 $.nfancybox.setTranslate(self.$content, self.contentLastPos); 4208 }); 4209 }; 4210 4211 // Make panning sticky to the edges 4212 Guestures.prototype.limitMovement = function () { 4213 var self = this; 4214 4215 var canvasWidth = self.canvasWidth; 4216 var canvasHeight = self.canvasHeight; 4217 4218 var distanceX = self.distanceX; 4219 var distanceY = self.distanceY; 4220 4221 var contentStartPos = self.contentStartPos; 4222 4223 var currentOffsetX = contentStartPos.left; 4224 var currentOffsetY = contentStartPos.top; 4225 4226 var currentWidth = contentStartPos.width; 4227 var currentHeight = contentStartPos.height; 4228 4229 var minTranslateX, minTranslateY, maxTranslateX, maxTranslateY, newOffsetX, newOffsetY; 4230 4231 if (currentWidth > canvasWidth) { 4232 newOffsetX = currentOffsetX + distanceX; 4233 } else { 4234 newOffsetX = currentOffsetX; 4235 } 4236 4237 newOffsetY = currentOffsetY + distanceY; 4238 4239 // Slow down proportionally to traveled distance 4240 minTranslateX = Math.max(0, canvasWidth * 0.5 - currentWidth * 0.5); 4241 minTranslateY = Math.max(0, canvasHeight * 0.5 - currentHeight * 0.5); 4242 4243 maxTranslateX = Math.min(canvasWidth - currentWidth, canvasWidth * 0.5 - currentWidth * 0.5); 4244 maxTranslateY = Math.min(canvasHeight - currentHeight, canvasHeight * 0.5 - currentHeight * 0.5); 4245 4246 // -> 4247 if (distanceX > 0 && newOffsetX > minTranslateX) { 4248 newOffsetX = minTranslateX - 1 + Math.pow(-minTranslateX + currentOffsetX + distanceX, 0.8) || 0; 4249 } 4250 4251 // <- 4252 if (distanceX < 0 && newOffsetX < maxTranslateX) { 4253 newOffsetX = maxTranslateX + 1 - Math.pow(maxTranslateX - currentOffsetX - distanceX, 0.8) || 0; 4254 } 4255 4256 // \/ 4257 if (distanceY > 0 && newOffsetY > minTranslateY) { 4258 newOffsetY = minTranslateY - 1 + Math.pow(-minTranslateY + currentOffsetY + distanceY, 0.8) || 0; 4259 } 4260 4261 // /\ 4262 if (distanceY < 0 && newOffsetY < maxTranslateY) { 4263 newOffsetY = maxTranslateY + 1 - Math.pow(maxTranslateY - currentOffsetY - distanceY, 0.8) || 0; 4264 } 4265 4266 return { 4267 top: newOffsetY, 4268 left: newOffsetX 4269 }; 4270 }; 4271 4272 Guestures.prototype.limitPosition = function (newOffsetX, newOffsetY, newWidth, newHeight) { 4273 var self = this; 4274 4275 var canvasWidth = self.canvasWidth; 4276 var canvasHeight = self.canvasHeight; 4277 4278 if (newWidth > canvasWidth) { 4279 newOffsetX = newOffsetX > 0 ? 0 : newOffsetX; 4280 newOffsetX = newOffsetX < canvasWidth - newWidth ? canvasWidth - newWidth : newOffsetX; 4281 } else { 4282 // Center horizontally 4283 newOffsetX = Math.max(0, canvasWidth / 2 - newWidth / 2); 4284 } 4285 4286 if (newHeight > canvasHeight) { 4287 newOffsetY = newOffsetY > 0 ? 0 : newOffsetY; 4288 newOffsetY = newOffsetY < canvasHeight - newHeight ? canvasHeight - newHeight : newOffsetY; 4289 } else { 4290 // Center vertically 4291 newOffsetY = Math.max(0, canvasHeight / 2 - newHeight / 2); 4292 } 4293 4294 return { 4295 top: newOffsetY, 4296 left: newOffsetX 4297 }; 4298 }; 4299 4300 Guestures.prototype.onZoom = function () { 4301 var self = this; 4302 4303 // Calculate current distance between points to get pinch ratio and new width and height 4304 var contentStartPos = self.contentStartPos; 4305 4306 var currentWidth = contentStartPos.width; 4307 var currentHeight = contentStartPos.height; 4308 4309 var currentOffsetX = contentStartPos.left; 4310 var currentOffsetY = contentStartPos.top; 4311 4312 var endDistanceBetweenFingers = distance(self.newPoints[0], self.newPoints[1]); 4313 4314 var pinchRatio = endDistanceBetweenFingers / self.startDistanceBetweenFingers; 4315 4316 var newWidth = Math.floor(currentWidth * pinchRatio); 4317 var newHeight = Math.floor(currentHeight * pinchRatio); 4318 4319 // This is the translation due to pinch-zooming 4320 var translateFromZoomingX = (currentWidth - newWidth) * self.percentageOfImageAtPinchPointX; 4321 var translateFromZoomingY = (currentHeight - newHeight) * self.percentageOfImageAtPinchPointY; 4322 4323 // Point between the two touches 4324 var centerPointEndX = (self.newPoints[0].x + self.newPoints[1].x) / 2 - $(window).scrollLeft(); 4325 var centerPointEndY = (self.newPoints[0].y + self.newPoints[1].y) / 2 - $(window).scrollTop(); 4326 4327 // And this is the translation due to translation of the centerpoint 4328 // between the two fingers 4329 var translateFromTranslatingX = centerPointEndX - self.centerPointStartX; 4330 var translateFromTranslatingY = centerPointEndY - self.centerPointStartY; 4331 4332 // The new offset is the old/current one plus the total translation 4333 var newOffsetX = currentOffsetX + (translateFromZoomingX + translateFromTranslatingX); 4334 var newOffsetY = currentOffsetY + (translateFromZoomingY + translateFromTranslatingY); 4335 4336 var newPos = { 4337 top: newOffsetY, 4338 left: newOffsetX, 4339 scaleX: pinchRatio, 4340 scaleY: pinchRatio 4341 }; 4342 4343 self.canTap = false; 4344 4345 self.newWidth = newWidth; 4346 self.newHeight = newHeight; 4347 4348 self.contentLastPos = newPos; 4349 4350 if (self.requestId) { 4351 cancelAFrame(self.requestId); 4352 } 4353 4354 self.requestId = requestAFrame(function () { 4355 $.nfancybox.setTranslate(self.$content, self.contentLastPos); 4356 }); 4357 }; 4358 4359 Guestures.prototype.ontouchend = function (e) { 4360 var self = this; 4361 4362 var swiping = self.isSwiping; 4363 var panning = self.isPanning; 4364 var zooming = self.isZooming; 4365 var scrolling = self.isScrolling; 4366 4367 self.endPoints = getPointerXY(e); 4368 self.dMs = Math.max(new Date().getTime() - self.startTime, 1); 4369 4370 self.$container.removeClass("nfancybox-is-grabbing"); 4371 4372 $(document).off(".fb.touch"); 4373 4374 document.removeEventListener("scroll", self.onscroll, true); 4375 4376 if (self.requestId) { 4377 cancelAFrame(self.requestId); 4378 4379 self.requestId = null; 4380 } 4381 4382 self.isSwiping = false; 4383 self.isPanning = false; 4384 self.isZooming = false; 4385 self.isScrolling = false; 4386 4387 self.instance.isDragging = false; 4388 4389 if (self.canTap) { 4390 return self.onTap(e); 4391 } 4392 4393 self.speed = 100; 4394 4395 // Speed in px/ms 4396 self.velocityX = (self.distanceX / self.dMs) * 0.5; 4397 self.velocityY = (self.distanceY / self.dMs) * 0.5; 4398 4399 if (panning) { 4400 self.endPanning(); 4401 } else if (zooming) { 4402 self.endZooming(); 4403 } else { 4404 self.endSwiping(swiping, scrolling); 4405 } 4406 4407 return; 4408 }; 4409 4410 Guestures.prototype.endSwiping = function (swiping, scrolling) { 4411 var self = this, 4412 ret = false, 4413 len = self.instance.group.length, 4414 distanceX = Math.abs(self.distanceX), 4415 canAdvance = swiping == "x" && len > 1 && ((self.dMs > 130 && distanceX > 10) || distanceX > 50), 4416 speedX = 300; 4417 4418 self.sliderLastPos = null; 4419 4420 // Close if swiped vertically / navigate if horizontally 4421 if (swiping == "y" && !scrolling && Math.abs(self.distanceY) > 50) { 4422 // Continue vertical movement 4423 $.nfancybox.animate( 4424 self.instance.current.$slide, { 4425 top: self.sliderStartPos.top + self.distanceY + self.velocityY * 150, 4426 opacity: 0 4427 }, 4428 200 4429 ); 4430 ret = self.instance.close(true, 250); 4431 } else if (canAdvance && self.distanceX > 0) { 4432 ret = self.instance.previous(speedX); 4433 } else if (canAdvance && self.distanceX < 0) { 4434 ret = self.instance.next(speedX); 4435 } 4436 4437 if (ret === false && (swiping == "x" || swiping == "y")) { 4438 self.instance.centerSlide(200); 4439 } 4440 4441 self.$container.removeClass("nfancybox-is-sliding"); 4442 }; 4443 4444 // Limit panning from edges 4445 // ======================== 4446 Guestures.prototype.endPanning = function () { 4447 var self = this, 4448 newOffsetX, 4449 newOffsetY, 4450 newPos; 4451 4452 if (!self.contentLastPos) { 4453 return; 4454 } 4455 4456 if (self.opts.momentum === false || self.dMs > 350) { 4457 newOffsetX = self.contentLastPos.left; 4458 newOffsetY = self.contentLastPos.top; 4459 } else { 4460 // Continue movement 4461 newOffsetX = self.contentLastPos.left + self.velocityX * 500; 4462 newOffsetY = self.contentLastPos.top + self.velocityY * 500; 4463 } 4464 4465 newPos = self.limitPosition(newOffsetX, newOffsetY, self.contentStartPos.width, self.contentStartPos.height); 4466 4467 newPos.width = self.contentStartPos.width; 4468 newPos.height = self.contentStartPos.height; 4469 4470 $.nfancybox.animate(self.$content, newPos, 366); 4471 }; 4472 4473 Guestures.prototype.endZooming = function () { 4474 var self = this; 4475 4476 var current = self.instance.current; 4477 4478 var newOffsetX, newOffsetY, newPos, reset; 4479 4480 var newWidth = self.newWidth; 4481 var newHeight = self.newHeight; 4482 4483 if (!self.contentLastPos) { 4484 return; 4485 } 4486 4487 newOffsetX = self.contentLastPos.left; 4488 newOffsetY = self.contentLastPos.top; 4489 4490 reset = { 4491 top: newOffsetY, 4492 left: newOffsetX, 4493 width: newWidth, 4494 height: newHeight, 4495 scaleX: 1, 4496 scaleY: 1 4497 }; 4498 4499 // Reset scalex/scaleY values; this helps for perfomance and does not break animation 4500 $.nfancybox.setTranslate(self.$content, reset); 4501 4502 if (newWidth < self.canvasWidth && newHeight < self.canvasHeight) { 4503 self.instance.scaleToFit(150); 4504 } else if (newWidth > current.width || newHeight > current.height) { 4505 self.instance.scaleToActual(self.centerPointStartX, self.centerPointStartY, 150); 4506 } else { 4507 newPos = self.limitPosition(newOffsetX, newOffsetY, newWidth, newHeight); 4508 4509 $.nfancybox.animate(self.$content, newPos, 150); 4510 } 4511 }; 4512 4513 Guestures.prototype.onTap = function (e) { 4514 var self = this; 4515 var $target = $(e.target); 4516 4517 var instance = self.instance; 4518 var current = instance.current; 4519 4520 var endPoints = (e && getPointerXY(e)) || self.startPoints; 4521 4522 var tapX = endPoints[0] ? endPoints[0].x - $(window).scrollLeft() - self.stagePos.left : 0; 4523 var tapY = endPoints[0] ? endPoints[0].y - $(window).scrollTop() - self.stagePos.top : 0; 4524 4525 var where; 4526 4527 var process = function (prefix) { 4528 var action = current.opts[prefix]; 4529 4530 if ($.isFunction(action)) { 4531 action = action.apply(instance, [current, e]); 4532 } 4533 4534 if (!action) { 4535 return; 4536 } 4537 4538 switch (action) { 4539 case "close": 4540 instance.close(self.startEvent); 4541 4542 break; 4543 4544 case "toggleControls": 4545 instance.toggleControls(); 4546 4547 break; 4548 4549 case "next": 4550 instance.next(); 4551 4552 break; 4553 4554 case "nextOrClose": 4555 if (instance.group.length > 1) { 4556 instance.next(); 4557 } else { 4558 instance.close(self.startEvent); 4559 } 4560 4561 break; 4562 4563 case "zoom": 4564 if (current.type == "image" && (current.isLoaded || current.$ghost)) { 4565 if (instance.canPan()) { 4566 instance.scaleToFit(); 4567 } else if (instance.isScaledDown()) { 4568 instance.scaleToActual(tapX, tapY); 4569 } else if (instance.group.length < 2) { 4570 instance.close(self.startEvent); 4571 } 4572 } 4573 4574 break; 4575 } 4576 }; 4577 4578 // Ignore right click 4579 if (e.originalEvent && e.originalEvent.button == 2) { 4580 return; 4581 } 4582 4583 // Skip if clicked on the scrollbar 4584 if (!$target.is("img") && tapX > $target[0].clientWidth + $target.offset().left) { 4585 return; 4586 } 4587 4588 // Check where is clicked 4589 if ($target.is(".nfancybox-bg,.nfancybox-inner,.nfancybox-outer,.nfancybox-container")) { 4590 where = "Outside"; 4591 } else if ($target.is(".nfancybox-slide")) { 4592 where = "Slide"; 4593 } else if ( 4594 instance.current.$content && 4595 instance.current.$content 4596 .find($target) 4597 .addBack() 4598 .filter($target).length 4599 ) { 4600 where = "Content"; 4601 } else { 4602 return; 4603 } 4604 4605 // Check if this is a double tap 4606 if (self.tapped) { 4607 // Stop previously created single tap 4608 clearTimeout(self.tapped); 4609 self.tapped = null; 4610 4611 // Skip if distance between taps is too big 4612 if (Math.abs(tapX - self.tapX) > 50 || Math.abs(tapY - self.tapY) > 50) { 4613 return this; 4614 } 4615 4616 // OK, now we assume that this is a double-tap 4617 process("dblclick" + where); 4618 } else { 4619 // Single tap will be processed if user has not clicked second time within 300ms 4620 // or there is no need to wait for double-tap 4621 self.tapX = tapX; 4622 self.tapY = tapY; 4623 4624 if (current.opts["dblclick" + where] && current.opts["dblclick" + where] !== current.opts["click" + where]) { 4625 self.tapped = setTimeout(function () { 4626 self.tapped = null; 4627 4628 if (!instance.isAnimating) { 4629 process("click" + where); 4630 } 4631 }, 500); 4632 } else { 4633 process("click" + where); 4634 } 4635 } 4636 4637 return this; 4638 }; 4639 4640 $(document) 4641 .on("onActivate.fb", function (e, instance) { 4642 if (instance && !instance.Guestures) { 4643 instance.Guestures = new Guestures(instance); 4644 } 4645 }) 4646 .on("beforeClose.fb", function (e, instance) { 4647 if (instance && instance.Guestures) { 4648 instance.Guestures.destroy(); 4649 } 4650 }); 4651})(window, document, jQuery); 4652// ========================================================================== 4653// 4654// SlideShow 4655// Enables slideshow functionality 4656// 4657// Example of usage: 4658// $.nfancybox.getInstance().SlideShow.start() 4659// 4660// ========================================================================== 4661(function (document, $) { 4662 "use strict"; 4663 4664 $.extend(true, $.nfancybox.defaults, { 4665 btnTpl: { 4666 slideShow: '<button data-nfancybox-play class="nfancybox-button nfancybox-button--play" title="{{PLAY_START}}">' + 4667 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6.5 5.4v13.2l11-6.6z"/></svg>' + 4668 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.33 5.75h2.2v12.5h-2.2V5.75zm5.15 0h2.2v12.5h-2.2V5.75z"/></svg>' + 4669 "</button>" 4670 }, 4671 slideShow: { 4672 autoStart: false, 4673 speed: 3000, 4674 progress: true 4675 } 4676 }); 4677 4678 var SlideShow = function (instance) { 4679 this.instance = instance; 4680 this.init(); 4681 }; 4682 4683 $.extend(SlideShow.prototype, { 4684 timer: null, 4685 isActive: false, 4686 $button: null, 4687 4688 init: function () { 4689 var self = this, 4690 instance = self.instance, 4691 opts = instance.group[instance.currIndex].opts.slideShow; 4692 4693 self.$button = instance.$refs.toolbar.find("[data-nfancybox-play]").on("click", function () { 4694 self.toggle(); 4695 }); 4696 4697 if (instance.group.length < 2 || !opts) { 4698 self.$button.hide(); 4699 } else if (opts.progress) { 4700 self.$progress = $('<div class="nfancybox-progress"></div>').appendTo(instance.$refs.inner); 4701 } 4702 }, 4703 4704 set: function (force) { 4705 var self = this, 4706 instance = self.instance, 4707 current = instance.current; 4708 4709 // Check if reached last element 4710 if (current && (force === true || current.opts.loop || instance.currIndex < instance.group.length - 1)) { 4711 if (self.isActive && current.contentType !== "video") { 4712 if (self.$progress) { 4713 $.nfancybox.animate(self.$progress.show(), { 4714 scaleX: 1 4715 }, current.opts.slideShow.speed); 4716 } 4717 4718 self.timer = setTimeout(function () { 4719 if (!instance.current.opts.loop && instance.current.index == instance.group.length - 1) { 4720 instance.jumpTo(0); 4721 } else { 4722 instance.next(); 4723 } 4724 }, current.opts.slideShow.speed); 4725 } 4726 } else { 4727 self.stop(); 4728 instance.idleSecondsCounter = 0; 4729 instance.showControls(); 4730 } 4731 }, 4732 4733 clear: function () { 4734 var self = this; 4735 4736 clearTimeout(self.timer); 4737 4738 self.timer = null; 4739 4740 if (self.$progress) { 4741 self.$progress.removeAttr("style").hide(); 4742 } 4743 }, 4744 4745 start: function () { 4746 var self = this, 4747 current = self.instance.current; 4748 4749 if (current) { 4750 self.$button 4751 .attr("title", (current.opts.i18n[current.opts.lang] || current.opts.i18n.en).PLAY_STOP) 4752 .removeClass("nfancybox-button--play") 4753 .addClass("nfancybox-button--pause"); 4754 4755 self.isActive = true; 4756 4757 if (current.isComplete) { 4758 self.set(true); 4759 } 4760 4761 self.instance.trigger("onSlideShowChange", true); 4762 } 4763 }, 4764 4765 stop: function () { 4766 var self = this, 4767 current = self.instance.current; 4768 4769 self.clear(); 4770 4771 self.$button 4772 .attr("title", (current.opts.i18n[current.opts.lang] || current.opts.i18n.en).PLAY_START) 4773 .removeClass("nfancybox-button--pause") 4774 .addClass("nfancybox-button--play"); 4775 4776 self.isActive = false; 4777 4778 self.instance.trigger("onSlideShowChange", false); 4779 4780 if (self.$progress) { 4781 self.$progress.removeAttr("style").hide(); 4782 } 4783 }, 4784 4785 toggle: function () { 4786 var self = this; 4787 4788 if (self.isActive) { 4789 self.stop(); 4790 } else { 4791 self.start(); 4792 } 4793 } 4794 }); 4795 4796 $(document).on({ 4797 "onInit.fb": function (e, instance) { 4798 if (instance && !instance.SlideShow) { 4799 instance.SlideShow = new SlideShow(instance); 4800 } 4801 }, 4802 4803 "beforeShow.fb": function (e, instance, current, firstRun) { 4804 var SlideShow = instance && instance.SlideShow; 4805 4806 if (firstRun) { 4807 if (SlideShow && current.opts.slideShow.autoStart) { 4808 SlideShow.start(); 4809 } 4810 } else if (SlideShow && SlideShow.isActive) { 4811 SlideShow.clear(); 4812 } 4813 }, 4814 4815 "afterShow.fb": function (e, instance, current) { 4816 var SlideShow = instance && instance.SlideShow; 4817 4818 if (SlideShow && SlideShow.isActive) { 4819 SlideShow.set(); 4820 } 4821 }, 4822 4823 "afterKeydown.fb": function (e, instance, current, keypress, keycode) { 4824 var SlideShow = instance && instance.SlideShow; 4825 4826 // "P" or Spacebar 4827 if (SlideShow && current.opts.slideShow && (keycode === 80 || keycode === 32) && !$(document.activeElement).is("button,a,input")) { 4828 keypress.preventDefault(); 4829 4830 SlideShow.toggle(); 4831 } 4832 }, 4833 4834 "beforeClose.fb onDeactivate.fb": function (e, instance) { 4835 var SlideShow = instance && instance.SlideShow; 4836 4837 if (SlideShow) { 4838 SlideShow.stop(); 4839 } 4840 } 4841 }); 4842 4843 // Page Visibility API to pause slideshow when window is not active 4844 $(document).on("visibilitychange", function () { 4845 var instance = $.nfancybox.getInstance(), 4846 SlideShow = instance && instance.SlideShow; 4847 4848 if (SlideShow && SlideShow.isActive) { 4849 if (document.hidden) { 4850 SlideShow.clear(); 4851 } else { 4852 SlideShow.set(); 4853 } 4854 } 4855 }); 4856})(document, jQuery); 4857// ========================================================================== 4858// 4859// FullScreen 4860// Adds fullscreen functionality 4861// 4862// ========================================================================== 4863(function (document, $) { 4864 "use strict"; 4865 4866 // Collection of methods supported by user browser 4867 var fn = (function () { 4868 var fnMap = [ 4869 ["requestFullscreen", "exitFullscreen", "fullscreenElement", "fullscreenEnabled", "fullscreenchange", "fullscreenerror"], 4870 // new WebKit 4871 [ 4872 "webkitRequestFullscreen", 4873 "webkitExitFullscreen", 4874 "webkitFullscreenElement", 4875 "webkitFullscreenEnabled", 4876 "webkitfullscreenchange", 4877 "webkitfullscreenerror" 4878 ], 4879 // old WebKit (Safari 5.1) 4880 [ 4881 "webkitRequestFullScreen", 4882 "webkitCancelFullScreen", 4883 "webkitCurrentFullScreenElement", 4884 "webkitCancelFullScreen", 4885 "webkitfullscreenchange", 4886 "webkitfullscreenerror" 4887 ], 4888 [ 4889 "mozRequestFullScreen", 4890 "mozCancelFullScreen", 4891 "mozFullScreenElement", 4892 "mozFullScreenEnabled", 4893 "mozfullscreenchange", 4894 "mozfullscreenerror" 4895 ], 4896 ["msRequestFullscreen", "msExitFullscreen", "msFullscreenElement", "msFullscreenEnabled", "MSFullscreenChange", "MSFullscreenError"] 4897 ]; 4898 4899 var ret = {}; 4900 4901 for (var i = 0; i < fnMap.length; i++) { 4902 var val = fnMap[i]; 4903 4904 if (val && val[1] in document) { 4905 for (var j = 0; j < val.length; j++) { 4906 ret[fnMap[0][j]] = val[j]; 4907 } 4908 4909 return ret; 4910 } 4911 } 4912 4913 return false; 4914 })(); 4915 4916 if (fn) { 4917 var FullScreen = { 4918 request: function (elem) { 4919 elem = elem || document.documentElement; 4920 4921 elem[fn.requestFullscreen](elem.ALLOW_KEYBOARD_INPUT); 4922 }, 4923 exit: function () { 4924 document[fn.exitFullscreen](); 4925 }, 4926 toggle: function (elem) { 4927 elem = elem || document.documentElement; 4928 4929 if (this.isFullscreen()) { 4930 this.exit(); 4931 } else { 4932 this.request(elem); 4933 } 4934 }, 4935 isFullscreen: function () { 4936 return Boolean(document[fn.fullscreenElement]); 4937 }, 4938 enabled: function () { 4939 return Boolean(document[fn.fullscreenEnabled]); 4940 } 4941 }; 4942 4943 $.extend(true, $.nfancybox.defaults, { 4944 btnTpl: { 4945 fullScreen: '<button data-nfancybox-fullscreen class="nfancybox-button nfancybox-button--fsenter" title="{{FULL_SCREEN}}">' + 4946 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>' + 4947 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 16h3v3h2v-5H5zm3-8H5v2h5V5H8zm6 11h2v-3h3v-2h-5zm2-11V5h-2v5h5V8z"/></svg>' + 4948 "</button>" 4949 }, 4950 fullScreen: { 4951 autoStart: false 4952 } 4953 }); 4954 4955 $(document).on(fn.fullscreenchange, function () { 4956 var isFullscreen = FullScreen.isFullscreen(), 4957 instance = $.nfancybox.getInstance(); 4958 4959 if (instance) { 4960 // If image is zooming, then force to stop and reposition properly 4961 if (instance.current && instance.current.type === "image" && instance.isAnimating) { 4962 instance.isAnimating = false; 4963 4964 instance.update(true, true, 0); 4965 4966 if (!instance.isComplete) { 4967 instance.complete(); 4968 } 4969 } 4970 4971 instance.trigger("onFullscreenChange", isFullscreen); 4972 4973 instance.$refs.container.toggleClass("nfancybox-is-fullscreen", isFullscreen); 4974 4975 instance.$refs.toolbar 4976 .find("[data-nfancybox-fullscreen]") 4977 .toggleClass("nfancybox-button--fsenter", !isFullscreen) 4978 .toggleClass("nfancybox-button--fsexit", isFullscreen); 4979 } 4980 }); 4981 } 4982 4983 $(document).on({ 4984 "onInit.fb": function (e, instance) { 4985 var $container; 4986 4987 if (!fn) { 4988 instance.$refs.toolbar.find("[data-nfancybox-fullscreen]").remove(); 4989 4990 return; 4991 } 4992 4993 if (instance && instance.group[instance.currIndex].opts.fullScreen) { 4994 $container = instance.$refs.container; 4995 4996 $container.on("click.fb-fullscreen", "[data-nfancybox-fullscreen]", function (e) { 4997 e.stopPropagation(); 4998 e.preventDefault(); 4999 5000 FullScreen.toggle(); 5001 }); 5002 5003 if (instance.opts.fullScreen && instance.opts.fullScreen.autoStart === true) { 5004 FullScreen.request(); 5005 } 5006 5007 // Expose API 5008 instance.FullScreen = FullScreen; 5009 } else if (instance) { 5010 instance.$refs.toolbar.find("[data-nfancybox-fullscreen]").hide(); 5011 } 5012 }, 5013 5014 "afterKeydown.fb": function (e, instance, current, keypress, keycode) { 5015 // "F" 5016 if (instance && instance.FullScreen && keycode === 70) { 5017 keypress.preventDefault(); 5018 5019 instance.FullScreen.toggle(); 5020 } 5021 }, 5022 5023 "beforeClose.fb": function (e, instance) { 5024 if (instance && instance.FullScreen && instance.$refs.container.hasClass("nfancybox-is-fullscreen")) { 5025 FullScreen.exit(); 5026 } 5027 } 5028 }); 5029})(document, jQuery); 5030// ========================================================================== 5031// 5032// Thumbs 5033// Displays thumbnails in a grid 5034// 5035// ========================================================================== 5036(function (document, $) { 5037 "use strict"; 5038 5039 var CLASS = "nfancybox-thumbs", 5040 CLASS_ACTIVE = CLASS + "-active"; 5041 5042 // Make sure there are default values 5043 $.nfancybox.defaults = $.extend( 5044 true, { 5045 btnTpl: { 5046 thumbs: '<button data-nfancybox-thumbs class="nfancybox-button nfancybox-button--thumbs" title="{{THUMBS}}">' + 5047 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14.59 14.59h3.76v3.76h-3.76v-3.76zm-4.47 0h3.76v3.76h-3.76v-3.76zm-4.47 0h3.76v3.76H5.65v-3.76zm8.94-4.47h3.76v3.76h-3.76v-3.76zm-4.47 0h3.76v3.76h-3.76v-3.76zm-4.47 0h3.76v3.76H5.65v-3.76zm8.94-4.47h3.76v3.76h-3.76V5.65zm-4.47 0h3.76v3.76h-3.76V5.65zm-4.47 0h3.76v3.76H5.65V5.65z"/></svg>' + 5048 "</button>" 5049 }, 5050 thumbs: { 5051 autoStart: false, // Display thumbnails on opening 5052 hideOnClose: true, // Hide thumbnail grid when closing animation starts 5053 parentEl: ".nfancybox-container", // Container is injected into this element 5054 axis: "y" // Vertical (y) or horizontal (x) scrolling 5055 } 5056 }, 5057 $.nfancybox.defaults 5058 ); 5059 5060 var FancyThumbs = function (instance) { 5061 this.init(instance); 5062 }; 5063 5064 $.extend(FancyThumbs.prototype, { 5065 $button: null, 5066 $grid: null, 5067 $list: null, 5068 isVisible: false, 5069 isActive: false, 5070 5071 init: function (instance) { 5072 var self = this, 5073 group = instance.group, 5074 enabled = 0; 5075 5076 self.instance = instance; 5077 self.opts = group[instance.currIndex].opts.thumbs; 5078 5079 instance.Thumbs = self; 5080 5081 self.$button = instance.$refs.toolbar.find("[data-nfancybox-thumbs]"); 5082 5083 // Enable thumbs if at least two group items have thumbnails 5084 for (var i = 0, len = group.length; i < len; i++) { 5085 if (group[i].thumb) { 5086 enabled++; 5087 } 5088 5089 if (enabled > 1) { 5090 break; 5091 } 5092 } 5093 5094 if (enabled > 1 && !!self.opts) { 5095 self.$button.removeAttr("style").on("click", function () { 5096 self.toggle(); 5097 }); 5098 5099 self.isActive = true; 5100 } else { 5101 self.$button.hide(); 5102 } 5103 }, 5104 5105 create: function () { 5106 var self = this, 5107 instance = self.instance, 5108 parentEl = self.opts.parentEl, 5109 list = [], 5110 src; 5111 5112 if (!self.$grid) { 5113 // Create main element 5114 self.$grid = $('<div class="' + CLASS + " " + CLASS + "-" + self.opts.axis + '"></div>').appendTo( 5115 instance.$refs.container 5116 .find(parentEl) 5117 .addBack() 5118 .filter(parentEl) 5119 ); 5120 5121 // Add "click" event that performs gallery navigation 5122 self.$grid.on("click", "a", function () { 5123 instance.jumpTo($(this).attr("data-index")); 5124 }); 5125 } 5126 5127 // Build the list 5128 if (!self.$list) { 5129 self.$list = $('<div class="' + CLASS + '__list">').appendTo(self.$grid); 5130 } 5131 5132 $.each(instance.group, function (i, item) { 5133 src = item.thumb; 5134 5135 if (!src && item.type === "image") { 5136 src = item.src; 5137 } 5138 5139 list.push( 5140 '<a href="javascript:;" tabindex="0" data-index="' + 5141 i + 5142 '"' + 5143 (src && src.length ? ' style="background-image:url(' + src + ')"' : 'class="nfancybox-thumbs-missing"') + 5144 "></a>" 5145 ); 5146 }); 5147 5148 self.$list[0].innerHTML = list.join(""); 5149 5150 if (self.opts.axis === "x") { 5151 // Set fixed width for list element to enable horizontal scrolling 5152 self.$list.width( 5153 parseInt(self.$grid.css("padding-right"), 10) + 5154 instance.group.length * 5155 self.$list 5156 .children() 5157 .eq(0) 5158 .outerWidth(true) 5159 ); 5160 } 5161 }, 5162 5163 focus: function (duration) { 5164 var self = this, 5165 $list = self.$list, 5166 $grid = self.$grid, 5167 thumb, 5168 thumbPos; 5169 5170 if (!self.instance.current) { 5171 return; 5172 } 5173 5174 thumb = $list 5175 .children() 5176 .removeClass(CLASS_ACTIVE) 5177 .filter('[data-index="' + self.instance.current.index + '"]') 5178 .addClass(CLASS_ACTIVE); 5179 5180 thumbPos = thumb.position(); 5181 5182 // Check if need to scroll to make current thumb visible 5183 if (self.opts.axis === "y" && (thumbPos.top < 0 || thumbPos.top > $list.height() - thumb.outerHeight())) { 5184 $list.stop().animate({ 5185 scrollTop: $list.scrollTop() + thumbPos.top 5186 }, 5187 duration 5188 ); 5189 } else if ( 5190 self.opts.axis === "x" && 5191 (thumbPos.left < $grid.scrollLeft() || thumbPos.left > $grid.scrollLeft() + ($grid.width() - thumb.outerWidth())) 5192 ) { 5193 $list 5194 .parent() 5195 .stop() 5196 .animate({ 5197 scrollLeft: thumbPos.left 5198 }, 5199 duration 5200 ); 5201 } 5202 }, 5203 5204 update: function () { 5205 var that = this; 5206 that.instance.$refs.container.toggleClass("nfancybox-show-thumbs", this.isVisible); 5207 5208 if (that.isVisible) { 5209 if (!that.$grid) { 5210 that.create(); 5211 } 5212 5213 that.instance.trigger("onThumbsShow"); 5214 5215 that.focus(0); 5216 } else if (that.$grid) { 5217 that.instance.trigger("onThumbsHide"); 5218 } 5219 5220 // Update content position 5221 that.instance.update(); 5222 }, 5223 5224 hide: function () { 5225 this.isVisible = false; 5226 this.update(); 5227 }, 5228 5229 show: function () { 5230 this.isVisible = true; 5231 this.update(); 5232 }, 5233 5234 toggle: function () { 5235 this.isVisible = !this.isVisible; 5236 this.update(); 5237 } 5238 }); 5239 5240 $(document).on({ 5241 "onInit.fb": function (e, instance) { 5242 var Thumbs; 5243 5244 if (instance && !instance.Thumbs) { 5245 Thumbs = new FancyThumbs(instance); 5246 5247 if (Thumbs.isActive && Thumbs.opts.autoStart === true) { 5248 Thumbs.show(); 5249 } 5250 } 5251 }, 5252 5253 "beforeShow.fb": function (e, instance, item, firstRun) { 5254 var Thumbs = instance && instance.Thumbs; 5255 5256 if (Thumbs && Thumbs.isVisible) { 5257 Thumbs.focus(firstRun ? 0 : 250); 5258 } 5259 }, 5260 5261 "afterKeydown.fb": function (e, instance, current, keypress, keycode) { 5262 var Thumbs = instance && instance.Thumbs; 5263 5264 // "G" 5265 if (Thumbs && Thumbs.isActive && keycode === 71) { 5266 keypress.preventDefault(); 5267 5268 Thumbs.toggle(); 5269 } 5270 }, 5271 5272 "beforeClose.fb": function (e, instance) { 5273 var Thumbs = instance && instance.Thumbs; 5274 5275 if (Thumbs && Thumbs.isVisible && Thumbs.opts.hideOnClose !== false) { 5276 Thumbs.$grid.hide(); 5277 } 5278 } 5279 }); 5280})(document, jQuery); 5281//// ========================================================================== 5282// 5283// Share 5284// Displays simple form for sharing current url 5285// 5286// ========================================================================== 5287(function (document, $) { 5288 "use strict"; 5289 5290 $.extend(true, $.nfancybox.defaults, { 5291 btnTpl: { 5292 share: '<button data-nfancybox-share class="nfancybox-button nfancybox-button--share" title="{{SHARE}}">' + 5293 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2.55 19c1.4-8.4 9.1-9.8 11.9-9.8V5l7 7-7 6.3v-3.5c-2.8 0-10.5 2.1-11.9 4.2z"/></svg>' + 5294 "</button>" 5295 }, 5296 share: { 5297 url: function (instance, item) { 5298 return ( 5299 (!instance.currentHash && !(item.type === "inline" || item.type === "html") ? item.origSrc || item.src : false) || window.location 5300 ); 5301 }, 5302 tpl: '<div class="nfancybox-share">' + 5303 "<h1>{{SHARE}}</h1>" + 5304 "<p>" + 5305 '<a class="nfancybox-share__button nfancybox-share__button--fb" href="https://www.facebook.com/sharer/sharer.php?u={{url}}">' + 5306 '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m287 456v-299c0-21 6-35 35-35h38v-63c-7-1-29-3-55-3-54 0-91 33-91 94v306m143-254h-205v72h196" /></svg>' + 5307 "<span>Facebook</span>" + 5308 "</a>" + 5309 '<a class="nfancybox-share__button nfancybox-share__button--tw" href="https://twitter.com/intent/tweet?url={{url}}&text={{descr}}">' + 5310 '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m456 133c-14 7-31 11-47 13 17-10 30-27 37-46-15 10-34 16-52 20-61-62-157-7-141 75-68-3-129-35-169-85-22 37-11 86 26 109-13 0-26-4-37-9 0 39 28 72 65 80-12 3-25 4-37 2 10 33 41 57 77 57-42 30-77 38-122 34 170 111 378-32 359-208 16-11 30-25 41-42z" /></svg>' + 5311 "<span>Twitter</span>" + 5312 "</a>" + 5313 '<a class="nfancybox-share__button nfancybox-share__button--pt" href="https://www.pinterest.com/pin/create/button/?url={{url}}&description={{descr}}&media={{media}}">' + 5314 '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m265 56c-109 0-164 78-164 144 0 39 15 74 47 87 5 2 10 0 12-5l4-19c2-6 1-8-3-13-9-11-15-25-15-45 0-58 43-110 113-110 62 0 96 38 96 88 0 67-30 122-73 122-24 0-42-19-36-44 6-29 20-60 20-81 0-19-10-35-31-35-25 0-44 26-44 60 0 21 7 36 7 36l-30 125c-8 37-1 83 0 87 0 3 4 4 5 2 2-3 32-39 42-75l16-64c8 16 31 29 56 29 74 0 124-67 124-157 0-69-58-132-146-132z" fill="#fff"/></svg>' + 5315 "<span>Pinterest</span>" + 5316 "</a>" + 5317 "</p>" + 5318 '<p><input class="nfancybox-share__input" type="text" value="{{url_raw}}" onclick="select()" /></p>' + 5319 "</div>" 5320 } 5321 }); 5322 5323 function escapeHtml(string) { 5324 var entityMap = { 5325 "&": "&", 5326 "<": "<", 5327 ">": ">", 5328 '"': """, 5329 "'": "'", 5330 "/": "/", 5331 "`": "`", 5332 "=": "=" 5333 }; 5334 5335 return String(string).replace(/[&<>"'`=\/]/g, function (s) { 5336 return entityMap[s]; 5337 }); 5338 } 5339 5340 $(document).on("click", "[data-nfancybox-share]", function () { 5341 var instance = $.nfancybox.getInstance(), 5342 current = instance.current || null, 5343 url, 5344 tpl; 5345 5346 if (!current) { 5347 return; 5348 } 5349 5350 if ($.type(current.opts.share.url) === "function") { 5351 url = current.opts.share.url.apply(current, [instance, current]); 5352 } 5353 5354 tpl = current.opts.share.tpl 5355 .replace(/\{\{media\}\}/g, current.type === "image" ? encodeURIComponent(current.src) : "") 5356 .replace(/\{\{url\}\}/g, encodeURIComponent(url)) 5357 .replace(/\{\{url_raw\}\}/g, escapeHtml(url)) 5358 .replace(/\{\{descr\}\}/g, instance.$caption ? encodeURIComponent(instance.$caption.text()) : ""); 5359 5360 $.nfancybox.open({ 5361 src: instance.translate(instance, tpl), 5362 type: "html", 5363 opts: { 5364 touch: false, 5365 animationEffect: false, 5366 afterLoad: function (shareInstance, shareCurrent) { 5367 // Close self if parent instance is closing 5368 instance.$refs.container.one("beforeClose.fb", function () { 5369 shareInstance.close(null, 0); 5370 }); 5371 5372 // Opening links in a popup window 5373 shareCurrent.$content.find(".nfancybox-share__button").click(function () { 5374 window.open(this.href, "Share", "width=550, height=450"); 5375 return false; 5376 }); 5377 }, 5378 mobile: { 5379 autoFocus: false 5380 } 5381 } 5382 }); 5383 }); 5384})(document, jQuery); 5385// ========================================================================== 5386// 5387// Hash 5388// Enables linking to each modal 5389// 5390// ========================================================================== 5391(function (window, document, $) { 5392 "use strict"; 5393 5394 // Simple $.escapeSelector polyfill (for jQuery prior v3) 5395 if (!$.escapeSelector) { 5396 $.escapeSelector = function (sel) { 5397 var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g; 5398 var fcssescape = function (ch, asCodePoint) { 5399 if (asCodePoint) { 5400 // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER 5401 if (ch === "\0") { 5402 return "\uFFFD"; 5403 } 5404 5405 // Control characters and (dependent upon position) numbers get escaped as code points 5406 return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16) + " "; 5407 } 5408 5409 // Other potentially-special ASCII characters get backslash-escaped 5410 return "\\" + ch; 5411 }; 5412 5413 return (sel + "").replace(rcssescape, fcssescape); 5414 }; 5415 } 5416 5417 // Get info about gallery name and current index from url 5418 function parseUrl() { 5419 var hash = window.location.hash.substr(1), 5420 rez = hash.split("-"), 5421 index = rez.length > 1 && /^\+?\d+$/.test(rez[rez.length - 1]) ? parseInt(rez.pop(-1), 10) || 1 : 1, 5422 gallery = rez.join("-"); 5423 5424 return { 5425 hash: hash, 5426 /* Index is starting from 1 */ 5427 index: index < 1 ? 1 : index, 5428 gallery: gallery 5429 }; 5430 } 5431 5432 // Trigger click evnt on links to open new nfancyBox instance 5433 function triggerFromUrl(url) { 5434 if (url.gallery !== "") { 5435 // If we can find element matching 'data-nfancybox' atribute, 5436 // then triggering click event should start nfancyBox 5437 $("[data-nfancybox='" + $.escapeSelector(url.gallery) + "']") 5438 .eq(url.index - 1) 5439 .focus() 5440 .trigger("click.fb-start"); 5441 } 5442 } 5443 5444 // Get gallery name from current instance 5445 function getGalleryID(instance) { 5446 var opts, ret; 5447 5448 if (!instance) { 5449 return false; 5450 } 5451 5452 opts = instance.current ? instance.current.opts : instance.opts; 5453 ret = opts.hash || (opts.$orig ? opts.$orig.data("nfancybox") || opts.$orig.data("nfancybox-trigger") : ""); 5454 5455 return ret === "" ? false : ret; 5456 } 5457 5458 // Start when DOM becomes ready 5459 $(function () { 5460 // Check if user has disabled this module 5461 if ($.nfancybox.defaults.hash === false) { 5462 return; 5463 } 5464 5465 // Update hash when opening/closing nfancyBox 5466 $(document).on({ 5467 "onInit.fb": function (e, instance) { 5468 var url, gallery; 5469 5470 if (instance.group[instance.currIndex].opts.hash === false) { 5471 return; 5472 } 5473 5474 url = parseUrl(); 5475 gallery = getGalleryID(instance); 5476 5477 // Make sure gallery start index matches index from hash 5478 if (gallery && url.gallery && gallery == url.gallery) { 5479 instance.currIndex = url.index - 1; 5480 } 5481 }, 5482 5483 "beforeShow.fb": function (e, instance, current, firstRun) { 5484 var gallery; 5485 5486 if (!current || current.opts.hash === false) { 5487 return; 5488 } 5489 5490 // Check if need to update window hash 5491 gallery = getGalleryID(instance); 5492 5493 if (!gallery) { 5494 return; 5495 } 5496 5497 // Variable containing last hash value set by nfancyBox 5498 // It will be used to determine if nfancyBox needs to close after hash change is detected 5499 instance.currentHash = gallery + (instance.group.length > 1 ? "-" + (current.index + 1) : ""); 5500 5501 // If current hash is the same (this instance most likely is opened by hashchange), then do nothing 5502 if (window.location.hash === "#" + instance.currentHash) { 5503 return; 5504 } 5505 5506 if (firstRun && !instance.origHash) { 5507 instance.origHash = window.location.hash; 5508 } 5509 5510 if (instance.hashTimer) { 5511 clearTimeout(instance.hashTimer); 5512 } 5513 5514 // Update hash 5515 instance.hashTimer = setTimeout(function () { 5516 if ("replaceState" in window.history) { 5517 window.history[firstRun ? "pushState" : "replaceState"]({}, 5518 document.title, 5519 window.location.pathname + window.location.search + "#" + instance.currentHash 5520 ); 5521 5522 if (firstRun) { 5523 instance.hasCreatedHistory = true; 5524 } 5525 } else { 5526 window.location.hash = instance.currentHash; 5527 } 5528 5529 instance.hashTimer = null; 5530 }, 300); 5531 }, 5532 5533 "beforeClose.fb": function (e, instance, current) { 5534 if (!current || current.opts.hash === false) { 5535 return; 5536 } 5537 5538 clearTimeout(instance.hashTimer); 5539 5540 // Goto previous history entry 5541 if (instance.currentHash && instance.hasCreatedHistory) { 5542 window.history.back(); 5543 } else if (instance.currentHash) { 5544 if ("replaceState" in window.history) { 5545 window.history.replaceState({}, document.title, window.location.pathname + window.location.search + (instance.origHash || "")); 5546 } else { 5547 window.location.hash = instance.origHash; 5548 } 5549 } 5550 5551 instance.currentHash = null; 5552 } 5553 }); 5554 5555 // Check if need to start/close after url has changed 5556 $(window).on("hashchange.fb", function () { 5557 var url = parseUrl(), 5558 fb = null; 5559 5560 // Find last nfancyBox instance that has "hash" 5561 $.each( 5562 $(".nfancybox-container") 5563 .get() 5564 .reverse(), 5565 function (index, value) { 5566 var tmp = $(value).data("nFancyBox"); 5567 5568 if (tmp && tmp.currentHash) { 5569 fb = tmp; 5570 return false; 5571 } 5572 } 5573 ); 5574 5575 if (fb) { 5576 // Now, compare hash values 5577 if (fb.currentHash !== url.gallery + "-" + url.index && !(url.index === 1 && fb.currentHash == url.gallery)) { 5578 fb.currentHash = null; 5579 5580 fb.close(); 5581 } 5582 } else if (url.gallery !== "") { 5583 triggerFromUrl(url); 5584 } 5585 }); 5586 5587 // Check current hash and trigger click event on matching element to start nfancyBox, if needed 5588 setTimeout(function () { 5589 if (!$.nfancybox.getInstance()) { 5590 triggerFromUrl(parseUrl()); 5591 } 5592 }, 50); 5593 }); 5594})(window, document, jQuery); 5595// ========================================================================== 5596// 5597// Wheel 5598// Basic mouse weheel support for gallery navigation 5599// 5600// ========================================================================== 5601(function (document, $) { 5602 "use strict"; 5603 5604 var prevTime = new Date().getTime(); 5605 5606 $(document).on({ 5607 "onInit.fb": function (e, instance, current) { 5608 instance.$refs.stage.on("mousewheel DOMMouseScroll wheel MozMousePixelScroll", function (e) { 5609 var current = instance.current, 5610 currTime = new Date().getTime(); 5611 5612 if (instance.group.length < 2 || current.opts.wheel === false || (current.opts.wheel === "auto" && current.type !== "image")) { 5613 return; 5614 } 5615 5616 e.preventDefault(); 5617 e.stopPropagation(); 5618 5619 if (current.$slide.hasClass("nfancybox-animated")) { 5620 return; 5621 } 5622 5623 e = e.originalEvent || e; 5624 5625 if (currTime - prevTime < 250) { 5626 return; 5627 } 5628 5629 prevTime = currTime; 5630 5631 instance[(-e.deltaY || -e.deltaX || e.wheelDelta || -e.detail) < 0 ? "next" : "previous"](); 5632 }); 5633 } 5634 }); 5635})(document, jQuery);
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.