-- added fancybox 1.3.1 to project, initially for showing screenshots. See documentat...
[Bookkeeping.git] / webkell / fancybox / jquery.fancybox-1.3.1.js
blob688f93aa34a8b739cbaeaf23e3dbfbaac8c098a4
1 /*\r
2  * FancyBox - jQuery Plugin\r
3  * Simple and fancy lightbox alternative\r
4  *\r
5  * Examples and documentation at: http://fancybox.net\r
6  * \r
7  * Copyright (c) 2008 - 2010 Janis Skarnelis\r
8  *\r
9  * Version: 1.3.1 (05/03/2010)\r
10  * Requires: jQuery v1.3+\r
11  *\r
12  * Dual licensed under the MIT and GPL licenses:\r
13  *   http://www.opensource.org/licenses/mit-license.php\r
14  *   http://www.gnu.org/licenses/gpl.html\r
15  */\r
17 (function($) {\r
19         var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,\r
21                 selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],\r
23                 ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,\r
25                 loadingTimer, loadingFrame = 1,\r
27                 start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0, \r
29                 isIE6 = !$.support.opacity && !window.XMLHttpRequest,\r
31                 /*\r
32                  * Private methods \r
33                  */\r
35                 fancybox_abort = function() {\r
36                         loading.hide();\r
38                         imgPreloader.onerror = imgPreloader.onload = null;\r
40                         if (ajaxLoader) {\r
41                                 ajaxLoader.abort();\r
42                         }\r
44                         tmp.empty();\r
45                 },\r
47                 fancybox_error = function() {\r
48                         $.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {\r
49                                 'scrolling'             : 'no',\r
50                                 'padding'               : 20,\r
51                                 'transitionIn'  : 'none',\r
52                                 'transitionOut' : 'none'\r
53                         });\r
54                 },\r
56                 fancybox_get_viewport = function() {\r
57                         return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];\r
58                 },\r
60                 fancybox_get_zoom_to = function () {\r
61                         var view        = fancybox_get_viewport(),\r
62                                 to              = {},\r
64                                 margin = currentOpts.margin,\r
65                                 resize = currentOpts.autoScale,\r
67                                 horizontal_space        = (shadow + margin) * 2,\r
68                                 vertical_space          = (shadow + margin) * 2,\r
69                                 double_padding          = (currentOpts.padding * 2),\r
70                                 \r
71                                 ratio;\r
73                         if (currentOpts.width.toString().indexOf('%') > -1) {\r
74                                 to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;\r
75                                 resize = false;\r
77                         } else {\r
78                                 to.width = currentOpts.width + double_padding;\r
79                         }\r
81                         if (currentOpts.height.toString().indexOf('%') > -1) {\r
82                                 to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);\r
83                                 resize = false;\r
85                         } else {\r
86                                 to.height = currentOpts.height + double_padding;\r
87                         }\r
89                         if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {\r
90                                 if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {\r
91                                         horizontal_space        += double_padding;\r
92                                         vertical_space          += double_padding;\r
94                                         ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);\r
96                                         to.width        = Math.round(ratio * (to.width  - double_padding)) + double_padding;\r
97                                         to.height       = Math.round(ratio * (to.height - double_padding)) + double_padding;\r
99                                 } else {\r
100                                         to.width        = Math.min(to.width,    (view[0] - horizontal_space));\r
101                                         to.height       = Math.min(to.height,   (view[1] - vertical_space));\r
102                                 }\r
103                         }\r
105                         to.top  = view[3] + ((view[1] - (to.height      + (shadow * 2 ))) * 0.5);\r
106                         to.left = view[2] + ((view[0] - (to.width       + (shadow * 2 ))) * 0.5);\r
108                         if (currentOpts.autoScale === false) {\r
109                                 to.top  = Math.max(view[3] + margin, to.top);\r
110                                 to.left = Math.max(view[2] + margin, to.left);\r
111                         }\r
113                         return to;\r
114                 },\r
116                 fancybox_format_title = function(title) {\r
117                         if (title && title.length) {\r
118                                 switch (currentOpts.titlePosition) {\r
119                                         case 'inside':\r
120                                                 return title;\r
121                                         case 'over':\r
122                                                 return '<span id="fancybox-title-over">' + title + '</span>';\r
123                                         default:\r
124                                                 return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';\r
125                                 }\r
126                         }\r
128                         return false;\r
129                 },\r
131                 fancybox_process_title = function() {\r
132                         var title       = currentOpts.title,\r
133                                 width   = final_pos.width - (currentOpts.padding * 2),\r
134                                 titlec  = 'fancybox-title-' + currentOpts.titlePosition;\r
135                                 \r
136                         $('#fancybox-title').remove();\r
138                         titleh = 0;\r
140                         if (currentOpts.titleShow === false) {\r
141                                 return;\r
142                         }\r
144                         title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);\r
146                         if (!title || title === '') {\r
147                                 return;\r
148                         }\r
150                         $('<div id="fancybox-title" class="' + titlec + '" />').css({\r
151                                 'width'                 : width,\r
152                                 'paddingLeft'   : currentOpts.padding,\r
153                                 'paddingRight'  : currentOpts.padding\r
154                         }).html(title).appendTo('body');\r
156                         switch (currentOpts.titlePosition) {\r
157                                 case 'inside':\r
158                                         titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;\r
159                                         final_pos.height += titleh;\r
160                                 break;\r
162                                 case 'over':\r
163                                         $('#fancybox-title').css('bottom', currentOpts.padding);\r
164                                 break;\r
166                                 default:\r
167                                         $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);\r
168                                 break;\r
169                         }\r
171                         $('#fancybox-title').appendTo( outer ).hide();\r
172                 },\r
174                 fancybox_set_navigation = function() {\r
175                         $(document).unbind('keydown.fb').bind('keydown.fb', function(e) {\r
176                                 if (e.keyCode == 27 && currentOpts.enableEscapeButton) {\r
177                                         e.preventDefault();\r
178                                         $.fancybox.close();\r
180                                 } else if (e.keyCode == 37) {\r
181                                         e.preventDefault();\r
182                                         $.fancybox.prev();\r
184                                 } else if (e.keyCode == 39) {\r
185                                         e.preventDefault();\r
186                                         $.fancybox.next();\r
187                                 }\r
188                         });\r
190                         if ($.fn.mousewheel) {\r
191                                 wrap.unbind('mousewheel.fb');\r
193                                 if (currentArray.length > 1) {\r
194                                         wrap.bind('mousewheel.fb', function(e, delta) {\r
195                                                 e.preventDefault();\r
197                                                 if (busy || delta === 0) {\r
198                                                         return;\r
199                                                 }\r
201                                                 if (delta > 0) {\r
202                                                         $.fancybox.prev();\r
203                                                 } else {\r
204                                                         $.fancybox.next();\r
205                                                 }\r
206                                         });\r
207                                 }\r
208                         }\r
210                         if (!currentOpts.showNavArrows) { return; }\r
212                         if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {\r
213                                 nav_left.show();\r
214                         }\r
216                         if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {\r
217                                 nav_right.show();\r
218                         }\r
219                 },\r
221                 fancybox_preload_images = function() {\r
222                         var href, \r
223                                 objNext;\r
224                                 \r
225                         if ((currentArray.length -1) > currentIndex) {\r
226                                 href = currentArray[ currentIndex + 1 ].href;\r
228                                 if (typeof href !== 'undefined' && href.match(imgRegExp)) {\r
229                                         objNext = new Image();\r
230                                         objNext.src = href;\r
231                                 }\r
232                         }\r
234                         if (currentIndex > 0) {\r
235                                 href = currentArray[ currentIndex - 1 ].href;\r
237                                 if (typeof href !== 'undefined' && href.match(imgRegExp)) {\r
238                                         objNext = new Image();\r
239                                         objNext.src = href;\r
240                                 }\r
241                         }\r
242                 },\r
244                 _finish = function () {\r
245                         inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));\r
247                         if (!$.support.opacity) {\r
248                                 inner.get(0).style.removeAttribute('filter');\r
249                                 wrap.get(0).style.removeAttribute('filter');\r
250                         }\r
252                         $('#fancybox-title').show();\r
254                         if (currentOpts.hideOnContentClick)     {\r
255                                 inner.one('click', $.fancybox.close);\r
256                         }\r
257                         if (currentOpts.hideOnOverlayClick)     {\r
258                                 overlay.one('click', $.fancybox.close);\r
259                         }\r
261                         if (currentOpts.showCloseButton) {\r
262                                 close.show();\r
263                         }\r
265                         fancybox_set_navigation();\r
267                         $(window).bind("resize.fb", $.fancybox.center);\r
269                         if (currentOpts.centerOnScroll) {\r
270                                 $(window).bind("scroll.fb", $.fancybox.center);\r
271                         } else {\r
272                                 $(window).unbind("scroll.fb");\r
273                         }\r
275                         if ($.isFunction(currentOpts.onComplete)) {\r
276                                 currentOpts.onComplete(currentArray, currentIndex, currentOpts);\r
277                         }\r
279                         busy = false;\r
281                         fancybox_preload_images();\r
282                 },\r
284                 fancybox_draw = function(pos) {\r
285                         var width       = Math.round(start_pos.width    + (final_pos.width      - start_pos.width)      * pos),\r
286                                 height  = Math.round(start_pos.height   + (final_pos.height     - start_pos.height)     * pos),\r
288                                 top             = Math.round(start_pos.top      + (final_pos.top        - start_pos.top)        * pos),\r
289                                 left    = Math.round(start_pos.left     + (final_pos.left       - start_pos.left)       * pos);\r
291                         wrap.css({\r
292                                 'width'         : width         + 'px',\r
293                                 'height'        : height        + 'px',\r
294                                 'top'           : top           + 'px',\r
295                                 'left'          : left          + 'px'\r
296                         });\r
298                         width   = Math.max(width - currentOpts.padding * 2, 0);\r
299                         height  = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);\r
301                         inner.css({\r
302                                 'width'         : width         + 'px',\r
303                                 'height'        : height        + 'px'\r
304                         });\r
306                         if (typeof final_pos.opacity !== 'undefined') {\r
307                                 wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));\r
308                         }\r
309                 },\r
311                 fancybox_get_obj_pos = function(obj) {\r
312                         var pos         = obj.offset();\r
314                         pos.top         += parseFloat( obj.css('paddingTop') )  || 0;\r
315                         pos.left        += parseFloat( obj.css('paddingLeft') ) || 0;\r
317                         pos.top         += parseFloat( obj.css('border-top-width') )    || 0;\r
318                         pos.left        += parseFloat( obj.css('border-left-width') )   || 0;\r
320                         pos.width       = obj.width();\r
321                         pos.height      = obj.height();\r
323                         return pos;\r
324                 },\r
326                 fancybox_get_zoom_from = function() {\r
327                         var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,\r
328                                 from = {},\r
329                                 pos,\r
330                                 view;\r
332                         if (orig && orig.length) {\r
333                                 pos = fancybox_get_obj_pos(orig);\r
335                                 from = {\r
336                                         width   : (pos.width    + (currentOpts.padding * 2)),\r
337                                         height  : (pos.height   + (currentOpts.padding * 2)),\r
338                                         top             : (pos.top              - currentOpts.padding - shadow),\r
339                                         left    : (pos.left             - currentOpts.padding - shadow)\r
340                                 };\r
341                                 \r
342                         } else {\r
343                                 view = fancybox_get_viewport();\r
345                                 from = {\r
346                                         width   : 1,\r
347                                         height  : 1,\r
348                                         top             : view[3] + view[1] * 0.5,\r
349                                         left    : view[2] + view[0] * 0.5\r
350                                 };\r
351                         }\r
353                         return from;\r
354                 },\r
356                 fancybox_show = function() {\r
357                         loading.hide();\r
359                         if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {\r
360                                 if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {\r
361                                         $.event.trigger('fancybox-cancel');\r
363                                         busy = false;\r
364                                         return;\r
365                                 }\r
366                         }\r
368                         currentArray    = selectedArray;\r
369                         currentIndex    = selectedIndex;\r
370                         currentOpts             = selectedOpts;\r
372                         inner.get(0).scrollTop  = 0;\r
373                         inner.get(0).scrollLeft = 0;\r
375                         if (currentOpts.overlayShow) {\r
376                                 if (isIE6) {\r
377                                         $('select:not(#fancybox-tmp select)').filter(function() {\r
378                                                 return this.style.visibility !== 'hidden';\r
379                                         }).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {\r
380                                                 this.style.visibility = 'inherit';\r
381                                         });\r
382                                 }\r
384                                 overlay.css({\r
385                                         'background-color'      : currentOpts.overlayColor,\r
386                                         'opacity'                       : currentOpts.overlayOpacity\r
387                                 }).unbind().show();\r
388                         }\r
390                         final_pos = fancybox_get_zoom_to();\r
392                         fancybox_process_title();\r
394                         if (wrap.is(":visible")) {\r
395                                 $( close.add( nav_left ).add( nav_right ) ).hide();\r
397                                 var pos = wrap.position(),\r
398                                         equal;\r
400                                 start_pos = {\r
401                                         top             :       pos.top ,\r
402                                         left    :       pos.left,\r
403                                         width   :       wrap.width(),\r
404                                         height  :       wrap.height()\r
405                                 };\r
407                                 equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);\r
409                                 inner.fadeOut(currentOpts.changeFade, function() {\r
410                                         var finish_resizing = function() {\r
411                                                 inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);\r
412                                         };\r
413                                         \r
414                                         $.event.trigger('fancybox-change');\r
416                                         inner.empty().css('overflow', 'hidden');\r
418                                         if (equal) {\r
419                                                 inner.css({\r
420                                                         top                     : currentOpts.padding,\r
421                                                         left            : currentOpts.padding,\r
422                                                         width           : Math.max(final_pos.width      - (currentOpts.padding * 2), 1),\r
423                                                         height          : Math.max(final_pos.height     - (currentOpts.padding * 2) - titleh, 1)\r
424                                                 });\r
425                                                 \r
426                                                 finish_resizing();\r
428                                         } else {\r
429                                                 inner.css({\r
430                                                         top                     : currentOpts.padding,\r
431                                                         left            : currentOpts.padding,\r
432                                                         width           : Math.max(start_pos.width      - (currentOpts.padding * 2), 1),\r
433                                                         height          : Math.max(start_pos.height     - (currentOpts.padding * 2), 1)\r
434                                                 });\r
435                                                 \r
436                                                 fx.prop = 0;\r
438                                                 $(fx).animate({ prop: 1 }, {\r
439                                                          duration       : currentOpts.changeSpeed,\r
440                                                          easing         : currentOpts.easingChange,\r
441                                                          step           : fancybox_draw,\r
442                                                          complete       : finish_resizing\r
443                                                 });\r
444                                         }\r
445                                 });\r
447                                 return;\r
448                         }\r
450                         wrap.css('opacity', 1);\r
452                         if (currentOpts.transitionIn == 'elastic') {\r
453                                 start_pos = fancybox_get_zoom_from();\r
455                                 inner.css({\r
456                                                 top                     : currentOpts.padding,\r
457                                                 left            : currentOpts.padding,\r
458                                                 width           : Math.max(start_pos.width      - (currentOpts.padding * 2), 1),\r
459                                                 height          : Math.max(start_pos.height     - (currentOpts.padding * 2), 1)\r
460                                         })\r
461                                         .html( tmp.contents() );\r
463                                 wrap.css(start_pos).show();\r
465                                 if (currentOpts.opacity) {\r
466                                         final_pos.opacity = 0;\r
467                                 }\r
469                                 fx.prop = 0;\r
471                                 $(fx).animate({ prop: 1 }, {\r
472                                          duration       : currentOpts.speedIn,\r
473                                          easing         : currentOpts.easingIn,\r
474                                          step           : fancybox_draw,\r
475                                          complete       : _finish\r
476                                 });\r
478                         } else {\r
479                                 inner.css({\r
480                                                 top                     : currentOpts.padding,\r
481                                                 left            : currentOpts.padding,\r
482                                                 width           : Math.max(final_pos.width      - (currentOpts.padding * 2), 1),\r
483                                                 height          : Math.max(final_pos.height     - (currentOpts.padding * 2) - titleh, 1)\r
484                                         })\r
485                                         .html( tmp.contents() );\r
487                                 wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );\r
488                         }\r
489                 },\r
491                 fancybox_process_inline = function() {\r
492                         tmp.width(      selectedOpts.width );\r
493                         tmp.height(     selectedOpts.height );\r
495                         if (selectedOpts.width  == 'auto') {\r
496                                 selectedOpts.width = tmp.width();\r
497                         }\r
498                         if (selectedOpts.height == 'auto') {\r
499                                 selectedOpts.height     = tmp.height();\r
500                         }\r
502                         fancybox_show();\r
503                 },\r
504                 \r
505                 fancybox_process_image = function() {\r
506                         busy = true;\r
508                         selectedOpts.width      = imgPreloader.width;\r
509                         selectedOpts.height     = imgPreloader.height;\r
511                         $("<img />").attr({\r
512                                 'id'    : 'fancybox-img',\r
513                                 'src'   : imgPreloader.src,\r
514                                 'alt'   : selectedOpts.title\r
515                         }).appendTo( tmp );\r
517                         fancybox_show();\r
518                 },\r
520                 fancybox_start = function() {\r
521                         fancybox_abort();\r
523                         var obj = selectedArray[ selectedIndex ],\r
524                                 href, \r
525                                 type, \r
526                                 title,\r
527                                 str,\r
528                                 emb,\r
529                                 selector,\r
530                                 data;\r
532                         selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));\r
533                         title = obj.title || $(obj).title || selectedOpts.title || '';\r
534                         \r
535                         if (obj.nodeName && !selectedOpts.orig) {\r
536                                 selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);\r
537                         }\r
539                         if (title === '' && selectedOpts.orig) {\r
540                                 title = selectedOpts.orig.attr('alt');\r
541                         }\r
543                         if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {\r
544                                 href = selectedOpts.href || null;\r
545                         } else {\r
546                                 href = selectedOpts.href || obj.href || null;\r
547                         }\r
549                         if (selectedOpts.type) {\r
550                                 type = selectedOpts.type;\r
552                                 if (!href) {\r
553                                         href = selectedOpts.content;\r
554                                 }\r
555                                 \r
556                         } else if (selectedOpts.content) {\r
557                                 type    = 'html';\r
559                         } else if (href) {\r
560                                 if (href.match(imgRegExp)) {\r
561                                         type = 'image';\r
563                                 } else if (href.match(swfRegExp)) {\r
564                                         type = 'swf';\r
566                                 } else if ($(obj).hasClass("iframe")) {\r
567                                         type = 'iframe';\r
569                                 } else if (href.match(/#/)) {\r
570                                         obj = href.substr(href.indexOf("#"));\r
572                                         type = $(obj).length > 0 ? 'inline' : 'ajax';\r
573                                 } else {\r
574                                         type = 'ajax';\r
575                                 }\r
576                         } else {\r
577                                 type = 'inline';\r
578                         }\r
580                         selectedOpts.type       = type;\r
581                         selectedOpts.href       = href;\r
582                         selectedOpts.title      = title;\r
584                         if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {\r
585                                 selectedOpts.width              = 'auto';\r
586                                 selectedOpts.height             = 'auto';\r
587                         }\r
589                         if (selectedOpts.modal) {\r
590                                 selectedOpts.overlayShow                = true;\r
591                                 selectedOpts.hideOnOverlayClick = false;\r
592                                 selectedOpts.hideOnContentClick = false;\r
593                                 selectedOpts.enableEscapeButton = false;\r
594                                 selectedOpts.showCloseButton    = false;\r
595                         }\r
597                         if ($.isFunction(selectedOpts.onStart)) {\r
598                                 if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {\r
599                                         busy = false;\r
600                                         return;\r
601                                 }\r
602                         }\r
604                         tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));\r
606                         $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {\r
607                                 $(this).replaceWith(inner.children());\r
608                         });\r
610                         switch (type) {\r
611                                 case 'html' :\r
612                                         tmp.html( selectedOpts.content );\r
613                                         fancybox_process_inline();\r
614                                 break;\r
616                                 case 'inline' :\r
617                                         $('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {\r
618                                                 $(this).replaceWith(inner.children());\r
619                                         }).bind('fancybox-cancel', function() {\r
620                                                 $(this).replaceWith(tmp.children());\r
621                                         });\r
623                                         $(obj).appendTo(tmp);\r
625                                         fancybox_process_inline();\r
626                                 break;\r
628                                 case 'image':\r
629                                         busy = false;\r
631                                         $.fancybox.showActivity();\r
633                                         imgPreloader = new Image();\r
635                                         imgPreloader.onerror = function() {\r
636                                                 fancybox_error();\r
637                                         };\r
639                                         imgPreloader.onload = function() {\r
640                                                 imgPreloader.onerror = null;\r
641                                                 imgPreloader.onload = null;\r
642                                                 fancybox_process_image();\r
643                                         };\r
645                                         imgPreloader.src = href;\r
646                 \r
647                                 break;\r
649                                 case 'swf':\r
650                                         str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';\r
651                                         emb = '';\r
652                                         \r
653                                         $.each(selectedOpts.swf, function(name, val) {\r
654                                                 str += '<param name="' + name + '" value="' + val + '"></param>';\r
655                                                 emb += ' ' + name + '="' + val + '"';\r
656                                         });\r
658                                         str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';\r
660                                         tmp.html(str);\r
662                                         fancybox_process_inline();\r
663                                 break;\r
665                                 case 'ajax':\r
666                                         selector        = href.split('#', 2);\r
667                                         data            = selectedOpts.ajax.data || {};\r
669                                         if (selector.length > 1) {\r
670                                                 href = selector[0];\r
672                                                 if (typeof data == "string") {\r
673                                                         data += '&selector=' + selector[1];\r
674                                                 } else {\r
675                                                         data.selector = selector[1];\r
676                                                 }\r
677                                         }\r
679                                         busy = false;\r
680                                         $.fancybox.showActivity();\r
682                                         ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {\r
683                                                 url             : href,\r
684                                                 data    : data,\r
685                                                 error   : fancybox_error,\r
686                                                 success : function(data, textStatus, XMLHttpRequest) {\r
687                                                         if (ajaxLoader.status == 200) {\r
688                                                                 tmp.html( data );\r
689                                                                 fancybox_process_inline();\r
690                                                         }\r
691                                                 }\r
692                                         }));\r
694                                 break;\r
696                                 case 'iframe' :\r
697                                         $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);\r
698                                         fancybox_show();\r
699                                 break;\r
700                         }\r
701                 },\r
703                 fancybox_animate_loading = function() {\r
704                         if (!loading.is(':visible')){\r
705                                 clearInterval(loadingTimer);\r
706                                 return;\r
707                         }\r
709                         $('div', loading).css('top', (loadingFrame * -40) + 'px');\r
711                         loadingFrame = (loadingFrame + 1) % 12;\r
712                 },\r
714                 fancybox_init = function() {\r
715                         if ($("#fancybox-wrap").length) {\r
716                                 return;\r
717                         }\r
719                         $('body').append(\r
720                                 tmp                     = $('<div id="fancybox-tmp"></div>'),\r
721                                 loading         = $('<div id="fancybox-loading"><div></div></div>'),\r
722                                 overlay         = $('<div id="fancybox-overlay"></div>'),\r
723                                 wrap            = $('<div id="fancybox-wrap"></div>')\r
724                         );\r
726                         if (!$.support.opacity) {\r
727                                 wrap.addClass('fancybox-ie');\r
728                                 loading.addClass('fancybox-ie');\r
729                         }\r
731                         outer = $('<div id="fancybox-outer"></div>')\r
732                                 .append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')\r
733                                 .appendTo( wrap );\r
735                         outer.append(\r
736                                 inner           = $('<div id="fancybox-inner"></div>'),\r
737                                 close           = $('<a id="fancybox-close"></a>'),\r
739                                 nav_left        = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),\r
740                                 nav_right       = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')\r
741                         );\r
743                         close.click($.fancybox.close);\r
744                         loading.click($.fancybox.cancel);\r
746                         nav_left.click(function(e) {\r
747                                 e.preventDefault();\r
748                                 $.fancybox.prev();\r
749                         });\r
751                         nav_right.click(function(e) {\r
752                                 e.preventDefault();\r
753                                 $.fancybox.next();\r
754                         });\r
756                         if (isIE6) {\r
757                                 overlay.get(0).style.setExpression('height',    "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");\r
758                                 loading.get(0).style.setExpression('top',               "(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");\r
760                                 outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');\r
761                         }\r
762                 };\r
764         /*\r
765          * Public methods \r
766          */\r
768         $.fn.fancybox = function(options) {\r
769                 $(this)\r
770                         .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))\r
771                         .unbind('click.fb').bind('click.fb', function(e) {\r
772                                 e.preventDefault();\r
774                                 if (busy) {\r
775                                         return;\r
776                                 }\r
778                                 busy = true;\r
780                                 $(this).blur();\r
782                                 selectedArray   = [];\r
783                                 selectedIndex   = 0;\r
785                                 var rel = $(this).attr('rel') || '';\r
787                                 if (!rel || rel == '' || rel === 'nofollow') {\r
788                                         selectedArray.push(this);\r
790                                 } else {\r
791                                         selectedArray   = $("a[rel=" + rel + "], area[rel=" + rel + "]");\r
792                                         selectedIndex   = selectedArray.index( this );\r
793                                 }\r
795                                 fancybox_start();\r
797                                 return false;\r
798                         });\r
800                 return this;\r
801         };\r
803         $.fancybox = function(obj) {\r
804                 if (busy) {\r
805                         return;\r
806                 }\r
808                 busy = true;\r
810                 var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};\r
812                 selectedArray   = [];\r
813                 selectedIndex   = opts.index || 0;\r
815                 if ($.isArray(obj)) {\r
816                         for (var i = 0, j = obj.length; i < j; i++) {\r
817                                 if (typeof obj[i] == 'object') {\r
818                                         $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));\r
819                                 } else {\r
820                                         obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));\r
821                                 }\r
822                         }\r
824                         selectedArray = jQuery.merge(selectedArray, obj);\r
826                 } else {\r
827                         if (typeof obj == 'object') {\r
828                                 $(obj).data('fancybox', $.extend({}, opts, obj));\r
829                         } else {\r
830                                 obj = $({}).data('fancybox', $.extend({content : obj}, opts));\r
831                         }\r
833                         selectedArray.push(obj);\r
834                 }\r
836                 if (selectedIndex > selectedArray.length || selectedIndex < 0) {\r
837                         selectedIndex = 0;\r
838                 }\r
840                 fancybox_start();\r
841         };\r
843         $.fancybox.showActivity = function() {\r
844                 clearInterval(loadingTimer);\r
846                 loading.show();\r
847                 loadingTimer = setInterval(fancybox_animate_loading, 66);\r
848         };\r
850         $.fancybox.hideActivity = function() {\r
851                 loading.hide();\r
852         };\r
854         $.fancybox.next = function() {\r
855                 return $.fancybox.pos( currentIndex + 1);\r
856         };\r
857         \r
858         $.fancybox.prev = function() {\r
859                 return $.fancybox.pos( currentIndex - 1);\r
860         };\r
862         $.fancybox.pos = function(pos) {\r
863                 if (busy) {\r
864                         return;\r
865                 }\r
867                 pos = parseInt(pos, 10);\r
869                 if (pos > -1 && currentArray.length > pos) {\r
870                         selectedIndex = pos;\r
871                         fancybox_start();\r
872                 }\r
874                 if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {\r
875                         selectedIndex = currentArray.length - 1;\r
876                         fancybox_start();\r
877                 }\r
879                 if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {\r
880                         selectedIndex = 0;\r
881                         fancybox_start();\r
882                 }\r
884                 return;\r
885         };\r
887         $.fancybox.cancel = function() {\r
888                 if (busy) {\r
889                         return;\r
890                 }\r
892                 busy = true;\r
894                 $.event.trigger('fancybox-cancel');\r
896                 fancybox_abort();\r
898                 if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {\r
899                         selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);\r
900                 }\r
902                 busy = false;\r
903         };\r
905         // Note: within an iframe use - parent.$.fancybox.close();\r
906         $.fancybox.close = function() {\r
907                 if (busy || wrap.is(':hidden')) {\r
908                         return;\r
909                 }\r
911                 busy = true;\r
913                 if (currentOpts && $.isFunction(currentOpts.onCleanup)) {\r
914                         if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {\r
915                                 busy = false;\r
916                                 return;\r
917                         }\r
918                 }\r
920                 fancybox_abort();\r
922                 $(close.add( nav_left ).add( nav_right )).hide();\r
924                 $('#fancybox-title').remove();\r
926                 wrap.add(inner).add(overlay).unbind();\r
928                 $(window).unbind("resize.fb scroll.fb");\r
929                 $(document).unbind('keydown.fb');\r
931                 function _cleanup() {\r
932                         overlay.fadeOut('fast');\r
934                         wrap.hide();\r
936                         $.event.trigger('fancybox-cleanup');\r
938                         inner.empty();\r
940                         if ($.isFunction(currentOpts.onClosed)) {\r
941                                 currentOpts.onClosed(currentArray, currentIndex, currentOpts);\r
942                         }\r
944                         currentArray    = selectedOpts  = [];\r
945                         currentIndex    = selectedIndex = 0;\r
946                         currentOpts             = selectedOpts  = {};\r
948                         busy = false;\r
949                 }\r
951                 inner.css('overflow', 'hidden');\r
953                 if (currentOpts.transitionOut == 'elastic') {\r
954                         start_pos = fancybox_get_zoom_from();\r
956                         var pos = wrap.position();\r
958                         final_pos = {\r
959                                 top             :       pos.top ,\r
960                                 left    :       pos.left,\r
961                                 width   :       wrap.width(),\r
962                                 height  :       wrap.height()\r
963                         };\r
965                         if (currentOpts.opacity) {\r
966                                 final_pos.opacity = 1;\r
967                         }\r
969                         fx.prop = 1;\r
971                         $(fx).animate({ prop: 0 }, {\r
972                                  duration       : currentOpts.speedOut,\r
973                                  easing         : currentOpts.easingOut,\r
974                                  step           : fancybox_draw,\r
975                                  complete       : _cleanup\r
976                         });\r
978                 } else {\r
979                         wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);\r
980                 }\r
981         };\r
983         $.fancybox.resize = function() {\r
984                 var c, h;\r
985                 \r
986                 if (busy || wrap.is(':hidden')) {\r
987                         return;\r
988                 }\r
990                 busy = true;\r
992                 c = inner.wrapInner("<div style='overflow:auto'></div>").children();\r
993                 h = c.height();\r
995                 wrap.css({height:       h + (currentOpts.padding * 2) + titleh});\r
996                 inner.css({height:      h});\r
998                 c.replaceWith(c.children());\r
1000                 $.fancybox.center();\r
1001         };\r
1003         $.fancybox.center = function() {\r
1004                 busy = true;\r
1006                 var view        = fancybox_get_viewport(),\r
1007                         margin  = currentOpts.margin,\r
1008                         to              = {};\r
1010                 to.top  = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);\r
1011                 to.left = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);\r
1013                 to.top  = Math.max(view[3] + margin, to.top);\r
1014                 to.left = Math.max(view[2] + margin, to.left);\r
1016                 wrap.css(to);\r
1018                 busy = false;\r
1019         };\r
1021         $.fn.fancybox.defaults = {\r
1022                 padding                         :       10,\r
1023                 margin                          :       20,\r
1024                 opacity                         :       false,\r
1025                 modal                           :       false,\r
1026                 cyclic                          :       false,\r
1027                 scrolling                       :       'auto', // 'auto', 'yes' or 'no'\r
1029                 width                           :       560,\r
1030                 height                          :       340,\r
1032                 autoScale                       :       true,\r
1033                 autoDimensions          :       true,\r
1034                 centerOnScroll          :       false,\r
1036                 ajax                            :       {},\r
1037                 swf                                     :       { wmode: 'transparent' },\r
1039                 hideOnOverlayClick      :       true,\r
1040                 hideOnContentClick      :       false,\r
1042                 overlayShow                     :       true,\r
1043                 overlayOpacity          :       0.3,\r
1044                 overlayColor            :       '#666',\r
1046                 titleShow                       :       true,\r
1047                 titlePosition           :       'outside',      // 'outside', 'inside' or 'over'\r
1048                 titleFormat                     :       null,\r
1050                 transitionIn            :       'fade', // 'elastic', 'fade' or 'none'\r
1051                 transitionOut           :       'fade', // 'elastic', 'fade' or 'none'\r
1053                 speedIn                         :       300,\r
1054                 speedOut                        :       300,\r
1056                 changeSpeed                     :       300,\r
1057                 changeFade                      :       'fast',\r
1059                 easingIn                        :       'swing',\r
1060                 easingOut                       :       'swing',\r
1062                 showCloseButton         :       true,\r
1063                 showNavArrows           :       true,\r
1064                 enableEscapeButton      :       true,\r
1066                 onStart                         :       null,\r
1067                 onCancel                        :       null,\r
1068                 onComplete                      :       null,\r
1069                 onCleanup                       :       null,\r
1070                 onClosed                        :       null\r
1071         };\r
1073         $(document).ready(function() {\r
1074                 fancybox_init();\r
1075         });\r
1077 })(jQuery);