lightbox.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. /* $Id: lightbox.js,v 1.5.2.6.2.136 2010/09/24 08:39:40 snpower Exp $ */
  2. /**
  3. * jQuery Lightbox
  4. * @author
  5. * Stella Power, <http://drupal.org/user/66894>
  6. *
  7. * Based on Lightbox v2.03.3 by Lokesh Dhakar
  8. * <http://www.huddletogether.com/projects/lightbox2/>
  9. * Also partially based on the jQuery Lightbox by Warren Krewenki
  10. * <http://warren.mesozen.com>
  11. *
  12. * Permission has been granted to Mark Ashmead & other Drupal Lightbox2 module
  13. * maintainers to distribute this file via Drupal.org
  14. * Under GPL license.
  15. *
  16. * Slideshow, iframe and video functionality added by Stella Power.
  17. */
  18. var Lightbox;
  19. (function($) {
  20. Lightbox = {
  21. auto_modal : false,
  22. overlayOpacity : 0.8, // Controls transparency of shadow overlay.
  23. overlayColor : '000', // Controls colour of shadow overlay.
  24. disableCloseClick : true,
  25. // Controls the order of the lightbox resizing animation sequence.
  26. resizeSequence: 0, // 0: simultaneous, 1: width then height, 2: height then width.
  27. resizeSpeed: 'normal', // Controls the speed of the lightbox resizing animation.
  28. fadeInSpeed: 'normal', // Controls the speed of the image appearance.
  29. slideDownSpeed: 'slow', // Controls the speed of the image details appearance.
  30. minWidth: 240,
  31. borderSize : 10,
  32. boxColor : 'fff',
  33. fontColor : '000',
  34. topPosition : '',
  35. infoHeight: 20,
  36. alternative_layout : false,
  37. imageArray : [],
  38. imageNum : null,
  39. total : 0,
  40. activeImage : null,
  41. inprogress : false,
  42. disableResize : false,
  43. disableZoom : false,
  44. isZoomedIn : false,
  45. rtl : false,
  46. loopItems : false,
  47. keysClose : ['c', 'x', 27],
  48. keysPrevious : ['p', 37],
  49. keysNext : ['n', 39],
  50. keysZoom : ['z'],
  51. keysPlayPause : [32],
  52. // Slideshow options.
  53. slideInterval : 5000, // In milliseconds.
  54. showPlayPause : true,
  55. autoStart : true,
  56. autoExit : true,
  57. pauseOnNextClick : false, // True to pause the slideshow when the "Next" button is clicked.
  58. pauseOnPrevClick : true, // True to pause the slideshow when the "Prev" button is clicked.
  59. slideIdArray : [],
  60. slideIdCount : 0,
  61. isSlideshow : false,
  62. isPaused : false,
  63. loopSlides : false,
  64. // Iframe options.
  65. isLightframe : false,
  66. iframe_width : 600,
  67. iframe_height : 400,
  68. iframe_border : 1,
  69. // Video and modal options.
  70. enableVideo : false,
  71. flvPlayer : '/flvplayer.swf',
  72. flvFlashvars : '',
  73. isModal : false,
  74. isVideo : false,
  75. videoId : false,
  76. modalWidth : 400,
  77. modalHeight : 400,
  78. modalHTML : null,
  79. // initialize()
  80. // Constructor runs on completion of the DOM loading.
  81. // The function inserts html at the bottom of the page which is used
  82. // to display the shadow overlay and the image container.
  83. initialize: function() {
  84. var s = Drupal.settings.lightbox2;
  85. Lightbox.overlayOpacity = s.overlay_opacity;
  86. Lightbox.overlayColor = s.overlay_color;
  87. Lightbox.disableCloseClick = s.disable_close_click;
  88. Lightbox.resizeSequence = s.resize_sequence;
  89. Lightbox.resizeSpeed = s.resize_speed;
  90. Lightbox.fadeInSpeed = s.fade_in_speed;
  91. Lightbox.slideDownSpeed = s.slide_down_speed;
  92. Lightbox.borderSize = s.border_size;
  93. Lightbox.boxColor = s.box_color;
  94. Lightbox.fontColor = s.font_color;
  95. Lightbox.topPosition = s.top_position;
  96. Lightbox.rtl = s.rtl;
  97. Lightbox.loopItems = s.loop_items;
  98. Lightbox.keysClose = s.keys_close.split(" ");
  99. Lightbox.keysPrevious = s.keys_previous.split(" ");
  100. Lightbox.keysNext = s.keys_next.split(" ");
  101. Lightbox.keysZoom = s.keys_zoom.split(" ");
  102. Lightbox.keysPlayPause = s.keys_play_pause.split(" ");
  103. Lightbox.disableResize = s.disable_resize;
  104. Lightbox.disableZoom = s.disable_zoom;
  105. Lightbox.slideInterval = s.slideshow_interval;
  106. Lightbox.showPlayPause = s.show_play_pause;
  107. Lightbox.showCaption = s.show_caption;
  108. Lightbox.autoStart = s.slideshow_automatic_start;
  109. Lightbox.autoExit = s.slideshow_automatic_exit;
  110. Lightbox.pauseOnNextClick = s.pause_on_next_click;
  111. Lightbox.pauseOnPrevClick = s.pause_on_previous_click;
  112. Lightbox.loopSlides = s.loop_slides;
  113. Lightbox.alternative_layout = s.use_alt_layout;
  114. Lightbox.iframe_width = s.iframe_width;
  115. Lightbox.iframe_height = s.iframe_height;
  116. Lightbox.iframe_border = s.iframe_border;
  117. Lightbox.enableVideo = s.enable_video;
  118. if (s.enable_video) {
  119. Lightbox.flvPlayer = s.flvPlayer;
  120. Lightbox.flvFlashvars = s.flvFlashvars;
  121. }
  122. // Make the lightbox divs.
  123. var layout_class = (s.use_alt_layout ? 'lightbox2-alt-layout' : 'lightbox2-orig-layout');
  124. var output = '<div id="lightbox2-overlay" style="display: none;"></div>\
  125. <div id="lightbox" style="display: none;" class="' + layout_class + '">\
  126. <div id="outerImageContainer"></div>\
  127. <div id="imageDataContainer" class="clearfix">\
  128. <div id="imageData"></div>\
  129. </div>\
  130. </div>';
  131. var loading = '<div id="loading"><a href="#" id="loadingLink"></a></div>';
  132. var modal = '<div id="modalContainer" style="display: none;"></div>';
  133. var frame = '<div id="frameContainer" style="display: none;"></div>';
  134. var imageContainer = '<div id="imageContainer" style="display: none;"></div>';
  135. var details = '<div id="imageDetails"></div>';
  136. var bottomNav = '<div id="bottomNav"></div>';
  137. var image = '<img id="lightboxImage" alt="" />';
  138. var hoverNav = '<div id="hoverNav"><a id="prevLink" href="#"></a><a id="nextLink" href="#"></a></div>';
  139. var frameNav = '<div id="frameHoverNav"><a id="framePrevLink" href="#"></a><a id="frameNextLink" href="#"></a></div>';
  140. var hoverNav = '<div id="hoverNav"><a id="prevLink" title="' + Drupal.t('Previous') + '" href="#"></a><a id="nextLink" title="' + Drupal.t('Next') + '" href="#"></a></div>';
  141. var frameNav = '<div id="frameHoverNav"><a id="framePrevLink" title="' + Drupal.t('Previous') + '" href="#"></a><a id="frameNextLink" title="' + Drupal.t('Next') + '" href="#"></a></div>';
  142. var caption = '<span id="caption"></span>';
  143. var numberDisplay = '<span id="numberDisplay"></span>';
  144. var close = '<a id="bottomNavClose" title="' + Drupal.t('Close') + '" href="#"></a>';
  145. var zoom = '<a id="bottomNavZoom" href="#"></a>';
  146. var zoomOut = '<a id="bottomNavZoomOut" href="#"></a>';
  147. var pause = '<a id="lightshowPause" title="' + Drupal.t('Pause Slideshow') + '" href="#" style="display: none;"></a>';
  148. var play = '<a id="lightshowPlay" title="' + Drupal.t('Play Slideshow') + '" href="#" style="display: none;"></a>';
  149. $("body").append(output);
  150. $('#outerImageContainer').append(modal + frame + imageContainer + loading);
  151. if (!s.use_alt_layout) {
  152. $('#imageContainer').append(image + hoverNav);
  153. $('#imageData').append(details + bottomNav);
  154. $('#imageDetails').append(caption + numberDisplay);
  155. $('#bottomNav').append(frameNav + close + zoom + zoomOut + pause + play);
  156. }
  157. else {
  158. $('#outerImageContainer').append(bottomNav);
  159. $('#imageContainer').append(image);
  160. $('#bottomNav').append(close + zoom + zoomOut);
  161. $('#imageData').append(hoverNav + details);
  162. $('#imageDetails').append(caption + numberDisplay + pause + play);
  163. }
  164. // Setup onclick handlers.
  165. if (Lightbox.disableCloseClick) {
  166. $('#lightbox2-overlay').click(function() { Lightbox.end(); return false; } ).hide();
  167. }
  168. $('#loadingLink, #bottomNavClose').click(function() { Lightbox.end('forceClose'); return false; } );
  169. $('#prevLink, #framePrevLink').click(function() { Lightbox.changeData(Lightbox.activeImage - 1); return false; } );
  170. $('#nextLink, #frameNextLink').click(function() { Lightbox.changeData(Lightbox.activeImage + 1); return false; } );
  171. $('#bottomNavZoom').click(function() { Lightbox.changeData(Lightbox.activeImage, true); return false; } );
  172. $('#bottomNavZoomOut').click(function() { Lightbox.changeData(Lightbox.activeImage, false); return false; } );
  173. $('#lightshowPause').click(function() { Lightbox.togglePlayPause("lightshowPause", "lightshowPlay"); return false; } );
  174. $('#lightshowPlay').click(function() { Lightbox.togglePlayPause("lightshowPlay", "lightshowPause"); return false; } );
  175. // Fix positioning.
  176. $('#prevLink, #nextLink, #framePrevLink, #frameNextLink').css({ 'paddingTop': Lightbox.borderSize + 'px'});
  177. $('#imageContainer, #frameContainer, #modalContainer').css({ 'padding': Lightbox.borderSize + 'px'});
  178. $('#outerImageContainer, #imageDataContainer, #bottomNavClose').css({'backgroundColor': '#' + Lightbox.boxColor, 'color': '#'+Lightbox.fontColor});
  179. if (Lightbox.alternative_layout) {
  180. $('#bottomNavZoom, #bottomNavZoomOut').css({'bottom': Lightbox.borderSize + 'px', 'right': Lightbox.borderSize + 'px'});
  181. }
  182. else if (Lightbox.rtl == 1 && $.browser.msie) {
  183. $('#bottomNavZoom, #bottomNavZoomOut').css({'left': '0px'});
  184. }
  185. // Force navigation links to always be displayed
  186. if (s.force_show_nav) {
  187. $('#prevLink, #nextLink').addClass("force_show_nav");
  188. }
  189. },
  190. // initList()
  191. // Loops through anchor tags looking for 'lightbox', 'lightshow' and
  192. // 'lightframe', etc, references and applies onclick events to appropriate
  193. // links. You can rerun after dynamically adding images w/ajax.
  194. initList : function(context) {
  195. if (context == undefined || context == null) {
  196. context = document;
  197. }
  198. // Attach lightbox to any links with rel 'lightbox', 'lightshow' or
  199. // 'lightframe', etc.
  200. $("a[rel^='lightbox']:not(.lightbox-processed), area[rel^='lightbox']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  201. if (Lightbox.disableCloseClick) {
  202. $('#lightbox').unbind('click');
  203. $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
  204. }
  205. Lightbox.start(this, false, false, false, false);
  206. if (e.preventDefault) { e.preventDefault(); }
  207. return false;
  208. });
  209. $("a[rel^='lightshow']:not(.lightbox-processed), area[rel^='lightshow']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  210. if (Lightbox.disableCloseClick) {
  211. $('#lightbox').unbind('click');
  212. $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
  213. }
  214. Lightbox.start(this, true, false, false, false);
  215. if (e.preventDefault) { e.preventDefault(); }
  216. return false;
  217. });
  218. $("a[rel^='lightframe']:not(.lightbox-processed), area[rel^='lightframe']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  219. if (Lightbox.disableCloseClick) {
  220. $('#lightbox').unbind('click');
  221. $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
  222. }
  223. Lightbox.start(this, false, true, false, false);
  224. if (e.preventDefault) { e.preventDefault(); }
  225. return false;
  226. });
  227. if (Lightbox.enableVideo) {
  228. $("a[rel^='lightvideo']:not(.lightbox-processed), area[rel^='lightvideo']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  229. if (Lightbox.disableCloseClick) {
  230. $('#lightbox').unbind('click');
  231. $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
  232. }
  233. Lightbox.start(this, false, false, true, false);
  234. if (e.preventDefault) { e.preventDefault(); }
  235. return false;
  236. });
  237. }
  238. $("a[rel^='lightmodal']:not(.lightbox-processed), area[rel^='lightmodal']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  239. $('#lightbox').unbind('click');
  240. // Add classes from the link to the lightbox div - don't include lightbox-processed
  241. $('#lightbox').addClass($(this).attr('class'));
  242. $('#lightbox').removeClass('lightbox-processed');
  243. Lightbox.start(this, false, false, false, true);
  244. if (e.preventDefault) { e.preventDefault(); }
  245. return false;
  246. });
  247. $("#lightboxAutoModal:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
  248. Lightbox.auto_modal = true;
  249. $('#lightbox').unbind('click');
  250. Lightbox.start(this, false, false, false, true);
  251. if (e.preventDefault) { e.preventDefault(); }
  252. return false;
  253. });
  254. },
  255. // start()
  256. // Display overlay and lightbox. If image is part of a set, add siblings to
  257. // imageArray.
  258. start: function(imageLink, slideshow, lightframe, lightvideo, lightmodal) {
  259. Lightbox.isPaused = !Lightbox.autoStart;
  260. // Replaces hideSelectBoxes() and hideFlash() calls in original lightbox2.
  261. Lightbox.toggleSelectsFlash('hide');
  262. // Stretch overlay to fill page and fade in.
  263. var arrayPageSize = Lightbox.getPageSize();
  264. $("#lightbox2-overlay").hide().css({
  265. 'width': '100%',
  266. 'zIndex': '10090',
  267. 'height': arrayPageSize[1] + 'px',
  268. 'backgroundColor' : '#' + Lightbox.overlayColor
  269. });
  270. // Detect OS X FF2 opacity + flash issue.
  271. if (lightvideo && this.detectMacFF2()) {
  272. $("#lightbox2-overlay").removeClass("overlay_default");
  273. $("#lightbox2-overlay").addClass("overlay_macff2");
  274. $("#lightbox2-overlay").css({'opacity' : null});
  275. }
  276. else {
  277. $("#lightbox2-overlay").removeClass("overlay_macff2");
  278. $("#lightbox2-overlay").addClass("overlay_default");
  279. $("#lightbox2-overlay").css({'opacity' : Lightbox.overlayOpacity});
  280. }
  281. $("#lightbox2-overlay").fadeIn(Lightbox.fadeInSpeed);
  282. Lightbox.isSlideshow = slideshow;
  283. Lightbox.isLightframe = lightframe;
  284. Lightbox.isVideo = lightvideo;
  285. Lightbox.isModal = lightmodal;
  286. Lightbox.imageArray = [];
  287. Lightbox.imageNum = 0;
  288. var anchors = $(imageLink.tagName);
  289. var anchor = null;
  290. var rel_parts = Lightbox.parseRel(imageLink);
  291. var rel = rel_parts["rel"];
  292. var rel_group = rel_parts["group"];
  293. var title = (rel_parts["title"] ? rel_parts["title"] : imageLink.title);
  294. var rel_style = null;
  295. var i = 0;
  296. if (rel_parts["flashvars"]) {
  297. Lightbox.flvFlashvars = Lightbox.flvFlashvars + '&' + rel_parts["flashvars"];
  298. }
  299. // Set the title for image alternative text.
  300. var alt = imageLink.title;
  301. if (!alt) {
  302. var img = $(imageLink).find("img");
  303. if (img && $(img).attr("alt")) {
  304. alt = $(img).attr("alt");
  305. }
  306. else {
  307. alt = title;
  308. }
  309. }
  310. if ($(imageLink).attr('id') == 'lightboxAutoModal') {
  311. rel_style = rel_parts["style"];
  312. Lightbox.imageArray.push(['#lightboxAutoModal > *', title, alt, rel_style, 1]);
  313. }
  314. else {
  315. // Handle lightbox images with no grouping.
  316. if ((rel == 'lightbox' || rel == 'lightshow') && !rel_group) {
  317. Lightbox.imageArray.push([imageLink.href, title, alt]);
  318. }
  319. // Handle other items with no grouping.
  320. else if (!rel_group) {
  321. rel_style = rel_parts["style"];
  322. Lightbox.imageArray.push([imageLink.href, title, alt, rel_style]);
  323. }
  324. // Handle grouped items.
  325. else {
  326. // Loop through anchors and add them to imageArray.
  327. for (i = 0; i < anchors.length; i++) {
  328. anchor = anchors[i];
  329. if (anchor.href && typeof(anchor.href) == "string" && $(anchor).attr('rel')) {
  330. var rel_data = Lightbox.parseRel(anchor);
  331. var anchor_title = (rel_data["title"] ? rel_data["title"] : anchor.title);
  332. img_alt = anchor.title;
  333. if (!img_alt) {
  334. var anchor_img = $(anchor).find("img");
  335. if (anchor_img && $(anchor_img).attr("alt")) {
  336. img_alt = $(anchor_img).attr("alt");
  337. }
  338. else {
  339. img_alt = title;
  340. }
  341. }
  342. if (rel_data["rel"] == rel) {
  343. if (rel_data["group"] == rel_group) {
  344. if (Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) {
  345. rel_style = rel_data["style"];
  346. }
  347. Lightbox.imageArray.push([anchor.href, anchor_title, img_alt, rel_style]);
  348. }
  349. }
  350. }
  351. }
  352. // Remove duplicates.
  353. for (i = 0; i < Lightbox.imageArray.length; i++) {
  354. for (j = Lightbox.imageArray.length-1; j > i; j--) {
  355. if (Lightbox.imageArray[i][0] == Lightbox.imageArray[j][0]) {
  356. Lightbox.imageArray.splice(j,1);
  357. }
  358. }
  359. }
  360. while (Lightbox.imageArray[Lightbox.imageNum][0] != imageLink.href) {
  361. Lightbox.imageNum++;
  362. }
  363. }
  364. }
  365. if (Lightbox.isSlideshow && Lightbox.showPlayPause && Lightbox.isPaused) {
  366. $('#lightshowPlay').show();
  367. $('#lightshowPause').hide();
  368. }
  369. // Calculate top and left offset for the lightbox.
  370. var arrayPageScroll = Lightbox.getPageScroll();
  371. var lightboxTop = arrayPageScroll[1] + (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
  372. var lightboxLeft = arrayPageScroll[0];
  373. $('#frameContainer, #modalContainer, #lightboxImage').hide();
  374. $('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
  375. $('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
  376. $('#outerImageContainer').css({'width': '250px', 'height': '250px'});
  377. $('#lightbox').css({
  378. 'zIndex': '10500',
  379. 'top': lightboxTop + 'px',
  380. 'left': lightboxLeft + 'px'
  381. }).show();
  382. Lightbox.total = Lightbox.imageArray.length;
  383. Lightbox.changeData(Lightbox.imageNum);
  384. },
  385. // changeData()
  386. // Hide most elements and preload image in preparation for resizing image
  387. // container.
  388. changeData: function(imageNum, zoomIn) {
  389. if (Lightbox.inprogress === false) {
  390. if (Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) {
  391. if (imageNum >= Lightbox.total) imageNum = 0;
  392. if (imageNum < 0) imageNum = Lightbox.total - 1;
  393. }
  394. if (Lightbox.isSlideshow) {
  395. for (var i = 0; i < Lightbox.slideIdCount; i++) {
  396. window.clearTimeout(Lightbox.slideIdArray[i]);
  397. }
  398. }
  399. Lightbox.inprogress = true;
  400. Lightbox.activeImage = imageNum;
  401. if (Lightbox.disableResize && !Lightbox.isSlideshow) {
  402. zoomIn = true;
  403. }
  404. Lightbox.isZoomedIn = zoomIn;
  405. // Hide elements during transition.
  406. $('#loading').css({'zIndex': '10500'}).show();
  407. if (!Lightbox.alternative_layout) {
  408. $('#imageContainer').hide();
  409. }
  410. $('#frameContainer, #modalContainer, #lightboxImage').hide();
  411. $('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
  412. $('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
  413. // Preload image content, but not iframe pages.
  414. if (!Lightbox.isLightframe && !Lightbox.isVideo && !Lightbox.isModal) {
  415. $("#lightbox #imageDataContainer").removeClass('lightbox2-alt-layout-data');
  416. imgPreloader = new Image();
  417. imgPreloader.onerror = function() { Lightbox.imgNodeLoadingError(this); };
  418. imgPreloader.onload = function() {
  419. var photo = document.getElementById('lightboxImage');
  420. photo.src = Lightbox.imageArray[Lightbox.activeImage][0];
  421. photo.alt = Lightbox.imageArray[Lightbox.activeImage][2];
  422. var imageWidth = imgPreloader.width;
  423. var imageHeight = imgPreloader.height;
  424. // Resize code.
  425. var arrayPageSize = Lightbox.getPageSize();
  426. var targ = { w:arrayPageSize[2] - (Lightbox.borderSize * 2), h:arrayPageSize[3] - (Lightbox.borderSize * 6) - (Lightbox.infoHeight * 4) - (arrayPageSize[3] / 10) };
  427. var orig = { w:imgPreloader.width, h:imgPreloader.height };
  428. // Image is very large, so show a smaller version of the larger image
  429. // with zoom button.
  430. if (zoomIn !== true) {
  431. var ratio = 1.0; // Shrink image with the same aspect.
  432. $('#bottomNavZoomOut, #bottomNavZoom').hide();
  433. if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
  434. ratio = ((targ.w / orig.w) < (targ.h / orig.h)) ? targ.w / orig.w : targ.h / orig.h;
  435. if (!Lightbox.disableZoom && !Lightbox.isSlideshow) {
  436. $('#bottomNavZoom').css({'zIndex': '10500'}).show();
  437. }
  438. }
  439. imageWidth = Math.floor(orig.w * ratio);
  440. imageHeight = Math.floor(orig.h * ratio);
  441. }
  442. else {
  443. $('#bottomNavZoom').hide();
  444. // Only display zoom out button if the image is zoomed in already.
  445. if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
  446. // Only display zoom out button if not a slideshow and if the
  447. // buttons aren't disabled.
  448. if (!Lightbox.disableResize && Lightbox.isSlideshow === false && !Lightbox.disableZoom) {
  449. $('#bottomNavZoomOut').css({'zIndex': '10500'}).show();
  450. }
  451. }
  452. }
  453. photo.style.width = (imageWidth) + 'px';
  454. photo.style.height = (imageHeight) + 'px';
  455. Lightbox.resizeContainer(imageWidth, imageHeight);
  456. // Clear onLoad, IE behaves irratically with animated gifs otherwise.
  457. imgPreloader.onload = function() {};
  458. };
  459. imgPreloader.src = Lightbox.imageArray[Lightbox.activeImage][0];
  460. imgPreloader.alt = Lightbox.imageArray[Lightbox.activeImage][2];
  461. }
  462. // Set up frame size, etc.
  463. else if (Lightbox.isLightframe) {
  464. $("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
  465. var src = Lightbox.imageArray[Lightbox.activeImage][0];
  466. $('#frameContainer').html('<iframe id="lightboxFrame" style="display: none;" src="'+src+'"></iframe>');
  467. // Enable swf support in Gecko browsers.
  468. if ($.browser.mozilla && src.indexOf('.swf') != -1) {
  469. setTimeout(function () {
  470. document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
  471. }, 1000);
  472. }
  473. if (!Lightbox.iframe_border) {
  474. $('#lightboxFrame').css({'border': 'none'});
  475. $('#lightboxFrame').attr('frameborder', '0');
  476. }
  477. var iframe = document.getElementById('lightboxFrame');
  478. var iframeStyles = Lightbox.imageArray[Lightbox.activeImage][3];
  479. iframe = Lightbox.setStyles(iframe, iframeStyles);
  480. Lightbox.resizeContainer(parseInt(iframe.width, 10), parseInt(iframe.height, 10));
  481. }
  482. else if (Lightbox.isVideo || Lightbox.isModal) {
  483. $("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
  484. var container = document.getElementById('modalContainer');
  485. var modalStyles = Lightbox.imageArray[Lightbox.activeImage][3];
  486. container = Lightbox.setStyles(container, modalStyles);
  487. if (Lightbox.isVideo) {
  488. Lightbox.modalHeight = parseInt(container.height, 10) - 10;
  489. Lightbox.modalWidth = parseInt(container.width, 10) - 10;
  490. Lightvideo.startVideo(Lightbox.imageArray[Lightbox.activeImage][0]);
  491. }
  492. Lightbox.resizeContainer(parseInt(container.width, 10), parseInt(container.height, 10));
  493. }
  494. }
  495. },
  496. // imgNodeLoadingError()
  497. imgNodeLoadingError: function(image) {
  498. var s = Drupal.settings.lightbox2;
  499. var original_image = Lightbox.imageArray[Lightbox.activeImage][0];
  500. if (s.display_image_size !== "") {
  501. original_image = original_image.replace(new RegExp("."+s.display_image_size), "");
  502. }
  503. Lightbox.imageArray[Lightbox.activeImage][0] = original_image;
  504. image.onerror = function() { Lightbox.imgLoadingError(image); };
  505. image.src = original_image;
  506. },
  507. // imgLoadingError()
  508. imgLoadingError: function(image) {
  509. var s = Drupal.settings.lightbox2;
  510. Lightbox.imageArray[Lightbox.activeImage][0] = s.default_image;
  511. image.src = s.default_image;
  512. },
  513. // resizeContainer()
  514. resizeContainer: function(imgWidth, imgHeight) {
  515. imgWidth = (imgWidth < Lightbox.minWidth ? Lightbox.minWidth : imgWidth);
  516. this.widthCurrent = $('#outerImageContainer').width();
  517. this.heightCurrent = $('#outerImageContainer').height();
  518. var widthNew = (imgWidth + (Lightbox.borderSize * 2));
  519. var heightNew = (imgHeight + (Lightbox.borderSize * 2));
  520. // Scalars based on change from old to new.
  521. this.xScale = ( widthNew / this.widthCurrent) * 100;
  522. this.yScale = ( heightNew / this.heightCurrent) * 100;
  523. // Calculate size difference between new and old image, and resize if
  524. // necessary.
  525. wDiff = this.widthCurrent - widthNew;
  526. hDiff = this.heightCurrent - heightNew;
  527. $('#modalContainer').css({'width': imgWidth, 'height': imgHeight});
  528. // Detect animation sequence.
  529. if (Lightbox.resizeSequence) {
  530. var animate1 = {width: widthNew};
  531. var animate2 = {height: heightNew};
  532. if (Lightbox.resizeSequence == 2) {
  533. animate1 = {height: heightNew};
  534. animate2 = {width: widthNew};
  535. }
  536. $('#outerImageContainer').animate(animate1, Lightbox.resizeSpeed).animate(animate2, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
  537. }
  538. // Simultaneous.
  539. else {
  540. $('#outerImageContainer').animate({'width': widthNew, 'height': heightNew}, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
  541. }
  542. // If new and old image are same size and no scaling transition is necessary
  543. // do a quick pause to prevent image flicker.
  544. if ((hDiff === 0) && (wDiff === 0)) {
  545. if ($.browser.msie) {
  546. Lightbox.pause(250);
  547. }
  548. else {
  549. Lightbox.pause(100);
  550. }
  551. }
  552. var s = Drupal.settings.lightbox2;
  553. if (!s.use_alt_layout) {
  554. $('#prevLink, #nextLink').css({'height': imgHeight + 'px'});
  555. }
  556. $('#imageDataContainer').css({'width': widthNew + 'px'});
  557. },
  558. // showData()
  559. // Display image and begin preloading neighbors.
  560. showData: function() {
  561. $('#loading').hide();
  562. if (Lightbox.isLightframe || Lightbox.isVideo || Lightbox.isModal) {
  563. Lightbox.updateDetails();
  564. if (Lightbox.isLightframe) {
  565. $('#frameContainer').show();
  566. if ($.browser.safari || Lightbox.fadeInSpeed === 0) {
  567. $('#lightboxFrame').css({'zIndex': '10500'}).show();
  568. }
  569. else {
  570. $('#lightboxFrame').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
  571. }
  572. }
  573. else {
  574. if (Lightbox.isVideo) {
  575. $("#modalContainer").html(Lightbox.modalHTML).click(function(){return false;}).css('zIndex', '10500').show();
  576. }
  577. else {
  578. var src = unescape(Lightbox.imageArray[Lightbox.activeImage][0]);
  579. if (Lightbox.imageArray[Lightbox.activeImage][4]) {
  580. $(src).appendTo("#modalContainer");
  581. $('#modalContainer').css({'zIndex': '10500'}).show();
  582. }
  583. else {
  584. // Use a callback to show the new image, otherwise you get flicker.
  585. $("#modalContainer").hide().load(src, function () {$('#modalContainer').css({'zIndex': '10500'}).show();});
  586. }
  587. $('#modalContainer').unbind('click');
  588. }
  589. // This might be needed in the Lightframe section above.
  590. //$('#modalContainer').css({'zIndex': '10500'}).show();
  591. }
  592. }
  593. // Handle display of image content.
  594. else {
  595. $('#imageContainer').show();
  596. if ($.browser.safari || Lightbox.fadeInSpeed === 0) {
  597. $('#lightboxImage').css({'zIndex': '10500'}).show();
  598. }
  599. else {
  600. $('#lightboxImage').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
  601. }
  602. Lightbox.updateDetails();
  603. this.preloadNeighborImages();
  604. }
  605. Lightbox.inprogress = false;
  606. // Slideshow specific stuff.
  607. if (Lightbox.isSlideshow) {
  608. if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
  609. if (Lightbox.autoExit) {
  610. Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.end('slideshow');}, Lightbox.slideInterval);
  611. }
  612. }
  613. else {
  614. if (!Lightbox.isPaused && Lightbox.total > 1) {
  615. Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.changeData(Lightbox.activeImage + 1);}, Lightbox.slideInterval);
  616. }
  617. }
  618. if (Lightbox.showPlayPause && Lightbox.total > 1 && !Lightbox.isPaused) {
  619. $('#lightshowPause').show();
  620. $('#lightshowPlay').hide();
  621. }
  622. else if (Lightbox.showPlayPause && Lightbox.total > 1) {
  623. $('#lightshowPause').hide();
  624. $('#lightshowPlay').show();
  625. }
  626. }
  627. // Adjust the page overlay size.
  628. var arrayPageSize = Lightbox.getPageSize();
  629. var arrayPageScroll = Lightbox.getPageScroll();
  630. var pageHeight = arrayPageSize[1];
  631. if (Lightbox.isZoomedIn && arrayPageSize[1] > arrayPageSize[3]) {
  632. var lightboxTop = (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
  633. pageHeight = pageHeight + arrayPageScroll[1] + lightboxTop;
  634. }
  635. $('#lightbox2-overlay').css({'height': pageHeight + 'px', 'width': arrayPageSize[0] + 'px'});
  636. // Gecko browsers (e.g. Firefox, SeaMonkey, etc) don't handle pdfs as
  637. // expected.
  638. if ($.browser.mozilla) {
  639. if (Lightbox.imageArray[Lightbox.activeImage][0].indexOf(".pdf") != -1) {
  640. setTimeout(function () {
  641. document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
  642. }, 1000);
  643. }
  644. }
  645. },
  646. // updateDetails()
  647. // Display caption, image number, and bottom nav.
  648. updateDetails: function() {
  649. $("#imageDataContainer").hide();
  650. var s = Drupal.settings.lightbox2;
  651. if (s.show_caption) {
  652. var caption = Lightbox.filterXSS(Lightbox.imageArray[Lightbox.activeImage][1]);
  653. if (!caption) caption = '';
  654. $('#caption').html(caption).css({'zIndex': '10500'}).show();
  655. }
  656. // If image is part of set display 'Image x of x'.
  657. var numberDisplay = null;
  658. if (s.image_count && Lightbox.total > 1) {
  659. var currentImage = Lightbox.activeImage + 1;
  660. if (!Lightbox.isLightframe && !Lightbox.isModal && !Lightbox.isVideo) {
  661. numberDisplay = s.image_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
  662. }
  663. else if (Lightbox.isVideo) {
  664. numberDisplay = s.video_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
  665. }
  666. else {
  667. numberDisplay = s.page_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
  668. }
  669. $('#numberDisplay').html(numberDisplay).css({'zIndex': '10500'}).show();
  670. }
  671. else {
  672. $('#numberDisplay').hide();
  673. }
  674. $("#imageDataContainer").hide().slideDown(Lightbox.slideDownSpeed, function() {
  675. $("#bottomNav").show();
  676. });
  677. if (Lightbox.rtl == 1) {
  678. $("#bottomNav").css({'float': 'left'});
  679. }
  680. Lightbox.updateNav();
  681. },
  682. // updateNav()
  683. // Display appropriate previous and next hover navigation.
  684. updateNav: function() {
  685. $('#hoverNav').css({'zIndex': '10500'}).show();
  686. var prevLink = '#prevLink';
  687. var nextLink = '#nextLink';
  688. // Slideshow is separated as we need to show play / pause button.
  689. if (Lightbox.isSlideshow) {
  690. if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage !== 0) {
  691. $(prevLink).css({'zIndex': '10500'}).show().click(function() {
  692. if (Lightbox.pauseOnPrevClick) {
  693. Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
  694. }
  695. Lightbox.changeData(Lightbox.activeImage - 1); return false;
  696. });
  697. }
  698. else {
  699. $(prevLink).hide();
  700. }
  701. // If not last image in set, display next image button.
  702. if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage != (Lightbox.total - 1)) {
  703. $(nextLink).css({'zIndex': '10500'}).show().click(function() {
  704. if (Lightbox.pauseOnNextClick) {
  705. Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
  706. }
  707. Lightbox.changeData(Lightbox.activeImage + 1); return false;
  708. });
  709. }
  710. // Safari browsers need to have hide() called again.
  711. else {
  712. $(nextLink).hide();
  713. }
  714. }
  715. // All other types of content.
  716. else {
  717. if ((Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) && !Lightbox.alternative_layout) {
  718. $('#frameHoverNav').css({'zIndex': '10500'}).show();
  719. $('#hoverNav').css({'zIndex': '10500'}).hide();
  720. prevLink = '#framePrevLink';
  721. nextLink = '#frameNextLink';
  722. }
  723. // If not first image in set, display prev image button.
  724. if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage !== 0) {
  725. // Unbind any other click handlers, otherwise this adds a new click handler
  726. // each time the arrow is clicked.
  727. $(prevLink).css({'zIndex': '10500'}).show().unbind().click(function() {
  728. Lightbox.changeData(Lightbox.activeImage - 1); return false;
  729. });
  730. }
  731. // Safari browsers need to have hide() called again.
  732. else {
  733. $(prevLink).hide();
  734. }
  735. // If not last image in set, display next image button.
  736. if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage != (Lightbox.total - 1)) {
  737. // Unbind any other click handlers, otherwise this adds a new click handler
  738. // each time the arrow is clicked.
  739. $(nextLink).css({'zIndex': '10500'}).show().unbind().click(function() {
  740. Lightbox.changeData(Lightbox.activeImage + 1); return false;
  741. });
  742. }
  743. // Safari browsers need to have hide() called again.
  744. else {
  745. $(nextLink).hide();
  746. }
  747. }
  748. // Don't enable keyboard shortcuts so forms will work.
  749. if (!Lightbox.isModal) {
  750. this.enableKeyboardNav();
  751. }
  752. },
  753. // enableKeyboardNav()
  754. enableKeyboardNav: function() {
  755. $(document).bind("keydown", this.keyboardAction);
  756. },
  757. // disableKeyboardNav()
  758. disableKeyboardNav: function() {
  759. $(document).unbind("keydown", this.keyboardAction);
  760. },
  761. // keyboardAction()
  762. keyboardAction: function(e) {
  763. if (e === null) { // IE.
  764. keycode = event.keyCode;
  765. escapeKey = 27;
  766. }
  767. else { // Mozilla.
  768. keycode = e.keyCode;
  769. escapeKey = e.DOM_VK_ESCAPE;
  770. }
  771. key = String.fromCharCode(keycode).toLowerCase();
  772. // Close lightbox.
  773. if (Lightbox.checkKey(Lightbox.keysClose, key, keycode)) {
  774. Lightbox.end('forceClose');
  775. }
  776. // Display previous image (p, <-).
  777. else if (Lightbox.checkKey(Lightbox.keysPrevious, key, keycode)) {
  778. if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage !== 0) {
  779. Lightbox.changeData(Lightbox.activeImage - 1);
  780. }
  781. }
  782. // Display next image (n, ->).
  783. else if (Lightbox.checkKey(Lightbox.keysNext, key, keycode)) {
  784. if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage != (Lightbox.total - 1)) {
  785. Lightbox.changeData(Lightbox.activeImage + 1);
  786. }
  787. }
  788. // Zoom in.
  789. else if (Lightbox.checkKey(Lightbox.keysZoom, key, keycode) && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
  790. if (Lightbox.isZoomedIn) {
  791. Lightbox.changeData(Lightbox.activeImage, false);
  792. }
  793. else if (!Lightbox.isZoomedIn) {
  794. Lightbox.changeData(Lightbox.activeImage, true);
  795. }
  796. return false;
  797. }
  798. // Toggle play / pause (space).
  799. else if (Lightbox.checkKey(Lightbox.keysPlayPause, key, keycode) && Lightbox.isSlideshow) {
  800. if (Lightbox.isPaused) {
  801. Lightbox.togglePlayPause("lightshowPlay", "lightshowPause");
  802. }
  803. else {
  804. Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
  805. }
  806. return false;
  807. }
  808. },
  809. preloadNeighborImages: function() {
  810. if ((Lightbox.total - 1) > Lightbox.activeImage) {
  811. preloadNextImage = new Image();
  812. preloadNextImage.src = Lightbox.imageArray[Lightbox.activeImage + 1][0];
  813. }
  814. if (Lightbox.activeImage > 0) {
  815. preloadPrevImage = new Image();
  816. preloadPrevImage.src = Lightbox.imageArray[Lightbox.activeImage - 1][0];
  817. }
  818. },
  819. end: function(caller) {
  820. var closeClick = (caller == 'slideshow' ? false : true);
  821. if (Lightbox.isSlideshow && Lightbox.isPaused && !closeClick) {
  822. return;
  823. }
  824. // To prevent double clicks on navigation links.
  825. if (Lightbox.inprogress === true && caller != 'forceClose') {
  826. return;
  827. }
  828. Lightbox.disableKeyboardNav();
  829. $('#lightbox').hide();
  830. $("#lightbox2-overlay").fadeOut();
  831. Lightbox.isPaused = true;
  832. Lightbox.inprogress = false;
  833. // Replaces calls to showSelectBoxes() and showFlash() in original
  834. // lightbox2.
  835. Lightbox.toggleSelectsFlash('visible');
  836. if (Lightbox.isSlideshow) {
  837. for (var i = 0; i < Lightbox.slideIdCount; i++) {
  838. window.clearTimeout(Lightbox.slideIdArray[i]);
  839. }
  840. $('#lightshowPause, #lightshowPlay').hide();
  841. }
  842. else if (Lightbox.isLightframe) {
  843. $('#frameContainer').empty().hide();
  844. }
  845. else if (Lightbox.isVideo || Lightbox.isModal) {
  846. if (!Lightbox.auto_modal) {
  847. $('#modalContainer').hide().html("");
  848. }
  849. Lightbox.auto_modal = false;
  850. }
  851. },
  852. // getPageScroll()
  853. // Returns array with x,y page scroll values.
  854. // Core code from - quirksmode.com.
  855. getPageScroll : function() {
  856. var xScroll, yScroll;
  857. if (self.pageYOffset || self.pageXOffset) {
  858. yScroll = self.pageYOffset;
  859. xScroll = self.pageXOffset;
  860. }
  861. else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) { // Explorer 6 Strict.
  862. yScroll = document.documentElement.scrollTop;
  863. xScroll = document.documentElement.scrollLeft;
  864. }
  865. else if (document.body) {// All other Explorers.
  866. yScroll = document.body.scrollTop;
  867. xScroll = document.body.scrollLeft;
  868. }
  869. arrayPageScroll = [xScroll,yScroll];
  870. return arrayPageScroll;
  871. },
  872. // getPageSize()
  873. // Returns array with page width, height and window width, height.
  874. // Core code from - quirksmode.com.
  875. // Edit for Firefox by pHaez.
  876. getPageSize : function() {
  877. var xScroll, yScroll;
  878. if (window.innerHeight && window.scrollMaxY) {
  879. xScroll = window.innerWidth + window.scrollMaxX;
  880. yScroll = window.innerHeight + window.scrollMaxY;
  881. }
  882. else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac.
  883. xScroll = document.body.scrollWidth;
  884. yScroll = document.body.scrollHeight;
  885. }
  886. else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari.
  887. xScroll = document.body.offsetWidth;
  888. yScroll = document.body.offsetHeight;
  889. }
  890. var windowWidth, windowHeight;
  891. if (self.innerHeight) { // All except Explorer.
  892. if (document.documentElement.clientWidth) {
  893. windowWidth = document.documentElement.clientWidth;
  894. }
  895. else {
  896. windowWidth = self.innerWidth;
  897. }
  898. windowHeight = self.innerHeight;
  899. }
  900. else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode.
  901. windowWidth = document.documentElement.clientWidth;
  902. windowHeight = document.documentElement.clientHeight;
  903. }
  904. else if (document.body) { // Other Explorers.
  905. windowWidth = document.body.clientWidth;
  906. windowHeight = document.body.clientHeight;
  907. }
  908. // For small pages with total height less than height of the viewport.
  909. if (yScroll < windowHeight) {
  910. pageHeight = windowHeight;
  911. }
  912. else {
  913. pageHeight = yScroll;
  914. }
  915. // For small pages with total width less than width of the viewport.
  916. if (xScroll < windowWidth) {
  917. pageWidth = xScroll;
  918. }
  919. else {
  920. pageWidth = windowWidth;
  921. }
  922. arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
  923. return arrayPageSize;
  924. },
  925. // pause(numberMillis)
  926. pause : function(ms) {
  927. var date = new Date();
  928. var curDate = null;
  929. do { curDate = new Date(); }
  930. while (curDate - date < ms);
  931. },
  932. // toggleSelectsFlash()
  933. // Hide / unhide select lists and flash objects as they appear above the
  934. // lightbox in some browsers.
  935. toggleSelectsFlash: function (state) {
  936. if (state == 'visible') {
  937. $("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").show();
  938. }
  939. else if (state == 'hide') {
  940. $("select:visible, embed:visible, object:visible").not('#lightboxAutoModal select, #lightboxAutoModal embed, #lightboxAutoModal object').addClass("lightbox_hidden");
  941. $("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").hide();
  942. }
  943. },
  944. // parseRel()
  945. parseRel: function (link) {
  946. var parts = [];
  947. parts["rel"] = parts["title"] = parts["group"] = parts["style"] = parts["flashvars"] = null;
  948. if (!$(link).attr('rel')) return parts;
  949. parts["rel"] = $(link).attr('rel').match(/\w+/)[0];
  950. if ($(link).attr('rel').match(/\[(.*)\]/)) {
  951. var info = $(link).attr('rel').match(/\[(.*?)\]/)[1].split('|');
  952. parts["group"] = info[0];
  953. parts["style"] = info[1];
  954. if (parts["style"] != undefined && parts["style"].match(/flashvars:\s?(.*?);/)) {
  955. parts["flashvars"] = parts["style"].match(/flashvars:\s?(.*?);/)[1];
  956. }
  957. }
  958. if ($(link).attr('rel').match(/\[.*\]\[(.*)\]/)) {
  959. parts["title"] = $(link).attr('rel').match(/\[.*\]\[(.*)\]/)[1];
  960. }
  961. return parts;
  962. },
  963. // setStyles()
  964. setStyles: function(item, styles) {
  965. item.width = Lightbox.iframe_width;
  966. item.height = Lightbox.iframe_height;
  967. item.scrolling = "auto";
  968. if (!styles) return item;
  969. var stylesArray = styles.split(';');
  970. for (var i = 0; i< stylesArray.length; i++) {
  971. if (stylesArray[i].indexOf('width:') >= 0) {
  972. var w = stylesArray[i].replace('width:', '');
  973. item.width = jQuery.trim(w);
  974. }
  975. else if (stylesArray[i].indexOf('height:') >= 0) {
  976. var h = stylesArray[i].replace('height:', '');
  977. item.height = jQuery.trim(h);
  978. }
  979. else if (stylesArray[i].indexOf('scrolling:') >= 0) {
  980. var scrolling = stylesArray[i].replace('scrolling:', '');
  981. item.scrolling = jQuery.trim(scrolling);
  982. }
  983. else if (stylesArray[i].indexOf('overflow:') >= 0) {
  984. var overflow = stylesArray[i].replace('overflow:', '');
  985. item.overflow = jQuery.trim(overflow);
  986. }
  987. }
  988. return item;
  989. },
  990. // togglePlayPause()
  991. // Hide the pause / play button as appropriate. If pausing the slideshow also
  992. // clear the timers, otherwise move onto the next image.
  993. togglePlayPause: function(hideId, showId) {
  994. if (Lightbox.isSlideshow && hideId == "lightshowPause") {
  995. for (var i = 0; i < Lightbox.slideIdCount; i++) {
  996. window.clearTimeout(Lightbox.slideIdArray[i]);
  997. }
  998. }
  999. $('#' + hideId).hide();
  1000. $('#' + showId).show();
  1001. if (hideId == "lightshowPlay") {
  1002. Lightbox.isPaused = false;
  1003. if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
  1004. Lightbox.end();
  1005. }
  1006. else if (Lightbox.total > 1) {
  1007. Lightbox.changeData(Lightbox.activeImage + 1);
  1008. }
  1009. }
  1010. else {
  1011. Lightbox.isPaused = true;
  1012. }
  1013. },
  1014. triggerLightbox: function (rel_type, rel_group) {
  1015. if (rel_type.length) {
  1016. if (rel_group && rel_group.length) {
  1017. $("a[rel^='" + rel_type +"\[" + rel_group + "\]'], area[rel^='" + rel_type +"\[" + rel_group + "\]']").eq(0).trigger("click");
  1018. }
  1019. else {
  1020. $("a[rel^='" + rel_type +"'], area[rel^='" + rel_type +"']").eq(0).trigger("click");
  1021. }
  1022. }
  1023. },
  1024. detectMacFF2: function() {
  1025. var ua = navigator.userAgent.toLowerCase();
  1026. if (/firefox[\/\s](\d+\.\d+)/.test(ua)) {
  1027. var ffversion = new Number(RegExp.$1);
  1028. if (ffversion < 3 && ua.indexOf('mac') != -1) {
  1029. return true;
  1030. }
  1031. }
  1032. return false;
  1033. },
  1034. checkKey: function(keys, key, code) {
  1035. return (jQuery.inArray(key, keys) != -1 || jQuery.inArray(String(code), keys) != -1);
  1036. },
  1037. filterXSS: function(str, allowed_tags) {
  1038. var output = "";
  1039. $.ajax({
  1040. url: Drupal.settings.basePath + 'system/lightbox2/filter-xss',
  1041. data: {
  1042. 'string' : str,
  1043. 'allowed_tags' : allowed_tags
  1044. },
  1045. type: "POST",
  1046. async: false,
  1047. dataType: "json",
  1048. success: function(data) {
  1049. output = data;
  1050. }
  1051. });
  1052. return output;
  1053. }
  1054. };
  1055. // Initialize the lightbox.
  1056. Drupal.behaviors.initLightbox = {
  1057. attach: function(context) {
  1058. $('body:not(.lightbox-processed)', context).addClass('lightbox-processed').each(function() {
  1059. Lightbox.initialize();
  1060. return false; // Break the each loop.
  1061. });
  1062. // Attach lightbox to any links with lightbox rels.
  1063. Lightbox.initList(context);
  1064. $('#lightboxAutoModal', context).triggerHandler('click');
  1065. }
  1066. };
  1067. })(jQuery);