annotate bns_website/static/js/fancybox/jquery.fancybox-1.3.4.js @ 24:0bac5dfbcc7c

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