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