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