PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/wiki/public/fancybox/jquery.fancybox-1.3.1.js

http://zoop.googlecode.com/
JavaScript | 1077 lines | 785 code | 270 blank | 22 comment | 185 complexity | 8e8c18a9e7a147606a74ad2a5f4d2cff MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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. *
  9. * Version: 1.3.1 (05/03/2010)
  10. * Requires: jQuery v1.3+
  11. *
  12. * Dual licensed under the MIT and GPL licenses:
  13. * http://www.opensource.org/licenses/mit-license.php
  14. * http://www.gnu.org/licenses/gpl.html
  15. */
  16. (function($) {
  17. var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,
  18. selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],
  19. ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
  20. loadingTimer, loadingFrame = 1,
  21. start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0,
  22. isIE6 = !$.support.opacity && !window.XMLHttpRequest,
  23. /*
  24. * Private methods
  25. */
  26. fancybox_abort = function() {
  27. loading.hide();
  28. imgPreloader.onerror = imgPreloader.onload = null;
  29. if (ajaxLoader) {
  30. ajaxLoader.abort();
  31. }
  32. tmp.empty();
  33. },
  34. fancybox_error = function() {
  35. $.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
  36. 'scrolling' : 'no',
  37. 'padding' : 20,
  38. 'transitionIn' : 'none',
  39. 'transitionOut' : 'none'
  40. });
  41. },
  42. fancybox_get_viewport = function() {
  43. return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
  44. },
  45. fancybox_get_zoom_to = function () {
  46. var view = fancybox_get_viewport(),
  47. to = {},
  48. margin = currentOpts.margin,
  49. resize = currentOpts.autoScale,
  50. horizontal_space = (shadow + margin) * 2,
  51. vertical_space = (shadow + margin) * 2,
  52. double_padding = (currentOpts.padding * 2),
  53. ratio;
  54. if (currentOpts.width.toString().indexOf('%') > -1) {
  55. to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
  56. resize = false;
  57. } else {
  58. to.width = currentOpts.width + double_padding;
  59. }
  60. if (currentOpts.height.toString().indexOf('%') > -1) {
  61. to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
  62. resize = false;
  63. } else {
  64. to.height = currentOpts.height + double_padding;
  65. }
  66. if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
  67. if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
  68. horizontal_space += double_padding;
  69. vertical_space += double_padding;
  70. ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);
  71. to.width = Math.round(ratio * (to.width - double_padding)) + double_padding;
  72. to.height = Math.round(ratio * (to.height - double_padding)) + double_padding;
  73. } else {
  74. to.width = Math.min(to.width, (view[0] - horizontal_space));
  75. to.height = Math.min(to.height, (view[1] - vertical_space));
  76. }
  77. }
  78. to.top = view[3] + ((view[1] - (to.height + (shadow * 2 ))) * 0.5);
  79. to.left = view[2] + ((view[0] - (to.width + (shadow * 2 ))) * 0.5);
  80. if (currentOpts.autoScale === false) {
  81. to.top = Math.max(view[3] + margin, to.top);
  82. to.left = Math.max(view[2] + margin, to.left);
  83. }
  84. return to;
  85. },
  86. fancybox_format_title = function(title) {
  87. if (title && title.length) {
  88. switch (currentOpts.titlePosition) {
  89. case 'inside':
  90. return title;
  91. case 'over':
  92. return '<span id="fancybox-title-over">' + title + '</span>';
  93. default:
  94. 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>';
  95. }
  96. }
  97. return false;
  98. },
  99. fancybox_process_title = function() {
  100. var title = currentOpts.title,
  101. width = final_pos.width - (currentOpts.padding * 2),
  102. titlec = 'fancybox-title-' + currentOpts.titlePosition;
  103. $('#fancybox-title').remove();
  104. titleh = 0;
  105. if (currentOpts.titleShow === false) {
  106. return;
  107. }
  108. title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);
  109. if (!title || title === '') {
  110. return;
  111. }
  112. $('<div id="fancybox-title" class="' + titlec + '" />').css({
  113. 'width' : width,
  114. 'paddingLeft' : currentOpts.padding,
  115. 'paddingRight' : currentOpts.padding
  116. }).html(title).appendTo('body');
  117. switch (currentOpts.titlePosition) {
  118. case 'inside':
  119. titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
  120. final_pos.height += titleh;
  121. break;
  122. case 'over':
  123. $('#fancybox-title').css('bottom', currentOpts.padding);
  124. break;
  125. default:
  126. $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
  127. break;
  128. }
  129. $('#fancybox-title').appendTo( outer ).hide();
  130. },
  131. fancybox_set_navigation = function() {
  132. $(document).unbind('keydown.fb').bind('keydown.fb', function(e) {
  133. if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
  134. e.preventDefault();
  135. $.fancybox.close();
  136. } else if (e.keyCode == 37) {
  137. e.preventDefault();
  138. $.fancybox.prev();
  139. } else if (e.keyCode == 39) {
  140. e.preventDefault();
  141. $.fancybox.next();
  142. }
  143. });
  144. if ($.fn.mousewheel) {
  145. wrap.unbind('mousewheel.fb');
  146. if (currentArray.length > 1) {
  147. wrap.bind('mousewheel.fb', function(e, delta) {
  148. e.preventDefault();
  149. if (busy || delta === 0) {
  150. return;
  151. }
  152. if (delta > 0) {
  153. $.fancybox.prev();
  154. } else {
  155. $.fancybox.next();
  156. }
  157. });
  158. }
  159. }
  160. if (!currentOpts.showNavArrows) { return; }
  161. if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
  162. nav_left.show();
  163. }
  164. if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
  165. nav_right.show();
  166. }
  167. },
  168. fancybox_preload_images = function() {
  169. var href,
  170. objNext;
  171. if ((currentArray.length -1) > currentIndex) {
  172. href = currentArray[ currentIndex + 1 ].href;
  173. if (typeof href !== 'undefined' && href.match(imgRegExp)) {
  174. objNext = new Image();
  175. objNext.src = href;
  176. }
  177. }
  178. if (currentIndex > 0) {
  179. href = currentArray[ currentIndex - 1 ].href;
  180. if (typeof href !== 'undefined' && href.match(imgRegExp)) {
  181. objNext = new Image();
  182. objNext.src = href;
  183. }
  184. }
  185. },
  186. _finish = function () {
  187. inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));
  188. if (!$.support.opacity) {
  189. inner.get(0).style.removeAttribute('filter');
  190. wrap.get(0).style.removeAttribute('filter');
  191. }
  192. $('#fancybox-title').show();
  193. if (currentOpts.hideOnContentClick) {
  194. inner.one('click', $.fancybox.close);
  195. }
  196. if (currentOpts.hideOnOverlayClick) {
  197. overlay.one('click', $.fancybox.close);
  198. }
  199. if (currentOpts.showCloseButton) {
  200. close.show();
  201. }
  202. fancybox_set_navigation();
  203. $(window).bind("resize.fb", $.fancybox.center);
  204. if (currentOpts.centerOnScroll) {
  205. $(window).bind("scroll.fb", $.fancybox.center);
  206. } else {
  207. $(window).unbind("scroll.fb");
  208. }
  209. if ($.isFunction(currentOpts.onComplete)) {
  210. currentOpts.onComplete(currentArray, currentIndex, currentOpts);
  211. }
  212. busy = false;
  213. fancybox_preload_images();
  214. },
  215. fancybox_draw = function(pos) {
  216. var width = Math.round(start_pos.width + (final_pos.width - start_pos.width) * pos),
  217. height = Math.round(start_pos.height + (final_pos.height - start_pos.height) * pos),
  218. top = Math.round(start_pos.top + (final_pos.top - start_pos.top) * pos),
  219. left = Math.round(start_pos.left + (final_pos.left - start_pos.left) * pos);
  220. wrap.css({
  221. 'width' : width + 'px',
  222. 'height' : height + 'px',
  223. 'top' : top + 'px',
  224. 'left' : left + 'px'
  225. });
  226. width = Math.max(width - currentOpts.padding * 2, 0);
  227. height = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);
  228. inner.css({
  229. 'width' : width + 'px',
  230. 'height' : height + 'px'
  231. });
  232. if (typeof final_pos.opacity !== 'undefined') {
  233. wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
  234. }
  235. },
  236. fancybox_get_obj_pos = function(obj) {
  237. var pos = obj.offset();
  238. pos.top += parseFloat( obj.css('paddingTop') ) || 0;
  239. pos.left += parseFloat( obj.css('paddingLeft') ) || 0;
  240. pos.top += parseFloat( obj.css('border-top-width') ) || 0;
  241. pos.left += parseFloat( obj.css('border-left-width') ) || 0;
  242. pos.width = obj.width();
  243. pos.height = obj.height();
  244. return pos;
  245. },
  246. fancybox_get_zoom_from = function() {
  247. var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
  248. from = {},
  249. pos,
  250. view;
  251. if (orig && orig.length) {
  252. pos = fancybox_get_obj_pos(orig);
  253. from = {
  254. width : (pos.width + (currentOpts.padding * 2)),
  255. height : (pos.height + (currentOpts.padding * 2)),
  256. top : (pos.top - currentOpts.padding - shadow),
  257. left : (pos.left - currentOpts.padding - shadow)
  258. };
  259. } else {
  260. view = fancybox_get_viewport();
  261. from = {
  262. width : 1,
  263. height : 1,
  264. top : view[3] + view[1] * 0.5,
  265. left : view[2] + view[0] * 0.5
  266. };
  267. }
  268. return from;
  269. },
  270. fancybox_show = function() {
  271. loading.hide();
  272. if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
  273. if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
  274. $.event.trigger('fancybox-cancel');
  275. busy = false;
  276. return;
  277. }
  278. }
  279. currentArray = selectedArray;
  280. currentIndex = selectedIndex;
  281. currentOpts = selectedOpts;
  282. inner.get(0).scrollTop = 0;
  283. inner.get(0).scrollLeft = 0;
  284. if (currentOpts.overlayShow) {
  285. if (isIE6) {
  286. $('select:not(#fancybox-tmp select)').filter(function() {
  287. return this.style.visibility !== 'hidden';
  288. }).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {
  289. this.style.visibility = 'inherit';
  290. });
  291. }
  292. overlay.css({
  293. 'background-color' : currentOpts.overlayColor,
  294. 'opacity' : currentOpts.overlayOpacity
  295. }).unbind().show();
  296. }
  297. final_pos = fancybox_get_zoom_to();
  298. fancybox_process_title();
  299. if (wrap.is(":visible")) {
  300. $( close.add( nav_left ).add( nav_right ) ).hide();
  301. var pos = wrap.position(),
  302. equal;
  303. start_pos = {
  304. top : pos.top ,
  305. left : pos.left,
  306. width : wrap.width(),
  307. height : wrap.height()
  308. };
  309. equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);
  310. inner.fadeOut(currentOpts.changeFade, function() {
  311. var finish_resizing = function() {
  312. inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
  313. };
  314. $.event.trigger('fancybox-change');
  315. inner.empty().css('overflow', 'hidden');
  316. if (equal) {
  317. inner.css({
  318. top : currentOpts.padding,
  319. left : currentOpts.padding,
  320. width : Math.max(final_pos.width - (currentOpts.padding * 2), 1),
  321. height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1)
  322. });
  323. finish_resizing();
  324. } else {
  325. inner.css({
  326. top : currentOpts.padding,
  327. left : currentOpts.padding,
  328. width : Math.max(start_pos.width - (currentOpts.padding * 2), 1),
  329. height : Math.max(start_pos.height - (currentOpts.padding * 2), 1)
  330. });
  331. fx.prop = 0;
  332. $(fx).animate({ prop: 1 }, {
  333. duration : currentOpts.changeSpeed,
  334. easing : currentOpts.easingChange,
  335. step : fancybox_draw,
  336. complete : finish_resizing
  337. });
  338. }
  339. });
  340. return;
  341. }
  342. wrap.css('opacity', 1);
  343. if (currentOpts.transitionIn == 'elastic') {
  344. start_pos = fancybox_get_zoom_from();
  345. inner.css({
  346. top : currentOpts.padding,
  347. left : currentOpts.padding,
  348. width : Math.max(start_pos.width - (currentOpts.padding * 2), 1),
  349. height : Math.max(start_pos.height - (currentOpts.padding * 2), 1)
  350. })
  351. .html( tmp.contents() );
  352. wrap.css(start_pos).show();
  353. if (currentOpts.opacity) {
  354. final_pos.opacity = 0;
  355. }
  356. fx.prop = 0;
  357. $(fx).animate({ prop: 1 }, {
  358. duration : currentOpts.speedIn,
  359. easing : currentOpts.easingIn,
  360. step : fancybox_draw,
  361. complete : _finish
  362. });
  363. } else {
  364. inner.css({
  365. top : currentOpts.padding,
  366. left : currentOpts.padding,
  367. width : Math.max(final_pos.width - (currentOpts.padding * 2), 1),
  368. height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1)
  369. })
  370. .html( tmp.contents() );
  371. wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
  372. }
  373. },
  374. fancybox_process_inline = function() {
  375. tmp.width( selectedOpts.width );
  376. tmp.height( selectedOpts.height );
  377. if (selectedOpts.width == 'auto') {
  378. selectedOpts.width = tmp.width();
  379. }
  380. if (selectedOpts.height == 'auto') {
  381. selectedOpts.height = tmp.height();
  382. }
  383. fancybox_show();
  384. },
  385. fancybox_process_image = function() {
  386. busy = true;
  387. selectedOpts.width = imgPreloader.width;
  388. selectedOpts.height = imgPreloader.height;
  389. $("<img />").attr({
  390. 'id' : 'fancybox-img',
  391. 'src' : imgPreloader.src,
  392. 'alt' : selectedOpts.title
  393. }).appendTo( tmp );
  394. fancybox_show();
  395. },
  396. fancybox_start = function() {
  397. fancybox_abort();
  398. var obj = selectedArray[ selectedIndex ],
  399. href,
  400. type,
  401. title,
  402. str,
  403. emb,
  404. selector,
  405. data;
  406. selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
  407. title = obj.title || $(obj).title || selectedOpts.title || '';
  408. if (obj.nodeName && !selectedOpts.orig) {
  409. selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
  410. }
  411. if (title === '' && selectedOpts.orig) {
  412. title = selectedOpts.orig.attr('alt');
  413. }
  414. if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
  415. href = selectedOpts.href || null;
  416. } else {
  417. href = selectedOpts.href || obj.href || null;
  418. }
  419. if (selectedOpts.type) {
  420. type = selectedOpts.type;
  421. if (!href) {
  422. href = selectedOpts.content;
  423. }
  424. } else if (selectedOpts.content) {
  425. type = 'html';
  426. } else if (href) {
  427. if (href.match(imgRegExp)) {
  428. type = 'image';
  429. } else if (href.match(swfRegExp)) {
  430. type = 'swf';
  431. } else if ($(obj).hasClass("iframe")) {
  432. type = 'iframe';
  433. } else if (href.match(/#/)) {
  434. obj = href.substr(href.indexOf("#"));
  435. type = $(obj).length > 0 ? 'inline' : 'ajax';
  436. } else {
  437. type = 'ajax';
  438. }
  439. } else {
  440. type = 'inline';
  441. }
  442. selectedOpts.type = type;
  443. selectedOpts.href = href;
  444. selectedOpts.title = title;
  445. if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
  446. selectedOpts.width = 'auto';
  447. selectedOpts.height = 'auto';
  448. }
  449. if (selectedOpts.modal) {
  450. selectedOpts.overlayShow = true;
  451. selectedOpts.hideOnOverlayClick = false;
  452. selectedOpts.hideOnContentClick = false;
  453. selectedOpts.enableEscapeButton = false;
  454. selectedOpts.showCloseButton = false;
  455. }
  456. if ($.isFunction(selectedOpts.onStart)) {
  457. if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
  458. busy = false;
  459. return;
  460. }
  461. }
  462. tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));
  463. $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
  464. $(this).replaceWith(inner.children());
  465. });
  466. switch (type) {
  467. case 'html' :
  468. tmp.html( selectedOpts.content );
  469. fancybox_process_inline();
  470. break;
  471. case 'inline' :
  472. $('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
  473. $(this).replaceWith(inner.children());
  474. }).bind('fancybox-cancel', function() {
  475. $(this).replaceWith(tmp.children());
  476. });
  477. $(obj).appendTo(tmp);
  478. fancybox_process_inline();
  479. break;
  480. case 'image':
  481. busy = false;
  482. $.fancybox.showActivity();
  483. imgPreloader = new Image();
  484. imgPreloader.onerror = function() {
  485. fancybox_error();
  486. };
  487. imgPreloader.onload = function() {
  488. imgPreloader.onerror = null;
  489. imgPreloader.onload = null;
  490. fancybox_process_image();
  491. };
  492. imgPreloader.src = href;
  493. break;
  494. case 'swf':
  495. str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
  496. emb = '';
  497. $.each(selectedOpts.swf, function(name, val) {
  498. str += '<param name="' + name + '" value="' + val + '"></param>';
  499. emb += ' ' + name + '="' + val + '"';
  500. });
  501. str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';
  502. tmp.html(str);
  503. fancybox_process_inline();
  504. break;
  505. case 'ajax':
  506. selector = href.split('#', 2);
  507. data = selectedOpts.ajax.data || {};
  508. if (selector.length > 1) {
  509. href = selector[0];
  510. if (typeof data == "string") {
  511. data += '&selector=' + selector[1];
  512. } else {
  513. data.selector = selector[1];
  514. }
  515. }
  516. busy = false;
  517. $.fancybox.showActivity();
  518. ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
  519. url : href,
  520. data : data,
  521. error : fancybox_error,
  522. success : function(data, textStatus, XMLHttpRequest) {
  523. if (ajaxLoader.status == 200) {
  524. tmp.html( data );
  525. fancybox_process_inline();
  526. }
  527. }
  528. }));
  529. break;
  530. case 'iframe' :
  531. $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
  532. fancybox_show();
  533. break;
  534. }
  535. },
  536. fancybox_animate_loading = function() {
  537. if (!loading.is(':visible')){
  538. clearInterval(loadingTimer);
  539. return;
  540. }
  541. $('div', loading).css('top', (loadingFrame * -40) + 'px');
  542. loadingFrame = (loadingFrame + 1) % 12;
  543. },
  544. fancybox_init = function() {
  545. if ($("#fancybox-wrap").length) {
  546. return;
  547. }
  548. $('body').append(
  549. tmp = $('<div id="fancybox-tmp"></div>'),
  550. loading = $('<div id="fancybox-loading"><div></div></div>'),
  551. overlay = $('<div id="fancybox-overlay"></div>'),
  552. wrap = $('<div id="fancybox-wrap"></div>')
  553. );
  554. if (!$.support.opacity) {
  555. wrap.addClass('fancybox-ie');
  556. loading.addClass('fancybox-ie');
  557. }
  558. outer = $('<div id="fancybox-outer"></div>')
  559. .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>')
  560. .appendTo( wrap );
  561. outer.append(
  562. inner = $('<div id="fancybox-inner"></div>'),
  563. close = $('<a id="fancybox-close"></a>'),
  564. nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
  565. nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
  566. );
  567. close.click($.fancybox.close);
  568. loading.click($.fancybox.cancel);
  569. nav_left.click(function(e) {
  570. e.preventDefault();
  571. $.fancybox.prev();
  572. });
  573. nav_right.click(function(e) {
  574. e.preventDefault();
  575. $.fancybox.next();
  576. });
  577. if (isIE6) {
  578. overlay.get(0).style.setExpression('height', "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
  579. 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'");
  580. outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
  581. }
  582. };
  583. /*
  584. * Public methods
  585. */
  586. $.fn.fancybox = function(options) {
  587. $(this)
  588. .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
  589. .unbind('click.fb').bind('click.fb', function(e) {
  590. e.preventDefault();
  591. if (busy) {
  592. return;
  593. }
  594. busy = true;
  595. $(this).blur();
  596. selectedArray = [];
  597. selectedIndex = 0;
  598. var rel = $(this).attr('rel') || '';
  599. if (!rel || rel == '' || rel === 'nofollow') {
  600. selectedArray.push(this);
  601. } else {
  602. selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
  603. selectedIndex = selectedArray.index( this );
  604. }
  605. fancybox_start();
  606. return false;
  607. });
  608. return this;
  609. };
  610. $.fancybox = function(obj) {
  611. if (busy) {
  612. return;
  613. }
  614. busy = true;
  615. var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};
  616. selectedArray = [];
  617. selectedIndex = opts.index || 0;
  618. if ($.isArray(obj)) {
  619. for (var i = 0, j = obj.length; i < j; i++) {
  620. if (typeof obj[i] == 'object') {
  621. $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
  622. } else {
  623. obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
  624. }
  625. }
  626. selectedArray = jQuery.merge(selectedArray, obj);
  627. } else {
  628. if (typeof obj == 'object') {
  629. $(obj).data('fancybox', $.extend({}, opts, obj));
  630. } else {
  631. obj = $({}).data('fancybox', $.extend({content : obj}, opts));
  632. }
  633. selectedArray.push(obj);
  634. }
  635. if (selectedIndex > selectedArray.length || selectedIndex < 0) {
  636. selectedIndex = 0;
  637. }
  638. fancybox_start();
  639. };
  640. $.fancybox.showActivity = function() {
  641. clearInterval(loadingTimer);
  642. loading.show();
  643. loadingTimer = setInterval(fancybox_animate_loading, 66);
  644. };
  645. $.fancybox.hideActivity = function() {
  646. loading.hide();
  647. };
  648. $.fancybox.next = function() {
  649. return $.fancybox.pos( currentIndex + 1);
  650. };
  651. $.fancybox.prev = function() {
  652. return $.fancybox.pos( currentIndex - 1);
  653. };
  654. $.fancybox.pos = function(pos) {
  655. if (busy) {
  656. return;
  657. }
  658. pos = parseInt(pos, 10);
  659. if (pos > -1 && currentArray.length > pos) {
  660. selectedIndex = pos;
  661. fancybox_start();
  662. }
  663. if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
  664. selectedIndex = currentArray.length - 1;
  665. fancybox_start();
  666. }
  667. if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
  668. selectedIndex = 0;
  669. fancybox_start();
  670. }
  671. return;
  672. };
  673. $.fancybox.cancel = function() {
  674. if (busy) {
  675. return;
  676. }
  677. busy = true;
  678. $.event.trigger('fancybox-cancel');
  679. fancybox_abort();
  680. if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
  681. selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
  682. }
  683. busy = false;
  684. };
  685. // Note: within an iframe use - parent.$.fancybox.close();
  686. $.fancybox.close = function() {
  687. if (busy || wrap.is(':hidden')) {
  688. return;
  689. }
  690. busy = true;
  691. if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
  692. if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
  693. busy = false;
  694. return;
  695. }
  696. }
  697. fancybox_abort();
  698. $(close.add( nav_left ).add( nav_right )).hide();
  699. $('#fancybox-title').remove();
  700. wrap.add(inner).add(overlay).unbind();
  701. $(window).unbind("resize.fb scroll.fb");
  702. $(document).unbind('keydown.fb');
  703. function _cleanup() {
  704. overlay.fadeOut('fast');
  705. wrap.hide();
  706. $.event.trigger('fancybox-cleanup');
  707. inner.empty();
  708. if ($.isFunction(currentOpts.onClosed)) {
  709. currentOpts.onClosed(currentArray, currentIndex, currentOpts);
  710. }
  711. currentArray = selectedOpts = [];
  712. currentIndex = selectedIndex = 0;
  713. currentOpts = selectedOpts = {};
  714. busy = false;
  715. }
  716. inner.css('overflow', 'hidden');
  717. if (currentOpts.transitionOut == 'elastic') {
  718. start_pos = fancybox_get_zoom_from();
  719. var pos = wrap.position();
  720. final_pos = {
  721. top : pos.top ,
  722. left : pos.left,
  723. width : wrap.width(),
  724. height : wrap.height()
  725. };
  726. if (currentOpts.opacity) {
  727. final_pos.opacity = 1;
  728. }
  729. fx.prop = 1;
  730. $(fx).animate({ prop: 0 }, {
  731. duration : currentOpts.speedOut,
  732. easing : currentOpts.easingOut,
  733. step : fancybox_draw,
  734. complete : _cleanup
  735. });
  736. } else {
  737. wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
  738. }
  739. };
  740. $.fancybox.resize = function() {
  741. var c, h;
  742. if (busy || wrap.is(':hidden')) {
  743. return;
  744. }
  745. busy = true;
  746. c = inner.wrapInner("<div style='overflow:auto'></div>").children();
  747. h = c.height();
  748. wrap.css({height: h + (currentOpts.padding * 2) + titleh});
  749. inner.css({height: h});
  750. c.replaceWith(c.children());
  751. $.fancybox.center();
  752. };
  753. $.fancybox.center = function() {
  754. busy = true;
  755. var view = fancybox_get_viewport(),
  756. margin = currentOpts.margin,
  757. to = {};
  758. to.top = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
  759. to.left = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);
  760. to.top = Math.max(view[3] + margin, to.top);
  761. to.left = Math.max(view[2] + margin, to.left);
  762. wrap.css(to);
  763. busy = false;
  764. };
  765. $.fn.fancybox.defaults = {
  766. padding : 10,
  767. margin : 20,
  768. opacity : false,
  769. modal : false,
  770. cyclic : false,
  771. scrolling : 'auto', // 'auto', 'yes' or 'no'
  772. width : 560,
  773. height : 340,
  774. autoScale : true,
  775. autoDimensions : true,
  776. centerOnScroll : false,
  777. ajax : {},
  778. swf : { wmode: 'transparent' },
  779. hideOnOverlayClick : true,
  780. hideOnContentClick : false,
  781. overlayShow : true,
  782. overlayOpacity : 0.3,
  783. overlayColor : '#666',
  784. titleShow : true,
  785. titlePosition : 'outside', // 'outside', 'inside' or 'over'
  786. titleFormat : null,
  787. transitionIn : 'fade', // 'elastic', 'fade' or 'none'
  788. transitionOut : 'fade', // 'elastic', 'fade' or 'none'
  789. speedIn : 300,
  790. speedOut : 300,
  791. changeSpeed : 300,
  792. changeFade : 'fast',
  793. easingIn : 'swing',
  794. easingOut : 'swing',
  795. showCloseButton : true,
  796. showNavArrows : true,
  797. enableEscapeButton : true,
  798. onStart : null,
  799. onCancel : null,
  800. onComplete : null,
  801. onCleanup : null,
  802. onClosed : null
  803. };
  804. $(document).ready(function() {
  805. fancybox_init();
  806. });
  807. })(jQuery);