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