1/* 2 * FancyBox - jQuery Plugin 3 * Simple and fancy lightbox alternative 4 * 5 * Examples and 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 * Version: 1.3.2 (20/10/2010) 11 * Requires: jQuery v1.3+ 12 * 13 * Dual licensed under the MIT and GPL licenses: 14 * http://www.opensource.org/licenses/mit-license.php 15 * http://www.gnu.org/licenses/gpl.html 16 */ 17 18;(function($) { 19 var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right, 20 21 selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], 22 23 ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, 24 25 loadingTimer, loadingFrame = 1, 26 27 titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx
27= $.extend($('<div/>')[0], { prop: 0 }), 28 29 isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, 30 31 /* 32 * Private methods 33 */ 34 35 _abort = function() { 36 loading.hide(); 37 38 imgPreloader.onerror = imgPreloader.onload = null; 39 40 if (ajaxLoader) { 41 ajaxLoader.abort(); 42 } 43 44 tmp.empty(); 45 }, 46 47 _error = function() { 48 if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { 49 loading.hide(); 50 busy = false; 51 return; 52 } 53 54 selectedOpts.titleShow = false; 55 56 selectedOpts.width = 'auto'; 57 selectedOpts.height = 'auto'; 58 59 tmp.html( '<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>' ); 60 61 _process_inline(); 62 }, 63 64 _start = function() { 65 var obj = selectedArray[ selectedIndex ], 66 href, 67 type, 68 title, 69 str, 70 emb, 71 ret; 72 73 _abort(); 74 75 selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); 76 77 ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); 78 79 if (ret === false) { 80 busy = false; 81 return; 82 } else if (typeof ret == 'object') { 83 selectedOpts = $.extend(selectedOpts, ret); 84 } 85 86 title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''; 87 88 if (obj.nodeName && !selectedOpts.orig) { 89 selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); 90 } 91 92 if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) { 93 title = selectedOpts.orig.attr('alt'); 94 } 95 96 href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; 97 98 if ((/^(?:javascript)/i).test(href) || href == '#') { 99 href = null; 100 } 101 102 if (selectedOpts.type) { 103 type = selectedOpts.type; 104 105 if (!href) { 106 href = selectedOpts.content; 107 } 108 109 } else if (selectedOpts.content) { 110 type = 'html'; 111 112 } else if (href) { 113 if (href.match(imgRegExp)) { 114 type = 'image'; 115 116 } else if (href.match(swfRegExp)) { 117 type = 'swf'; 118 119 } else if ($(obj).hasClass("iframe")) { 120 type = 'iframe'; 121 122 } else if (href.indexOf("#") === 0) { 123 type = 'inline'; 124 125 } else { 126 type = 'ajax'; 127 } 128 } 129 130 if (!type) { 131 _error(); 132 return; 133 } 134 135 if (type == 'inline') { 136 obj = href.substr(href.indexOf("#")); 137 type = $(obj).length > 0 ? 'inline' : 'ajax'; 138 } 139 140 selectedOpts.type = type; 141 selectedOpts.href = href; 142 selectedOpts.title = title; 143 144 if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') { 145 selectedOpts.width = 'auto'; 146 selectedOpts.height = 'auto'; 147 } 148 149 if (selectedOpts.modal) { 150 selectedOpts.overlayShow = true; 151 selectedOpts.hideOnOverlayClick = false; 152 selectedOpts.hideOnContentClick = false; 153 selectedOpts.enableEscapeButton = false; 154 selectedOpts.showCloseButton = false; 155 } 156 157 selectedOpts.padding = parseInt(selectedOpts.padding, 10); 158 selectedOpts.margin = parseInt(selectedOpts.margin, 10); 159 160 tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); 161 162 $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { 163 $(this).replaceWith(content.children()); 164 }); 165 166 switch (type) { 167 case 'html' : 168 tmp.html( selectedOpts.content ); 169 _process_inline(); 170 break; 171 172 case 'inline' : 173 if ( $(obj).parent().is('#fancybox-content') === true) { 174 busy = false; 175 return; 176 } 177 178 $('<div class="fancybox-inline-tmp" />') 179 .hide() 180 .insertBefore( $(obj) ) 181 .bind('fancybox-cleanup', function() { 182 $(this).replaceWith(content.children()); 183 }).bind('fancybox-cancel', function() { 184 $(this).replaceWith(tmp.children()); 185 }); 186 187 $(obj).appendTo(tmp); 188 189 _process_inline(); 190 break; 191 192 case 'image': 193 busy = false; 194 195 $.fancybox.showActivity(); 196 197 imgPreloader = new Image(); 198 199 imgPreloader.onerror = function() { 200 _error(); 201 }; 202 203 imgPreloader.onload = function() { 204 busy = true; 205 206 imgPreloader.onerror = imgPreloader.onload = null; 207 208 _process_image(); 209 }; 210 211 imgPreloader.src = href; 212 break; 213 214 case 'swf': 215 str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>'; 216 emb = ''; 217 218 $.each(selectedOpts.swf, function(name, val) { 219 str += '<param name="' + name + '" value="' + val + '"></param>'; 220 emb += ' ' + name + '="' + val + '"'; 221 });
222 223 str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>'; 224 225 tmp.html(str); 226 227 _process_inline(); 228 break; 229 230 case 'ajax': 231 busy = false; 232 233 $.fancybox.showActivity(); 234 235 selectedOpts.ajax.win = selectedOpts.ajax.success; 236 237 ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { 238 url : href, 239 data : selectedOpts.ajax.data || {}, 240 error : function(XMLHttpRequest, textStatus, errorThrown) { 241 if ( XMLHttpRequest.status > 0 ) { 242 _error(); 243 } 244 }, 245 success : function(data, textStatus, XMLHttpRequest) { 246 if ( XMLHttpRequest.status == 200 ) { 247 if ( typeof selectedOpts.ajax.win == 'function' ) { 248 ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); 249 250 if (ret === false) { 251 loading.hide(); 252 return; 253 } else if (typeof ret == 'string' || typeof ret == 'object') { 254 data = ret; 255 } 256 } 257 258 tmp.html( data ); 259 _process_inline(); 260 } 261 } 262 })); 263 264 break; 265 266 case 'iframe' : 267 _show(); 268 break; 269 } 270 }, 271 272 _process_inline = function() { 273 tmp.width( selectedOpts.width ); 274 tmp.height( selectedOpts.height ); 275 276 if (selectedOpts.width == 'auto') { 277 selectedOpts.width = tmp.width(); 278 } 279 280 if (selectedOpts.height == 'auto') { 281 selectedOpts.height = tmp.height(); 282 } 283 284 _show(); 285 }, 286 287 _process_image = function() { 288 selectedOpts.width = imgPreloader.width; 289 selectedOpts.height = imgPreloader.height; 290 291 $("<img />").attr({ 292 'id' : 'fancybox-img', 293 'src' : imgPreloader.src, 294 'alt' : selectedOpts.title 295 }).appendTo( tmp ); 296 297 _show(); 298 }, 299 300 _show = function() { 301 var pos, equal; 302 303 loading.hide(); 304 305 if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { 306 $.event.trigger('fancybox-cancel'); 307 308 busy = false; 309 return; 310 } 311 312 busy = true; 313 314 $(content.add( overlay )).unbind(); 315 316 $(window).unbind("resize.fb scroll.fb"); 317 $(document).unbind('keydown.fb'); 318 319 if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') { 320 wrap.css('height', wrap.height()); 321 } 322 323 currentArray = selectedArray; 324 currentIndex = selectedIndex; 325 currentOpts = selectedOpts; 326 327 if (currentOpts.overlayShow) { 328 overlay.css({ 329 'background-color' : currentOpts.overlayColor, 330 'opacity' : currentOpts.overlayOpacity, 331 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto', 332 'height' : $(document).height() 333 }); 334 335 if (!overlay.is(':visible')) { 336 if (isIE6) { 337 $('select:not(#fancybox-tmp select)').filter(function() { 338 return this.style.visibility !== 'hidden'; 339 }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() { 340 this.style.visibility = 'inherit'; 341 }); 342 } 343 344 overlay.show(); 345 } 346 } else { 347 overlay.hide(); 348 } 349 350 content.get(0).scrollTop = 0; 351 content.get(0).scrollLeft = 0; 352 353 final_pos = _get_zoom_to(); 354 355 _process_title(); 356 357 if (wrap.is(":visible")) { 358 $( close.add( nav_left ).add( nav_right ) ).hide(); 359 360 pos = wrap.position(), 361 362 start_pos = { 363 top : pos.top, 364 left : pos.left, 365 width : wrap.width(), 366 height : wrap.height() 367 }; 368 369 equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); 370 371 content.fadeTo(currentOpts.changeFade, 0.3, function() { 372 var finish_resizing = function() { 373 content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); 374 }; 375 376 $.event.trigger('fancybox-change'); 377 378 content 379 .empty() 380 .removeAttr('filter') 381 .css({ 382 'border-width' : currentOpts.padding, 383 'width' : final_pos.width - currentOpts.padding * 2, 384 'height' : currentOpts.type == 'image' || currentOpts.type == 'swf' || currentOpts.type == 'iframe' ? final_pos.height - titleHeight - currentOpts.padding * 2 : 'auto' 385 });
386 387 if (equal) { 388 finish_resizing(); 389 390 } else { 391 fx.prop = 0; 392 393 $(fx).animate({prop: 1}, { 394 duration : currentOpts.changeSpeed, 395 easing : currentOpts.easingChange, 396 step : _draw, 397 complete : finish_resizing 398 }); 399 } 400 }); 401 402 return; 403 } 404 405 wrap.removeAttr("style"); 406 407 content.css('border-width', currentOpts.padding); 408 409 if (currentOpts.transitionIn == 'elastic') { 410 start_pos = _get_zoom_from(); 411 412 content.html( tmp.contents() ); 413 414 wrap.show(); 415 416 if (currentOpts.opacity) { 417 final_pos.opacity = 0; 418 } 419 420 fx.prop = 0; 421 422 $(fx).animate({prop: 1}, { 423 duration : currentOpts.speedIn, 424 easing : currentOpts.easingIn, 425 step : _draw, 426 complete : _finish 427 }); 428 429 return; 430 } 431 432 if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { 433 title.show(); 434 } 435 436 content 437 .css({ 438 'width' : final_pos.width - currentOpts.padding * 2, 439 'height' : currentOpts.type == 'image' || currentOpts.type == 'swf' || currentOpts.type == 'iframe' ? final_pos.height - titleHeight - currentOpts.padding * 2 : 'auto' 440 }) 441 .html( tmp.contents() ); 442 443 wrap 444 .css(final_pos) 445 .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.fadeIn, _finish ); 446 }, 447 448 _format_title = function(title) { 449 if (title && title.length) { 450 if (currentOpts.titlePosition == 'float') { 451 return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + title + '</td><td id="fancybox-title-float-right"></td></tr></table>'; 452 } 453 454 return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title + '</div>'; 455 } 456 457 return false; 458 }, 459 460 _process_title = function() { 461 titleStr = currentOpts.title || ''; 462 titleHeight = 0; 463 464 title 465 .empty() 466 .removeAttr('style') 467 .removeClass(); 468 469 if (currentOpts.titleShow === false) { 470 title.hide(); 471 return; 472 } 473 474 titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); 475 476 if (!titleStr || titleStr === '') { 477 title.hide(); 478 return; 479 } 480 481 title 482 .addClass('fancybox-title-' + currentOpts.titlePosition) 483 .html( titleStr ) 484 .appendTo( 'body' ) 485 .show(); 486 487 switch (currentOpts.titlePosition) { 488 case 'inside': 489 title 490 .css({ 491 'width' : final_pos.width - (currentOpts.padding * 2), 492 'marginLeft' : currentOpts.padding, 493 'marginRight' : currentOpts.padding 494 }); 495 496 titleHeight = title.outerHeight(true); 497 498 title.appendTo( outer ); 499 500 final_pos.height += titleHeight; 501 break; 502 503 case 'over': 504 title 505 .css({ 506 'marginLeft' : currentOpts.padding, 507 'width' : final_pos.width - (currentOpts.padding * 2), 508 'bottom' : currentOpts.padding 509 }) 510 .appendTo( outer ); 511 break; 512 513 case 'float': 514 title 515 .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) 516 .appendTo( wrap ); 517 break; 518 519 default: 520 title 521 .css({ 522 'width' : final_pos.width - (currentOpts.padding * 2), 523 'paddingLeft' : currentOpts.padding, 524 'paddingRight' : currentOpts.padding 525 }) 526 .appendTo( wrap ); 527 break; 528 } 529 530 title.hide(); 531 }, 532 533 _set_navigation = function() { 534 if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { 535 $(document).bind('keydown.fb', function(e) { 536 if (e.keyCode == 27 && currentOpts.enableEscapeButton) { 537 e.preventDefault(); 538 $.fancybox.close(); 539 540 } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { 541 e.preventDefault(); 542 $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); 543 } 544 }); 545 } 546 547 if (!currentOpts.showNavArrows) { 548 nav_left.hide(); 549 nav_right.hide(); 550 return; 551 } 552 553 if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { 554 nav_left.show(); 555 } 556 557 if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { 558 nav_right.show(); 559 } 560 }, 561 562 _finish = function () { 563 if (!$.support.opacity) { 564 content.get(0).style.removeAttribute('filter'); 565 wrap.get(0).style.removeAttribute('filter'); 566 } 567 568 wrap.css('height', 'auto'); 569
570 if (currentOpts.type !== 'image' && currentOpts.type !== 'swf' && currentOpts.type !== 'iframe') { 571 content.css('height', 'auto'); 572 } 573 574 if (titleStr && titleStr.length) { 575 title.show(); 576 } 577 578 if (currentOpts.showCloseButton) { 579 close.show(); 580 } 581 582 _set_navigation(); 583 584 if (currentOpts.hideOnContentClick) { 585 content.bind('click', $.fancybox.close); 586 } 587 588 if (currentOpts.hideOnOverlayClick) { 589 overlay.bind('click', $.fancybox.close); 590 } 591 592 $(window).bind("resize.fb", $.fancybox.resize); 593 594 if (currentOpts.centerOnScroll) { 595 $(window).bind("scroll.fb", $.fancybox.center); 596 } 597 598 if (currentOpts.type == 'iframe') { 599 $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="' + selectedOpts.scrolling + '" src="' + currentOpts.href + '"></iframe>').appendTo(content); 600 } 601 602 wrap.show(); 603 604 busy = false; 605 606 $.fancybox.center(); 607 608 currentOpts.onComplete(currentArray, currentIndex, currentOpts); 609 610 _preload_images(); 611 }, 612 613 _preload_images = function() { 614 var href, 615 objNext; 616 617 if ((currentArray.length -1) > currentIndex) { 618 href = currentArray[ currentIndex + 1 ].href; 619 620 if (typeof href !== 'undefined' && href.match(imgRegExp)) { 621 objNext = new Image(); 622 objNext.src = href; 623 } 624 } 625 626 if (currentIndex > 0) { 627 href = currentArray[ currentIndex - 1 ].href; 628 629 if (typeof href !== 'undefined' && href.match(imgRegExp)) { 630 objNext = new Image(); 631 objNext.src = href; 632 } 633 } 634 }, 635 636 _draw = function(pos) { 637 var dim = { 638 width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), 639 height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), 640 641 top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), 642 left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) 643 }; 644 645 if (typeof final_pos.opacity !== 'undefined') { 646 dim.opacity = pos < 0.5 ? 0.5 : pos; 647 } 648 649 wrap.css(dim); 650 651 content.css({ 652 'width' : dim.width - currentOpts.padding * 2, 653 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 654 }); 655 }, 656 657 _get_viewport = function() { 658 return [ 659 $(window).width() - (currentOpts.margin * 2), 660 $(window).height() - (currentOpts.margin * 2), 661 $(document).scrollLeft() + currentOpts.margin, 662 $(document).scrollTop() + currentOpts.margin 663 ]; 664 }, 665 666 _get_zoom_to = function () { 667 var view = _get_viewport(), 668 to = {}, 669 resize = currentOpts.autoScale, 670 double_padding = currentOpts.padding * 2, 671 ratio; 672 673 if (currentOpts.width.toString().indexOf('%') > -1) { 674 to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); 675 } else { 676 to.width = currentOpts.width + double_padding; 677 } 678 679 if (currentOpts.height.toString().indexOf('%') > -1) { 680 to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); 681 } else { 682 to.height = currentOpts.height + double_padding; 683 } 684 685 if (resize && (to.width > view[0] || to.height > view[1])) { 686 if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { 687 ratio = (currentOpts.width ) / (currentOpts.height ); 688 689 if ((to.width ) > view[0]) { 690 to.width = view[0]; 691 to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); 692 } 693 694 if ((to.height) > view[1]) { 695 to.height = view[1]; 696 to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); 697 } 698 699 } else { 700 to.width = Math.min(to.width, view[0]); 701 to.height = Math.min(to.height, view[1]); 702 } 703 } 704 705 to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); 706 to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); 707 708 return to; 709 }, 710 711 _get_obj_pos = function(obj) { 712 var pos = obj.offset(); 713 714 pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; 715 pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; 716 717 pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; 718 pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; 719 720 pos.width = obj.width(); 721 pos.height = obj.height(); 722 723 return pos; 724 }, 725 726 _get_zoom_from = function() { 727 var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, 728 from = {}, 729 pos, 730 view; 731 732 if (orig && orig.length) { 733 pos = _get_obj_pos(orig); 734 735 from = { 736 width : pos.width + (currentOpts.padding * 2), 737 height : pos.height + (currentOpts.padding * 2), 738 top : pos.top - currentOpts.padding - 20, 739 left : pos.left - currentOpts.padding - 20 740 }; 741 742 } else { 743 view = _get_viewport(); 744 745 from = { 746 width : currentOpts.padding * 2, 747 height : currentOpts.padding * 2,
748 top : parseInt(view[3] + view[1] * 0.5, 10), 749 left : parseInt(view[2] + view[0] * 0.5, 10) 750 }; 751 } 752 753 return from; 754 }, 755 756 _animate_loading = function() { 757 if (!loading.is(':visible')){ 758 clearInterval(loadingTimer); 759 return; 760 } 761 762 $('div', loading).css('top', (loadingFrame * -40) + 'px'); 763 764 loadingFrame = (loadingFrame + 1) % 12; 765 }; 766 767 /* 768 * Public methods 769 */ 770 771 $.fn.fancybox = function(options) { 772 if (!$(this).length) { 773 return this; 774 } 775 776 $(this) 777 .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) 778 .unbind('click.fb') 779 .bind('click.fb', function(e) { 780 e.preventDefault(); 781 782 if (busy) { 783 return; 784 } 785 786 busy = true; 787 788 $(this).blur(); 789 790 selectedArray = []; 791 selectedIndex = 0; 792 793 var rel = $(this).attr('rel') || ''; 794 795 if (!rel || rel == '' || rel === 'nofollow') { 796 selectedArray.push(this); 797 798 } else { 799 selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); 800 selectedIndex = selectedArray.index( this ); 801 } 802 803 _start(); 804 805 return; 806 }); 807 808 return this; 809 }; 810 811 $.fancybox = function(obj) { 812 var opts; 813 814 if (busy) { 815 return; 816 } 817 818 busy = true; 819 opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; 820 821 selectedArray = []; 822 selectedIndex = parseInt(opts.index, 10) || 0; 823 824 if ($.isArray(obj)) { 825 for (var i = 0, j = obj.length; i < j; i++) { 826 if (typeof obj[i] == 'object') { 827 $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); 828 } else { 829 obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); 830 } 831 } 832 833 selectedArray = jQuery.merge(selectedArray, obj); 834 835 } else { 836 if (typeof obj == 'object') { 837 $(obj).data('fancybox', $.extend({}, opts, obj)); 838 } else { 839 obj = $({}).data('fancybox', $.extend({content : obj}, opts)); 840 } 841 842 selectedArray.push(obj); 843 } 844 845 if (selectedIndex > selectedArray.length || selectedIndex < 0) { 846 selectedIndex = 0; 847 } 848 849 _start(); 850 }; 851 852 $.fancybox.showActivity = function() { 853 clearInterval(loadingTimer); 854 855 loading.show(); 856 loadingTimer = setInterval(_animate_loading, 66); 857 }; 858 859 $.fancybox.hideActivity = function() { 860 loading.hide(); 861 }; 862 863 $.fancybox.next = function() { 864 return $.fancybox.pos( currentIndex + 1); 865 }; 866 867 $.fancybox.prev = function() { 868 return $.fancybox.pos( currentIndex - 1); 869 }; 870 871 $.fancybox.pos = function(pos) { 872 if (busy) { 873 return; 874 } 875 876 pos = parseInt(pos); 877 878 selectedArray = currentArray; 879 880 if (pos > -1 && pos < currentArray.length) { 881 selectedIndex = pos; 882 _start(); 883 884 } else if (currentOpts.cyclic && currentArray.length > 1) { 885 selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; 886 _start(); 887 } 888 889 return; 890 }; 891 892 $.fancybox.cancel = function() { 893 if (busy) { 894 return; 895 } 896 897 busy = true; 898 899 $.event.trigger('fancybox-cancel'); 900 901 _abort(); 902 903 selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); 904 905 busy = false; 906 }; 907 908 // Note: within an iframe use - parent.$.fancybox.close(); 909 $.fancybox.close = function() { 910 if (busy || wrap.is(':hidden')) { 911 return; 912 } 913 914 busy = true; 915 916 if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { 917 busy = false; 918 return; 919 } 920 921 _abort(); 922 923 $(close.add( nav_left ).add( nav_right )).hide(); 924 925 $(content.add( overlay )).unbind(); 926 927 $(window).unbind("resize.fb scroll.fb"); 928 $(document).unbind('keydown.fb'); 929 930 content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); 931 932 if (currentOpts.titlePosition !== 'inside') { 933 title.empty(); 934 } 935 936 wrap.stop(); 937 938 function _cleanup() { 939 overlay.fadeOut('fast'); 940 941 title.empty().hide(); 942 wrap.hide(); 943 944 $.event.trigger('fancybox-cleanup'); 945 946 content.empty(); 947 948 currentOpts.onClosed(currentArray, currentIndex, currentOpts); 949 950 currentArray = selectedOpts = []; 951 currentIndex = selectedIndex = 0; 952 currentOpts = selectedOpts = {}; 953 954 busy = false; 955 } 956 957 if (currentOpts.transitionOut == 'elastic') { 958 start_pos = _get_zoom_from(); 959 960 var pos = wrap.position(); 961 962 final_pos = { 963 top : pos.top , 964 left : pos.left, 965 width : wrap.width(), 966 height : wrap.height() 967 }; 968 969 if (currentOpts.opacity) { 970 final_pos.opacity = 1; 971 } 972 973 title.empty().hide(); 974 975 fx.prop = 1; 976 977 $(fx).animate({ prop: 0 }, { 978 duration : currentOpts.speedOut, 979 easing : currentOpts.easingOut, 980 step : _draw, 981 complete : _cleanup 982 }); 983 984 } else { 985 wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); 986 } 987 }; 988 989 $.fancybox.resize = function() { 990 if (overlay.is(':visible')) { 991 overlay.css('height', $(document).height()); 992 } 993 994 $.fancybox.center(true); 995 }; 996 997 $.fancybox.center = function() { 998 var view, align; 999 1000 if (busy) { 1001 return; 1002 } 1003 1004 align = arguments[0] === true ? 1 : 0; 1005 view = _get_viewport(); 1006 1007 if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { 1008 return; 1009 } 1010 1011 wrap 1012 .stop() 1013 .animate({ 1014 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), 1015 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) 1016 }, typeof arguments[0] == 'number' ? arguments[0] : 200); 1017 }; 1018 1019 $.fancybox.init = function() { 1020 if ($("#fancybox-wrap").length) { 1021 return; 1022 } 1023 1024 $('body').append( 1025 tmp = $('<div id="fancybox-tmp"></div>'), 1026 loading = $('<div id="fancybox-loading"><div></div></div>'), 1027 overlay = $('<div id="fancybox-overlay"></div>'), 1028 wrap = $('<div id="fancybox-wrap"></div>') 1029 ); 1030
1031 outer = $('<div id="fancybox-outer"></div>') 1032 .append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>') 1033 .appendTo( wrap ); 1034 1035 outer.append( 1036 content = $('<div id="fancybox-content"></div>'), 1037 close = $('<a id="fancybox-close"></a>'), 1038 title = $('<div id="fancybox-title"></div>'), 1039 1040 nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'), 1041 nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>') 1042 ); 1043 1044 close.click($.fancybox.close); 1045 loading.click($.fancybox.cancel); 1046 1047 nav_left.click(function(e) { 1048 e.preventDefault(); 1049 $.fancybox.prev(); 1050 }); 1051 1052 nav_right.click(function(e) { 1053 e.preventDefault(); 1054 $.fancybox.next(); 1055 }); 1056 1057 if ($.fn.mousewheel) { 1058 wrap.bind('mousewheel.fb', function(e, delta) { 1059 e.preventDefault(); 1060 1061 $.fancybox[ delta > 0 ? 'prev' : 'next'](); 1062 }); 1063 } 1064 1065 if (!$.support.opacity) { 1066 wrap.addClass('fancybox-ie'); 1067 } 1068 1069 if (isIE6) { 1070 loading.addClass('fancybox-ie6'); 1071 wrap.addClass('fancybox-ie6'); 1072 1073 $('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer); 1074 } 1075 }; 1076 1077 $.fn.fancybox.defaults = { 1078 padding : 10, 1079 margin : 40, 1080 opacity : false, 1081 modal : false, 1082 cyclic : false, 1083 scrolling : 'auto', // 'auto', 'yes' or 'no' 1084 1085 width : 560, 1086 height : 340, 1087 1088 autoScale : true, 1089 autoDimensions : true, 1090 centerOnScroll : false, 1091 1092 ajax : {}, 1093 swf : { wmode: 'transparent' }, 1094 1095 hideOnOverlayClick : true, 1096 hideOnContentClick : false, 1097 1098 overlayShow : true, 1099 overlayOpacity : 0.7, 1100 overlayColor : '#000', 1101 1102 titleShow : true, 1103 titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' 1104 titleFormat : null, 1105 titleFromAlt : false, 1106 1107 transitionIn : 'fade', // 'elastic', 'fade' or 'none' 1108 transitionOut : 'fade', // 'elastic', 'fade' or 'none' 1109 1110 speedIn : 300, 1111 speedOut : 300, 1112 1113 changeSpeed : 300, 1114 changeFade : 'fast', 1115 1116 easingIn : 'swing', 1117 easingOut : 'swing', 1118 1119 showCloseButton : true, 1120 showNavArrows : true, 1121 enableEscapeButton : true, 1122 enableKeyboardNav : true, 1123 1124 onStart : function(){}, 1125 onCancel : function(){}, 1126 onComplete : function(){}, 1127 onCleanup : function(){}, 1128 onClosed : function(){}, 1129 onError : function(){} 1130 }; 1131 1132 $(document).ready(function() { 1133 $.fancybox.init(); 1134 }); 1135 1136})(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.