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