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