1/** 2 * FancyBox Classic - jQuery Plugin 3 * Simple but fancy lightbox, based on the original FancyBox by Janis Skarnelis, modernized. 4 * 5 * Examples and original documentation at: http://fancybox.net 6 * 7 * Copyright (c) 2008 - 2010 Janis Skarnelis 8 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. 9 * 10 * Copyright (c) 2020 - RavanH 11 * Version: 1.5 (2020/11/09) 12 * Requires: jQuery v1.7+ 13 * 14 * Dual licensed under the MIT and GPL licenses: 15 * http://www.opensource.org/licenses/mit-license.php 16 * http://www.gnu.org/licenses/gpl.html 17 */ 18 19(function($) { 20 var tmp, loading, overlay, wrap, outer, content, close, title, nav_prev, nav_next, resize_timeout, previousType, clone, final_pos, 21 selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], ajaxLoader = null, 22 imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg|webp)(.*)?$/i, svgRegExp = /[^\.]\.(svg)\s*$/i, 23 pdfRegExp = /[^\.]\.(pdf)\s*$/i, titleHeight = 0, titleStr = '', busy = false, swipe_busy = false, move_startX, move_endX, pixel_ratio = window.devicePixelRatio || 1, 24 isTouch = 'ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; 25 26 /* 27 * Private methods 28 */ 29 30 _abort = function() { 31 $.fancybox.hideActivity(); 32 33 imgPreloader.onerror = imgPreloader.onload = null; 34 35 if (ajaxLoader) { 36 ajaxLoader.abort(); 37 } 38 39 tmp.empty(); 40 }; 41 42 _error = function(msg) { 43 if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { 44 $.fancybox.hideActivity(); 45 busy = false; 46 return; 47 } 48 49 if ( typeof msg === 'undefined' ) { 50 msg = selectedOpts.txt.error.later; 51 } 52 53 selectedOpts.type = 'html'; 54 selectedOpts.enableSwipeNav = false; 55 selectedOpts.titleShow = false; 56 selectedOpts.width = 'auto'; 57 selectedOpts.height = 'auto'; 58 59 tmp.html('<p id="fancybox-error">' + selectedOpts.txt.error.content + '<br />' + msg + '</p>'); 60 61 _process_inline(); 62 }; 63 64 _start = function() { 65 var obj = selectedArray[ selectedIndex ], 66 href, type, title, ret; 67 68 _abort(); 69 70 selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); 71 72 $('html').addClass('fancybox-active'); 73 74 $(document).trigger('fancybox-start', [ selectedArray, selectedIndex, selectedOpts ] ); 75 76 ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); 77 78 if (ret === false) { 79 busy = false; 80 return; 81 } else if (typeof ret == 'object') { 82 selectedOpts = $.extend(selectedOpts, ret); 83 } 84 85 title = DOMPurify.sanitize(selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''); 86 87 if (obj.nodeName && !selectedOpts.orig) { 88 selectedOpts.orig = $(obj).find("img:first").length ? $(obj).find("img:first") : $(obj); 89 } 90 91 if (title === '' && selectedOpts.orig) { 92 title = DOMPurify.sanitize(selectedOpts.orig.attr('title')) || (selectedOpts.titleFromAlt ? DOMPurify.sanitize(selectedOpts.orig.attr('alt')) : ''); 93 } 94 95 href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; 96 97 // Block script-capable / document-loading schemes that could execute when interpolated 98 // into object[data], embed[src], img[src] or a link href (javascript:, vbscript:, data:). 99 // Other schemes (mailto:, tel:, ftp:, custom app schemes), protocol-relative (//), relative 100 // URLs and in-page anchors (#) are intentionally left intact for compatibility. 101 if (href && /^\s*(?:javascript|vbscript|data)\s*:/i.test(href)) { 102 href = null; 103 } 104 105 if ((/^(?:javascript)/i).test(href) || href == '#') { 106 href = null; 107 } 108 109 if (selectedOpts.type) { 110 type = selectedOpts.type; 111 if (!href) { 112 href = selectedOpts.content; 113 } 114 } else if (selectedOpts.content) { 115 type = 'html'; 116 } else if ( $(obj).hasClass('iframe') ) { 117 type = 'iframe'; 118 } else if (href) { 119 if (href.match(imgRegExp) || $(obj).hasClass("image")) { 120 type = 'image'; 121 } else if (href.match(svgRegExp)) { 122 type = 'svg'; 123 }
123 else if (href.match(pdfRegExp)) { 124 type = 'pdf'; 125 } else if (href.indexOf("#") === 0) { 126 type = 'inline'; 127 } else { 128 type = 'ajax'; 129 } 130 } 131 132 if (!type) { 133 _error(selectedOpts.txt.error.type); 134 return; 135 } 136 137 if ($(obj).hasClass('modal')) { 138 selectedOpts.modal = true; 139 } 140 141 if (type == 'inline') { 142 obj = href.substr(href.indexOf("#")); 143 type = $(obj).length > 0 ? 'inline' : 'ajax'; 144 } 145 146 selectedOpts.type = type; 147 selectedOpts.href = href; 148 selectedOpts.title = title; 149 150 if (selectedOpts.autoDimensions) { 151 if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') { 152 selectedOpts.width = 'auto'; 153 selectedOpts.height = 'auto'; 154 } else { 155 selectedOpts.autoDimensions = false; 156 } 157 } 158 159 if (selectedOpts.modal) { 160 selectedOpts.overlayShow = true; 161 selectedOpts.hideOnOverlayClick = false; 162 selectedOpts.hideOnContentClick = false; 163 selectedOpts.enableEscapeButton = false; 164 selectedOpts.showCloseButton = false; 165 } 166 167 selectedOpts.padding = parseInt(selectedOpts.padding, 10); 168 selectedOpts.margin = parseInt(selectedOpts.margin, 10); 169 170 tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); 171 172 if (selectedOpts.enableEscapeButton) { 173 $(document).on('keydown.fb', function(e) { 174 if (e.keyCode == 27) { 175 e.preventDefault(); 176 $.fancybox.cancel(); 177 return false; 178 } 179 }); 180 } 181 182 switch (type) { 183 case 'html' : 184 tmp.html( selectedOpts.content ); 185 selectedOpts.enableSwipeNav = false; 186 187 _process_inline(); 188 break; 189 190 case 'inline' : 191 if ( $(obj).parent().is('#fancybox-content') === true) { 192 busy = false; 193 return; 194 } 195 196 selectedOpts.enableSwipeNav = false; 197 198 $(obj).clone() 199 .attr('id', $(obj).attr('id')+'-tmp') 200 .insertBefore( $(obj) ); 201 202 $(document).on('fancybox-cleanup fancybox-change', function() { 203 let theObj = content.children().children(); 204 $('#'+theObj.attr('id')+'-tmp').replaceWith(theObj); 205 }).on('fancybox-cancel', function() { 206 let theObj = tmp.children(); 207 if (!theObj.length) { 208 theObj = content.children().children(); 209 } 210 $('#'+theObj.attr('id')+'-tmp').replaceWith(theObj); 211 }); 212 213 $(obj).appendTo(tmp); 214 215 _process_inline(); 216 break; 217 218 case 'image': 219 selectedOpts.keepRatio = true; 220 221 busy = false; 222 223 imgPreloader = new Image(); 224 225 imgPreloader.onerror = function() { 226 _error(selectedOpts.txt.error.image); 227 }; 228 229 imgPreloader.onload = function() { 230 busy = true; 231 232 $.fancybox.hideActivity(); 233 234 imgPreloader.onerror = imgPreloader.onload = null; 235 236 selectedOpts.width = imgPreloader.width; 237 selectedOpts.height = imgPreloader.height; 238 239 $("<img />").attr({ 240 'id' : 'fancybox-img', 241 'src' : imgPreloader.src, 242 'alt' : selectedOpts.title 243 }).appendTo(tmp); 244 245 _show(); 246 }; 247 248 imgPreloader.src = href; 249 250 $.fancybox.showActivity(); 251 break; 252 253 case 'svg': 254 selectedOpts.scrolling = 'no'; 255 selectedOpts.keepRatio = true; 256 257 var $svgObj = $('<object/>', { 258 type : 'image/svg+xml', 259 width : selectedOpts.width, 260 height : selectedOpts.height 261 }).attr('data', href); 262 263 tmp.empty().append($svgObj); 264 265 _process_inline(); 266 break; 267 268 case 'pdf': 269 selectedOpts.scrolling = 'no'; 270 selectedOpts.enableSwipeNav = false; 271 272 var $pdfFallback = $('<a/>', { 273 style : 'display:block;position:absolute;top:48%;width:100%;text-align:center' 274 }).attr('href', href).html(DOMPurify.sanitize($(obj).html())); 275 276 var $pdfObj = $('<object/>', { 277 type : 'application/pdf', 278 width : '100%', 279 height : '100%' 280 }).attr('data', href).append($pdfFallback); 281 282 tmp.empty().append($pdfObj); 283 284 _process_inline(); 285 break; 286 287 case 'ajax': 288 selectedOpts.enableKeyboardNav = false;
289 selectedOpts.showNavArrows = false; 290 selectedOpts.enableSwipeNav = false; 291 292 busy = false; 293 294 $.fancybox.showActivity(); 295 296 selectedOpts.ajax.win = selectedOpts.ajax.success; 297 298 ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { 299 url : href, 300 data : selectedOpts.ajax.data || {}, 301 error : function() { 302 if ( arguments[0].status > 0 ) { // XMLHttpRequest 303 _error(arguments[2]); // errorThrown 304 } 305 }, 306 success : function(data, textStatus, XMLHttpRequest) { 307 var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader; 308 if (o.status == 200) { 309 if ( typeof selectedOpts.ajax.win == 'function' ) { 310 ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); 311 312 if (ret === false) { 313 $.fancybox.hideActivity(); 314 return; 315 } else if (typeof ret == 'string' || typeof ret == 'object') { 316 data = ret; 317 } 318 } 319 320 if ( data.indexOf("<!DOCTYPE") > -1 || data.indexOf("<html") > -1 || data.indexOf("<body") > -1 ) { 321 _error(selectedOpts.txt.error.unexpected); 322 } else { 323 tmp.html(data); 324 _process_inline(); 325 } 326 } 327 } 328 })); 329 break; 330 331 case 'iframe': 332 selectedOpts.enableSwipeNav = false; 333 334 $.fancybox.showActivity(); 335 336 _show(); 337 break; 338 } 339 }; 340 341 _process_inline = function() { 342 var w = selectedOpts.width, 343 h = selectedOpts.height; 344 345 $.fancybox.hideActivity(); 346 347 if (w.toString().indexOf('%') > -1) { 348 w = parseInt((window.innerWidth - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; 349 } else { 350 w = w == 'auto' ? 'auto' : w + 'px'; 351 } 352 353 if (h.toString().indexOf('%') > -1) { 354 h = parseInt((window.innerHeight - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; 355 } else { 356 h = h == 'auto' ? 'auto' : h + 'px'; 357 } 358 359 tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow:hidden;position:relative;"></div>'); 360 361 selectedOpts.width = tmp.width(); 362 selectedOpts.height = tmp.height(); 363 364 _show(); 365 }; 366 367 _show = function() { 368 busy = true; 369 370 $(content.add( overlay )).off(); 371 372 $(window).off('resize.fb'); 373 374 previousType = currentOpts.type; 375 376 currentArray = selectedArray; 377 currentIndex = selectedIndex; 378 currentOpts = selectedOpts; 379 380 if (currentOpts.overlayShow) { 381 overlay.css({ 382 'background-color' : currentOpts.overlayColor, 383 'opacity' : currentOpts.overlayOpacity, 384 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto' 385 }); 386 387 if (!overlay.is(':visible')) { 388 overlay.fadeIn('fast'); 389 } 390 } else { 391 overlay.hide(); 392 } 393 394 _process_title(); 395 396 final_pos = _get_zoom_to(); 397 398 if (wrap.is(':visible')) { 399 $( close.add( nav_prev ).add( nav_next ) ).hide(); 400 401 // if both images 402 if (previousType === 'image' && currentOpts.type === 'image') { 403 // crossfade 404 content.prepend( tmp.contents() ); 405 content 406 .children() 407 .first() 408 .next().fadeOut(currentOpts.changeSpeed, function(){ $( this ).remove(); } ); 409 410 content.css('border-width', currentOpts.padding); 411 412 wrap.animate(final_pos, { 413 duration : currentOpts.changeSpeed, 414 easing : currentOpts.easingChange, 415 complete : _finish 416 }); 417 } else { 418 content.fadeTo(currentOpts.changeFade, 0.3, function() { 419 420 content.css('border-width', currentOpts.padding); 421 422 wrap.animate(final_pos, { 423 duration : currentOpts.changeSpeed, 424 easing : currentOpts.easingChange, 425 complete : function() { 426 content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); 427 } 428 }); 429 }); 430 } 431 432 return; 433 } 434 435 wrap.removeAttr("style"); 436 437 content.css('border-width', currentOpts.padding); 438 439 content.html( tmp.contents() ); 440 441 if (currentOpts.transitionIn == 'elastic') { 442 wrap.css(_get_orig_pos()).show(); 443 444 final_pos.opacity = 1; 445 446 wrap 447 .attr('aria-hidden','false') 448 .animate(final_pos, { 449 duration : currentOpts.speedIn, 450 easing : currentOpts.easingIn, 451 complete : _finish 452 }); 453 } else { 454 wrap 455 .css(final_pos) 456 .attr('aria-hidden','false') 457 .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); 458 } 459 }; 460 461 _format_title = function(title) { 462 if (title && title.length) { 463 return '<div id="fancybox-title">' + title + '</div>'; 464 } 465 466 return false;
467 }; 468 469 _process_title = function() { 470 titleStr = currentOpts.title || ''; 471 titleHeight = 0; 472 473 title 474 .empty() 475 .removeAttr('style') 476 .removeClass(); 477 478 if (currentOpts.titleShow === false) { 479 title.hide(); 480 return; 481 } 482 483 titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); 484 485 if (!titleStr || titleStr === '') { 486 title.hide(); 487 return; 488 } 489 490 title 491 .addClass('fancybox-title-' + currentOpts.titlePosition) 492 .html( titleStr ) 493 .appendTo( 'body' ) 494 .show(); 495 496 switch (currentOpts.titlePosition) { 497 case 'outside': 498 case 'inside': 499 titleHeight = title.outerHeight(true); 500 title.appendTo( outer ); 501 break; 502 503 case 'over': 504 if (content.is(':visible')) { 505 title.appendTo( content ); 506 } else { 507 title.appendTo( tmp ); 508 } 509 break; 510 511 default: 512 title 513 .css({ 514 'paddingLeft' : currentOpts.padding, 515 'paddingRight' : currentOpts.padding 516 }) 517 .appendTo( wrap ); 518 } 519 520 title.hide(); 521 }; 522 523 _swipe = function() { 524 let dx = move_startX - move_endX; 525 526 move_startX = move_endX = 0; 527 528 if (Math.abs(dx) < currentOpts.swipeThreshold) return; 529 530 if ( dx < 0 ) { 531 $.fancybox.prev(); 532 } else { 533 $.fancybox.next(); 534 } 535 }; 536 537 _set_navigation = function() { 538 if (currentArray.length === 1) return; 539 540 if (currentOpts.enableSwipeNav) { 541 wrap.css('cursor','move'); 542 543 wrap.on('mousedown.fb', function(e) { 544 e.preventDefault(); 545 move_startX = move_endX = typeof e.clientX !== 'undefined' ? e.clientX : e.originalEvent.clientX; 546 wrap.on('mousemove.fb', function(e) { 547 move_endX = typeof e.clientX !== 'undefined' ? e.clientX : e.originalEvent.clientX; 548 }); 549 }); 550 wrap.on('mouseup.fb', function() { 551 wrap.off('mousemove.fb'); 552 _swipe(); 553 }); 554 if (isTouch) { 555 wrap.on('touchstart.fb', function(e) { 556 swipe_busy = e.touches.length === 1; 557 move_startX = move_endX = typeof e.touches !== 'undefined' ? e.touches[0].clientX : e.originalEvent.touches[0].clientX; 558 wrap.on('touchmove.fb', function(e) { 559 if (e.touches.length === 1) { 560 move_endX = typeof e.touches !== 'undefined' ? e.touches[0].clientX : e.originalEvent.touches[0].clientX; 561 } else { // more than one touch, probably pinch or zoom 562 swipe_busy = false; 563 wrap.off('touchmove.fb'); 564 } 565 }); 566 }); 567 wrap.on('touchend.fb', function() { 568 wrap.off('touchmove.fb'); 569 if (swipe_busy) { 570 swipe_busy = false; 571 _swipe(); 572 } 573 }); 574 } 575 } 576 577 if ($.fn.mousewheel) { 578 wrap.on('mousewheel.fb', function(e, delta) { 579 if (busy) { 580 e.preventDefault(); 581 } else if ( currentOpts.type == 'image' && ( $(e.target).outerHeight() == 0 || $(e.target).prop('scrollHeight') === $(e.target).outerHeight() ) ) { 582 e.preventDefault(); 583 $.fancybox[ delta > 0 ? 'prev' : 'next' ](); 584 } 585 }); 586 } 587 588 $(document).off('keydown.fb'); 589 if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { 590 $(document).on('keydown.fb', function(e) { 591 if (currentOpts.enableEscapeButton && e.keyCode == 27) { 592 e.preventDefault(); 593 $.fancybox.close(); 594 return false; 595 } else if (currentOpts.enableKeyboardNav && (e.keyCode == 37 || e.keyCode == 39) && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { 596 e.preventDefault(); 597 $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); 598 } else if (currentOpts.enableKeyboardNav && (e.keyCode == 9) && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { 599 e.preventDefault(); 600 $.fancybox[ e.shiftKey ? 'prev' : 'next'](); 601 } 602 }); 603 } 604 605 if (currentOpts.showNavArrows) { 606 if (currentOpts.cyclic || currentIndex !== 0) { 607 nav_prev.attr('title',currentOpts.txt.prev).show(); 608 } 609 610 if (currentOpts.cyclic || currentIndex != currentArray.length-1) { 611 nav_next.attr('title',currentOpts.txt.next).show(); 612 } 613 } 614 }; 615 616 _finish = function () { 617 if (titleStr && titleStr.length) { 618 title.fadeIn(); 619 } 620 621 if (currentOpts.showCloseButton) { 622 close.attr('title',currentOpts.txt.close).show(); 623 } 624 625 _set_navigation(); 626 627 if (currentOpts.hideOnContentClick) { 628 content.on('click', $.fancybox.close).css('cursor','pointer');; 629 } 630 631 if (currentOpts.hideOnOverlayClick) { 632 overlay.on('click', $.fancybox.close); 633 } 634 635 if (currentOpts.autoResize) { 636 $(window).on("resize.fb", $.fancybox.resize); 637 } 638 639 if (currentOpts.type == 'iframe') { 640 var $frame = $('<iframe/>', { 641 id : 'fancybox-frame', 642 name : 'fancybox-frame' + new Date().getTime(), 643 style : 'border:0;margin:0;overflow:' + (currentOpts.scrolling == 'auto' ? 'auto' : (currentOpts.scrolling == 'yes' ? 'scroll' : 'hidden')),
644 allow : 'autoplay; encrypted-media', 645 tabindex : 999 646 }).attr('src', currentOpts.href); 647 648 if (false !== currentOpts.allowfullscreen) { 649 $frame.attr('allowfullscreen', ''); 650 } 651 652 $frame.appendTo(content).on('load',function() { 653 $.fancybox.hideActivity(); 654 }); 655 } 656 657 if (currentOpts.type == 'inline' || currentOpts.type == 'html') { 658 $(content).children().css('overflow', currentOpts.scrolling == 'auto' ? 'auto' : (currentOpts.scrolling == 'yes' ? 'scroll' : 'hidden') ); 659 } 660 661 wrap.show().focus(); 662 663 busy = false; 664 665 $(document).trigger('fancybox-complete', [ currentArray, currentIndex, currentOpts ] ); 666 667 currentOpts.onComplete(currentArray, currentIndex, currentOpts); 668 669 if (currentArray.length > 1) { 670 _preload_next(); 671 _preload_prev(); 672 } 673 }; 674 675 _preload_next = function() { 676 var pos = typeof arguments[0] == 'number' ? arguments[0] : currentIndex + 1; 677 678 if ( pos >= currentArray.length ) { 679 if (currentOpts.cyclic) { 680 pos = 0; 681 } else { 682 return; 683 } 684 } 685 686 if ( pos == currentIndex ) { 687 currentOpts.enableKeyboardNav = false;
688 currentOpts.enableSwipeNav = false; 689 wrap.off('mousewheel.fb touchstart.fb touchmove.fb touchend.fb mousedown.fb mousemove.fb mouseup.fb'); 690 nav_next.hide(); 691 return; 692 } 693 694 if ( _preload_image( pos ) ) { 695 return; 696 } else { 697 _preload_next( pos + 1 ); 698 } 699 }; 700 701 _preload_prev = function() { 702 var pos = typeof arguments[0] == 'number' ? arguments[0] : currentIndex - 1; 703 704 if ( pos < 0 ) { 705 if (currentOpts.cyclic) { 706 pos = currentArray.length - 1; 707 } else { 708 return; 709 } 710 } 711 712 if ( pos == currentIndex ) { 713 currentOpts.enableKeyboardNav = false; 714 currentOpts.enableSwipeNav = false; 715 wrap.off('mousewheel.fb touchstart.fb touchmove.fb touchend.fb mousedown.fb mousemove.fb mouseup.fb'); 716 nav_prev.hide(); 717 return; 718 } 719 720 if ( _preload_image( pos ) ) { 721 return; 722 } else { 723 _preload_prev( pos - 1 ); 724 } 725 }; 726 727 _preload_image = function(pos) { 728 var objNext, obj = currentArray[ pos ]; 729 730 if ( typeof obj !== 'undefined' && typeof obj.href !== 'undefined' && obj.href !== currentOpts.href && (obj.href.match(imgRegExp) || $(obj).hasClass("image")) ) { 731 objNext = new Image(); 732 objNext.src = obj.href; 733 return true; 734 } else { 735 return false; 736 } 737 }; 738 739 _get_zoom_to = function () { 740 var view = [ 741 window.innerWidth - (currentOpts.margin * 2), 742 window.innerHeight - (currentOpts.margin * 2) - titleHeight, 743 $(document).scrollLeft() + currentOpts.margin, 744 $(document).scrollTop() + currentOpts.margin 745 ], 746 to = {}, 747 ratio = currentOpts.keepRatio && currentOpts.height ? currentOpts.width / currentOpts.height : 1; 748 749 if (currentOpts.width.toString().indexOf('%') > -1) { 750 to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); 751 } else { 752 to.width = currentOpts.width + (currentOpts.padding * 2); 753 } 754 755 if (currentOpts.height.toString().indexOf('%') > -1) { 756 to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); 757 } else { 758 to.height = currentOpts.height + (currentOpts.padding * 2); 759 } 760 761 // scale down to fit viewport, recalculate by ratio based on width and height without border and title 762 if (to.width > view[0]) { 763 if (currentOpts.autoScale) { 764 to.width = view[0] - (currentOpts.padding * 2); 765 to.height = parseInt(to.width / ratio, 10); 766 } else { 767 $('html').addClass('fancybox-allowscroll'); 768 } 769 } 770 if (currentOpts.autoScale && to.height > view[1]) { 771 if (currentOpts.autoScale) { 772 to.height = view[1] - (currentOpts.padding * 2); 773 to.width = parseInt(to.height * ratio, 10); 774 } else { 775 $('html').addClass('fancybox-allowscroll'); 776 } 777 } 778 779 // calculate position 780 to.left = parseInt(Math.max(view[2], view[2] + (view[0] - to.width ) / 2), 10); 781 to.top = parseInt(Math.max(view[3], view[3] + (view[1] - to.height) / 2), 10); 782 783 return to; 784 }; 785 786 _get_orig_pos = function() { 787 if ( !selectedOpts.orig ) return false; 788 789 var orig = $(selectedOpts.orig); 790 791 if ( !orig.length ) return false; 792 793 var pos = orig.offset(); 794 795 pos.top += parseInt( orig.css('paddingTop'), 10 ) || parseInt( orig.css('border-top-width'), 10 ) || 0; 796 pos.left += parseInt( orig.css('paddingLeft'), 10 ) || parseInt( orig.css('border-left-width'), 10 ) || 0; 797 798 return { 799 width : orig.width() + (currentOpts.padding * 2), 800 height : orig.height() + (currentOpts.padding * 2), 801 top : pos.top - currentOpts.padding, 802 left : pos.left - currentOpts.padding, 803 opacity : 0 804 }; 805 }; 806 807 _closed = function() { 808 overlay.fadeOut('fast'); 809 810 $(document).trigger('fancybox-closed', [ currentArray, currentIndex, currentOpts ] ); 811 812 currentOpts.onClosed(currentArray, currentIndex, currentOpts); 813 814 _cleanup(); 815 }; 816 817 _cleanup = function() { 818 overlay.hide(); 819 820 title.empty().hide(); 821 wrap.hide().attr('aria-hidden','true');; 822 823 content.empty(); 824 825 currentArray = selectedArray = []; 826 currentIndex = selectedIndex = 0; 827 currentOpts = selectedOpts = {}; 828 829 $('html').css( { '--vertical-scrollbar' : '', '--horizontal-scrollbar' : '' } ); 830 $('html').removeClass('fancybox-active fancybox-allowscroll'); 831 832 $(document).off('fancybox-cancel fancybox-change fancybox-cleanup fancybox-closed'); 833 834 busy = false;
835 }; 836 837 /* 838 * Public methods 839 */ 840 841 $.fn.fancybox = function(options) { 842 if (!$(this).length) { 843 return this; 844 } 845 846 let objOpts = $.extend({}, options, ($.metadata ? $(this).metadata() : {})); 847 848 if ( ! objOpts.minViewportWidth || document.documentElement.clientWidth >= objOpts.minViewportWidth ) { 849 $(this) 850 .data('fancybox', objOpts) 851 .attr({'aria-controls':'fancybox-wrap','aria-haspopup':'dialog'}) 852 .off('click.fb') 853 .on('click.fb', function(e) { 854 e.preventDefault(); 855 856 if (busy) { 857 return false; 858 } 859 860 busy = true; 861 862 $(this).blur(); 863 864 selectedArray = []; 865 selectedIndex = 0; 866 867 var rel = $(this).attr('rel') || ''; 868 869 if (rel == '' || rel.replace(/alternate|external|help|license|nofollow|noreferrer|noopener|\s+/gi,'') == '') { 870 selectedArray.push(this); 871 } else { 872 selectedArray = $('a[rel="' + rel + '"], area[rel="' + rel + '"]'); 873 selectedIndex = selectedArray.index( this ); 874 } 875 876 $('html').css( { '--vertical-scrollbar' : window.innerWidth-$(window).width() + 'px', '--horizontal-scrollbar' : window.innerHeight-$(window).height() + 'px' } ); 877 878 _start(); 879 880 return false; 881 }); 882 }; 883 884 return this; 885 }; 886 887 $.fancybox = function(obj) { 888 var opts; 889 890 if (busy) { 891 return; 892 } 893 894 busy = true; 895 opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; 896 897 selectedArray = []; 898 selectedIndex = parseInt(opts.index, 10) || 0; 899 900 if ( $.isArray(obj) ) { 901 for (var i = 0, j = obj.length; i < j; i++) { 902 if (typeof obj[i] == 'object') { 903 $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); 904 } else { 905 obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); 906 } 907 } 908 909 selectedArray = jQuery.merge(selectedArray, obj); 910 } else { 911 if ( typeof obj == 'object' ) { 912 $(obj).data('fancybox', $.extend({}, opts, obj)); 913 } else { 914 obj = $({}).data('fancybox', $.extend({content : obj}, opts)); 915 } 916 917 selectedArray.push(obj); 918 } 919 920 if (selectedIndex > selectedArray.length || selectedIndex < 0) { 921 selectedIndex = 0; 922 } 923 924 $('html').css( { '--vertical-scrollbar' : window.innerWidth-$(window).width() + 'px', '--horizontal-scrollbar' : window.innerHeight-$(window).height() + 'px' } ); 925 926 _start(); 927 }; 928 929 $.fancybox.showActivity = function() { 930 loading.attr('title',selectedOpts.txt.loading).show(); 931 }; 932 933 $.fancybox.hideActivity = function() { 934 loading.hide(); 935 }; 936 937 $.fancybox.next = function() { 938 var obj, pos = typeof arguments[0] == 'number' ? arguments[0] : currentIndex + 1; 939 940 if (pos >= currentArray.length) { 941 if (currentOpts.cyclic) { 942 pos = 0; 943 } else { 944 return; 945 } 946 } 947 948 obj = currentArray[pos]; 949 950 if ( pos != currentIndex && typeof obj !== 'undefined' && typeof obj.href !== 'undefined' && obj.href === currentOpts.href ) { 951 $.fancybox.next( pos + 1 ); 952 } else { 953 $.fancybox.pos( pos ); 954 } 955 956 return; 957 }; 958 959 $.fancybox.prev = function() { 960 var obj, pos = typeof arguments[0] == 'number' ? arguments[0] : currentIndex - 1; 961 962 if (pos < 0) { 963 if (currentOpts.cyclic) { 964 pos = currentArray.length - 1; 965 } else { 966 return; 967 } 968 } 969 970 obj = currentArray[pos]; 971 972 if ( pos != currentIndex && typeof obj !== 'undefined' && typeof obj.href !== 'undefined' && obj.href === currentOpts.href ) { 973 $.fancybox.prev( pos - 1 ); 974 } else { 975 $.fancybox.pos( pos ); 976 } 977 978 return; 979 }; 980 981 $.fancybox.pos = function(pos) { 982 if (busy) { 983 return; 984 } 985 986 pos = parseInt(pos); 987 988 if (currentArray.length > 1 && pos != currentIndex && pos > -1 && pos < currentArray.length) { 989 $(document).trigger('fancybox-change'); 990 991 selectedArray = currentArray; 992 selectedIndex = pos; 993 994 wrap.off('mousewheel.fb touchstart.fb touchmove.fb touchend.fb mousedown.fb mousemove.fb mouseup.fb').css('cursor','initial'); 995 content.off('click'); 996 997 _start(); 998 } 999 1000 return; 1001 }; 1002 1003 $.fancybox.cancel = function() { 1004 busy = true; 1005 1006 _abort(); 1007 1008 $(document).trigger('fancybox-cancel', [ selectedArray, selectedIndex, selectedOpts ] ); 1009 1010 if (selectedOpts && false === selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts) ) { 1011 busy = false; 1012 return; 1013 }; 1014 1015 $(selectedArray[ selectedIndex ]).focus(); 1016 1017 $(close.add( nav_prev ).add( nav_next )).hide(); 1018 1019 $(content.add( overlay )).off(); 1020 1021 $(window).off('resize.fb'); 1022 $(wrap).off('mousewheel.fb touchstart.fb touchmove.fb touchend.fb mousedown.fb mousemove.fb mouseup.fb'); 1023 $(document).off('keydown.fb'); 1024 1025 // This helps IE 1026 if (/MSIE|Trident/.test(window.navigator.userAgent)) { 1027 content.find('iframe#fancybox-frame').attr('src', '//about:blank'); 1028 } 1029 1030 wrap.stop(); 1031 1032 _cleanup(); 1033 }; 1034 1035 // Note: within an iframe use - parent.$.fancybox.close(); 1036 $.fancybox.close = function() { 1037 if (busy || wrap.is(':hidden')) { 1038 return; 1039 } 1040 1041 busy = true; 1042 1043 _abort(); 1044 1045 $(document).trigger('fancybox-cleanup', [ currentArray, currentIndex, currentOpts ] ); 1046 1047 if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { 1048 busy = false;
1049 return; 1050 } 1051 1052 $(currentArray[ currentIndex ]).focus(); 1053 1054 $(close.add( nav_prev ).add( nav_next )).hide(); 1055 1056 $(content.add( overlay )).off(); 1057 1058 $(window).off('resize.fb'); 1059 $(wrap).off('mousewheel.fb touchstart.fb touchmove.fb touchend.fb mousedown.fb mousemove.fb mouseup.fb'); 1060 $(document).off('keydown.fb'); 1061 1062 // This helps IE 1063 if (/MSIE|Trident/.test(window.navigator.userAgent)) { 1064 content.find('iframe#fancybox-frame').attr('src', '//about:blank'); 1065 } 1066 1067 if (currentOpts.titlePosition !== 'inside') { 1068 title.empty(); 1069 } 1070 1071 wrap.stop(); 1072 1073 if (currentOpts.transitionOut == 'elastic') { 1074 title.empty().hide(); 1075 1076 wrap.animate(_get_orig_pos(), { 1077 duration : currentOpts.speedOut, 1078 easing : currentOpts.easingOut, 1079 complete : _closed 1080 }); 1081 1082 } else { 1083 wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _closed); 1084 } 1085 }; 1086 1087 $.fancybox.resize = function() { 1088 clearTimeout( resize_timeout ); 1089 1090 resize_timeout = setTimeout( function() { 1091 var restore = []; 1092 1093 busy = true; 1094 1095 _process_title(); 1096 1097 final_pos = _get_zoom_to(); 1098 1099 close.is(':visible') && restore.push(close) && close.hide(); 1100 nav_prev.is(':visible') && restore.push(nav_prev) && nav_prev.hide(); 1101 nav_next.is(':visible') && restore.push(nav_next) && nav_next.hide(); 1102 1103 wrap.animate(final_pos, { 1104 duration : currentOpts.changeSpeed, 1105 easing : currentOpts.easingChange, 1106 complete : function() { 1107 if (titleStr && titleStr.length) { 1108 title.fadeIn(); 1109 } 1110 restore.forEach( function(el){ el.show(); } ); 1111 busy = false; 1112 } 1113 }); 1114 }, 500 ); 1115 }; 1116 1117 $.fancybox.init = function() { 1118 if ($("#fancybox-wrap").length) { 1119 return; 1120 } 1121 1122 $('body').append( 1123 tmp = $('<div id="fancybox-tmp"></div>'), 1124 loading = $('<div id="fancybox-loading" title="Cancel"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>'), 1125 overlay = $('<div id="fancybox-overlay"></div>'), 1126 wrap = $('<div id="fancybox-wrap" role="dialog" aria-hidden="true" aria-labelledby="fancybox-title" tabindex="-1"></div>') 1127 ); 1128 1129 wrap.append( 1130 outer = $('<div id="fancybox-outer"></div>') 1131 ); 1132 1133 outer.append( 1134 content = $('<div id="fancybox-content"></div>'), 1135 close = $(`<a id="fancybox-close" href="javascript:;" title="${(window.efb_i18n && window.efb_i18n.close) || 'Close'}" class="fancy-ico" tabindex="1"><span></span></a>`), 1136 nav_next = $(`<a id="fancybox-next" href="javascript:;" title="${(window.efb_i18n && window.efb_i18n.next) || 'Next'}" class="fancy-ico" tabindex="2"><span></span></a>`), 1137 nav_prev = $(`<a id="fancybox-prev" href="javascript:;" title="${(window.efb_i18n && window.efb_i18n.prev) || 'Previous'}" class="fancy-ico" tabindex="3"><span></span></a>`), 1138 title = $('<div id="fancybox-title-wrap"></div>') 1139 ); 1140 1141 close.on('click',$.fancybox.close); 1142 loading.on('click',$.fancybox.cancel); 1143 1144 nav_prev.on('click',function(e) { 1145 e.preventDefault(); 1146 $.fancybox.prev(); 1147 }); 1148 1149 nav_next.on('click',function(e) { 1150 e.preventDefault(); 1151 $.fancybox.next(); 1152 }); 1153 }; 1154 1155 $.fn.fancybox.defaults = { 1156 padding : 10, 1157 margin : 40, 1158 modal : false, 1159 cyclic : false, 1160 allowfullscreen : false, 1161 scrolling : 'auto', // 'auto', 'yes' or 'no' 1162 1163 width : 560, 1164 height : 340, 1165 1166 autoScale : true, 1167 autoDimensions : true, 1168 autoResize : true, 1169 keepRatio : false, 1170 minViewportWidth : 0, 1171 1172 swipeThreshold: 100, 1173 1174 ajax : {}, 1175 svg : { wmode: 'opaque' }, 1176 1177 hideOnOverlayClick : true, 1178 hideOnContentClick : false, 1179 1180 overlayShow : true, 1181 overlayColor : '#000', 1182 overlayOpacity : 0.6, 1183 1184 titleShow : true, 1185 titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' 1186 titleFormat : null, 1187 titleFromAlt : true, 1188 1189 transitionIn : 'fade', // 'elastic', 'fade' or 'none' 1190 transitionOut : 'fade', // 'elastic', 'fade' or 'none' 1191 1192 speedIn : 400, 1193 speedOut : 400, 1194 1195 changeSpeed : 200, 1196 changeFade : 200, 1197 1198 easingIn : 'swing', 1199 easingOut : 'swing', 1200 1201 showCloseButton : true, 1202 showNavArrows : true, 1203 enableEscapeButton : true, 1204 enableKeyboardNav : true, 1205 enableSwipeNav : true, 1206 1207 txt: { 1208 error : { 1209 content : 'The requested content cannot be loaded.', 1210 later : 'Please try again later.', 1211 type : 'No content type found.', 1212 image : 'No image found.', 1213 unexpected : 'Unexpected response.' 1214 }, 1215 loading : 'Cancel', 1216 close : 'Close', 1217 next : 'Next', 1218 prev : 'Previous' 1219 }, 1220 1221 onStart : function(){}, 1222 onCancel : function(){}, 1223 onComplete : function(){}, 1224 onCleanup : function(){}, 1225 onClosed : function(){}, 1226 onError : function(){} 1227 }; 1228 1229 $(document).ready(function() { 1230 $.fancybox.init(); 1231 }); 1232 1233})(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.