--- /dev/null
+/**\r
+ * jQuery lightBox plugin\r
+ * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)\r
+ * and adapted to me for use like a plugin from jQuery.\r
+ * @name jquery-lightbox-0.5.js\r
+ * @author Leandro Vieira Pinho - http://leandrovieira.com\r
+ * @version 0.5\r
+ * @date April 11, 2008\r
+ * @category jQuery plugin\r
+ * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)\r
+ * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US\r
+ * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin\r
+ */\r
+\r
+// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias\r
+(function($) {\r
+ /**\r
+ * $ is an alias to jQuery object\r
+ *\r
+ */\r
+ $.fn.lightBox = function(settings) {\r
+ // Settings to configure the jQuery lightBox plugin how you like\r
+ settings = jQuery.extend({\r
+ // Configuration related to overlay\r
+ overlayBgColor: '#000', // (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.\r
+ overlayOpacity: 0.8, // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9\r
+ // Configuration related to navigation\r
+ fixedNavigation: false, // (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.\r
+ // Configuration related to images\r
+ imageLoading: 'img/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon\r
+ imageBtnPrev: 'img/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image\r
+ imageBtnNext: 'img/lightbox-btn-next.gif', // (string) Path and the name of the next button image\r
+ imageBtnClose: 'img/lightbox-btn-close.gif', // (string) Path and the name of the close btn\r
+ imageBlank: 'img/lightbox-blank.gif', // (string) Path and the name of a blank image (one pixel)\r
+ // Configuration related to container image box\r
+ containerBorderSize: 10, // (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value\r
+ containerResizeSpeed: 400, // (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.\r
+ // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.\r
+ txtImage: 'Image', // (string) Specify text "Image"\r
+ txtOf: 'of', // (string) Specify text "of"\r
+ // Configuration related to keyboard navigation\r
+ keyToClose: 'c', // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.\r
+ keyToPrev: 'p', // (string) (p = previous) Letter to show the previous image\r
+ keyToNext: 'n', // (string) (n = next) Letter to show the next image.\r
+ // Don´t alter these variables in any way\r
+ imageArray: [],\r
+ activeImage: 0\r
+ },settings);\r
+ // Caching the jQuery object with all elements matched\r
+ var jQueryMatchedObj = this; // This, in this context, refer to jQuery object\r
+ /**\r
+ * Initializing the plugin calling the start function\r
+ *\r
+ * @return boolean false\r
+ */\r
+ function _initialize() {\r
+ _start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked\r
+ return false; // Avoid the browser following the link\r
+ }\r
+ /**\r
+ * Start the jQuery lightBox plugin\r
+ *\r
+ * @param object objClicked The object (link) whick the user have clicked\r
+ * @param object jQueryMatchedObj The jQuery object with all elements matched\r
+ */\r
+ function _start(objClicked,jQueryMatchedObj) {\r
+ // Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.\r
+ $('embed, object, select').css({ 'visibility' : 'hidden' });\r
+ // Call the function to create the markup structure; style some elements; assign events in some elements.\r
+ _set_interface();\r
+ // Unset total images in imageArray\r
+ settings.imageArray.length = 0;\r
+ // Unset image active information\r
+ settings.activeImage = 0;\r
+ // We have an image set? Or just an image? Let´s see it.\r
+ if ( jQueryMatchedObj.length == 1 ) {\r
+ settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));\r
+ } else {\r
+ // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references \r
+ for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {\r
+ settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));\r
+ }\r
+ }\r
+ while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {\r
+ settings.activeImage++;\r
+ }\r
+ // Call the function that prepares image exibition\r
+ _set_image_to_view();\r
+ }\r
+ /**\r
+ * Create the jQuery lightBox plugin interface\r
+ *\r
+ * The HTML markup will be like that:\r
+ <div id="jquery-overlay"></div>\r
+ <div id="jquery-lightbox">\r
+ <div id="lightbox-container-image-box">\r
+ <div id="lightbox-container-image">\r
+ <img src="../fotos/XX.jpg" id="lightbox-image">\r
+ <div id="lightbox-nav">\r
+ <a href="#" id="lightbox-nav-btnPrev"></a>\r
+ <a href="#" id="lightbox-nav-btnNext"></a>\r
+ </div>\r
+ <div id="lightbox-loading">\r
+ <a href="#" id="lightbox-loading-link">\r
+ <img src="../img/lightbox-ico-loading.gif">\r
+ </a>\r
+ </div>\r
+ </div>\r
+ </div>\r
+ <div id="lightbox-container-image-data-box">\r
+ <div id="lightbox-container-image-data">\r
+ <div id="lightbox-image-details">\r
+ <span id="lightbox-image-details-caption"></span>\r
+ <span id="lightbox-image-details-currentNumber"></span>\r
+ </div>\r
+ <div id="lightbox-secNav">\r
+ <a href="#" id="lightbox-secNav-btnClose">\r
+ <img src="../img/lightbox-btn-close.gif">\r
+ </a>\r
+ </div>\r
+ </div>\r
+ </div>\r
+ </div>\r
+ *\r
+ */\r
+ function _set_interface() {\r
+ // Apply the HTML markup into body tag\r
+ $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>'); \r
+ // Get page sizes\r
+ var arrPageSizes = ___getPageSize();\r
+ // Style overlay and show it\r
+ $('#jquery-overlay').css({\r
+ backgroundColor: settings.overlayBgColor,\r
+ opacity: settings.overlayOpacity,\r
+ width: arrPageSizes[0],\r
+ height: arrPageSizes[1]\r
+ }).fadeIn();\r
+ // Get page scroll\r
+ var arrPageScroll = ___getPageScroll();\r
+ // Calculate top and left offset for the jquery-lightbox div object and show it\r
+ $('#jquery-lightbox').css({\r
+ top: arrPageScroll[1] + (arrPageSizes[3] / 10),\r
+ left: arrPageScroll[0]\r
+ }).show();\r
+ // Assigning click events in elements to close overlay\r
+ $('#jquery-overlay,#jquery-lightbox').click(function() {\r
+ _finish(); \r
+ });\r
+ // Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects\r
+ $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {\r
+ _finish();\r
+ return false;\r
+ });\r
+ // If window was resized, calculate the new overlay dimensions\r
+ $(window).resize(function() {\r
+ // Get page sizes\r
+ var arrPageSizes = ___getPageSize();\r
+ // Style overlay and show it\r
+ $('#jquery-overlay').css({\r
+ width: arrPageSizes[0],\r
+ height: arrPageSizes[1]\r
+ });\r
+ // Get page scroll\r
+ var arrPageScroll = ___getPageScroll();\r
+ // Calculate top and left offset for the jquery-lightbox div object and show it\r
+ $('#jquery-lightbox').css({\r
+ top: arrPageScroll[1] + (arrPageSizes[3] / 10),\r
+ left: arrPageScroll[0]\r
+ });\r
+ });\r
+ }\r
+ /**\r
+ * Prepares image exibition; doing a image´s preloader to calculate it´s size\r
+ *\r
+ */\r
+ function _set_image_to_view() { // show the loading\r
+ // Show the loading\r
+ $('#lightbox-loading').show();\r
+ if ( settings.fixedNavigation ) {\r
+ $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();\r
+ } else {\r
+ // Hide some elements\r
+ $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();\r
+ }\r
+ // Image preload process\r
+ var objImagePreloader = new Image();\r
+ objImagePreloader.onload = function() {\r
+ $('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);\r
+ // Perfomance an effect in the image container resizing it\r
+ _resize_container_image_box(objImagePreloader.width,objImagePreloader.height);\r
+ // clear onLoad, IE behaves irratically with animated gifs otherwise\r
+ objImagePreloader.onload=function(){};\r
+ };\r
+ objImagePreloader.src = settings.imageArray[settings.activeImage][0];\r
+ };\r
+ /**\r
+ * Perfomance an effect in the image container resizing it\r
+ *\r
+ * @param integer intImageWidth The image´s width that will be showed\r
+ * @param integer intImageHeight The image´s height that will be showed\r
+ */\r
+ function _resize_container_image_box(intImageWidth,intImageHeight) {\r
+ // Get current width and height\r
+ var intCurrentWidth = $('#lightbox-container-image-box').width();\r
+ var intCurrentHeight = $('#lightbox-container-image-box').height();\r
+ // Get the width and height of the selected image plus the padding\r
+ var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value\r
+ var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value\r
+ // Diferences\r
+ var intDiffW = intCurrentWidth - intWidth;\r
+ var intDiffH = intCurrentHeight - intHeight;\r
+ // Perfomance the effect\r
+ $('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });\r
+ if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {\r
+ if ( $.browser.msie ) {\r
+ ___pause(250);\r
+ } else {\r
+ ___pause(100); \r
+ }\r
+ } \r
+ $('#lightbox-container-image-data-box').css({ width: intImageWidth });\r
+ $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });\r
+ };\r
+ /**\r
+ * Show the prepared image\r
+ *\r
+ */\r
+ function _show_image() {\r
+ $('#lightbox-loading').hide();\r
+ $('#lightbox-image').fadeIn(function() {\r
+ _show_image_data();\r
+ _set_navigation();\r
+ });\r
+ _preload_neighbor_images();\r
+ };\r
+ /**\r
+ * Show the image information\r
+ *\r
+ */\r
+ function _show_image_data() {\r
+ $('#lightbox-container-image-data-box').slideDown('fast');\r
+ $('#lightbox-image-details-caption').hide();\r
+ if ( settings.imageArray[settings.activeImage][1] ) {\r
+ $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();\r
+ }\r
+ // If we have a image set, display 'Image X of X'\r
+ if ( settings.imageArray.length > 1 ) {\r
+ $('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();\r
+ } \r
+ }\r
+ /**\r
+ * Display the button navigations\r
+ *\r
+ */\r
+ function _set_navigation() {\r
+ $('#lightbox-nav').show();\r
+\r
+ // Instead to define this configuration in CSS file, we define here. And it´s need to IE. Just.\r
+ $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });\r
+ \r
+ // Show the prev button, if not the first image in set\r
+ if ( settings.activeImage != 0 ) {\r
+ if ( settings.fixedNavigation ) {\r
+ $('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })\r
+ .unbind()\r
+ .bind('click',function() {\r
+ settings.activeImage = settings.activeImage - 1;\r
+ _set_image_to_view();\r
+ return false;\r
+ });\r
+ } else {\r
+ // Show the images button for Next buttons\r
+ $('#lightbox-nav-btnPrev').unbind().hover(function() {\r
+ $(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });\r
+ },function() {\r
+ $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });\r
+ }).show().bind('click',function() {\r
+ settings.activeImage = settings.activeImage - 1;\r
+ _set_image_to_view();\r
+ return false;\r
+ });\r
+ }\r
+ }\r
+ \r
+ // Show the next button, if not the last image in set\r
+ if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {\r
+ if ( settings.fixedNavigation ) {\r
+ $('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })\r
+ .unbind()\r
+ .bind('click',function() {\r
+ settings.activeImage = settings.activeImage + 1;\r
+ _set_image_to_view();\r
+ return false;\r
+ });\r
+ } else {\r
+ // Show the images button for Next buttons\r
+ $('#lightbox-nav-btnNext').unbind().hover(function() {\r
+ $(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });\r
+ },function() {\r
+ $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });\r
+ }).show().bind('click',function() {\r
+ settings.activeImage = settings.activeImage + 1;\r
+ _set_image_to_view();\r
+ return false;\r
+ });\r
+ }\r
+ }\r
+ // Enable keyboard navigation\r
+ _enable_keyboard_navigation();\r
+ }\r
+ /**\r
+ * Enable a support to keyboard navigation\r
+ *\r
+ */\r
+ function _enable_keyboard_navigation() {\r
+ $(document).keydown(function(objEvent) {\r
+ _keyboard_action(objEvent);\r
+ });\r
+ }\r
+ /**\r
+ * Disable the support to keyboard navigation\r
+ *\r
+ */\r
+ function _disable_keyboard_navigation() {\r
+ $(document).unbind();\r
+ }\r
+ /**\r
+ * Perform the keyboard actions\r
+ *\r
+ */\r
+ function _keyboard_action(objEvent) {\r
+ // To ie\r
+ if ( objEvent == null ) {\r
+ keycode = event.keyCode;\r
+ escapeKey = 27;\r
+ // To Mozilla\r
+ } else {\r
+ keycode = objEvent.keyCode;\r
+ escapeKey = objEvent.DOM_VK_ESCAPE;\r
+ }\r
+ // Get the key in lower case form\r
+ key = String.fromCharCode(keycode).toLowerCase();\r
+ // Verify the keys to close the ligthBox\r
+ if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {\r
+ _finish();\r
+ }\r
+ // Verify the key to show the previous image\r
+ if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {\r
+ // If we´re not showing the first image, call the previous\r
+ if ( settings.activeImage != 0 ) {\r
+ settings.activeImage = settings.activeImage - 1;\r
+ _set_image_to_view();\r
+ _disable_keyboard_navigation();\r
+ }\r
+ }\r
+ // Verify the key to show the next image\r
+ if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {\r
+ // If we´re not showing the last image, call the next\r
+ if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {\r
+ settings.activeImage = settings.activeImage + 1;\r
+ _set_image_to_view();\r
+ _disable_keyboard_navigation();\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * Preload prev and next images being showed\r
+ *\r
+ */\r
+ function _preload_neighbor_images() {\r
+ if ( (settings.imageArray.length -1) > settings.activeImage ) {\r
+ objNext = new Image();\r
+ objNext.src = settings.imageArray[settings.activeImage + 1][0];\r
+ }\r
+ if ( settings.activeImage > 0 ) {\r
+ objPrev = new Image();\r
+ objPrev.src = settings.imageArray[settings.activeImage -1][0];\r
+ }\r
+ }\r
+ /**\r
+ * Remove jQuery lightBox plugin HTML markup\r
+ *\r
+ */\r
+ function _finish() {\r
+ $('#jquery-lightbox').remove();\r
+ $('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });\r
+ // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.\r
+ $('embed, object, select').css({ 'visibility' : 'visible' });\r
+ }\r
+ /**\r
+ / THIRD FUNCTION\r
+ * getPageSize() by quirksmode.com\r
+ *\r
+ * @return Array Return an array with page width, height and window width, height\r
+ */\r
+ function ___getPageSize() {\r
+ var xScroll, yScroll;\r
+ if (window.innerHeight && window.scrollMaxY) { \r
+ xScroll = window.innerWidth + window.scrollMaxX;\r
+ yScroll = window.innerHeight + window.scrollMaxY;\r
+ } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac\r
+ xScroll = document.body.scrollWidth;\r
+ yScroll = document.body.scrollHeight;\r
+ } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari\r
+ xScroll = document.body.offsetWidth;\r
+ yScroll = document.body.offsetHeight;\r
+ }\r
+ var windowWidth, windowHeight;\r
+ if (self.innerHeight) { // all except Explorer\r
+ if(document.documentElement.clientWidth){\r
+ windowWidth = document.documentElement.clientWidth; \r
+ } else {\r
+ windowWidth = self.innerWidth;\r
+ }\r
+ windowHeight = self.innerHeight;\r
+ } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode\r
+ windowWidth = document.documentElement.clientWidth;\r
+ windowHeight = document.documentElement.clientHeight;\r
+ } else if (document.body) { // other Explorers\r
+ windowWidth = document.body.clientWidth;\r
+ windowHeight = document.body.clientHeight;\r
+ } \r
+ // for small pages with total height less then height of the viewport\r
+ if(yScroll < windowHeight){\r
+ pageHeight = windowHeight;\r
+ } else { \r
+ pageHeight = yScroll;\r
+ }\r
+ // for small pages with total width less then width of the viewport\r
+ if(xScroll < windowWidth){ \r
+ pageWidth = xScroll; \r
+ } else {\r
+ pageWidth = windowWidth;\r
+ }\r
+ arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);\r
+ return arrayPageSize;\r
+ };\r
+ /**\r
+ / THIRD FUNCTION\r
+ * getPageScroll() by quirksmode.com\r
+ *\r
+ * @return Array Return an array with x,y page scroll values.\r
+ */\r
+ function ___getPageScroll() {\r
+ var xScroll, yScroll;\r
+ if (self.pageYOffset) {\r
+ yScroll = self.pageYOffset;\r
+ xScroll = self.pageXOffset;\r
+ } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict\r
+ yScroll = document.documentElement.scrollTop;\r
+ xScroll = document.documentElement.scrollLeft;\r
+ } else if (document.body) {// all other Explorers\r
+ yScroll = document.body.scrollTop;\r
+ xScroll = document.body.scrollLeft; \r
+ }\r
+ arrayPageScroll = new Array(xScroll,yScroll);\r
+ return arrayPageScroll;\r
+ };\r
+ /**\r
+ * Stop the code execution from a escified time in milisecond\r
+ *\r
+ */\r
+ function ___pause(ms) {\r
+ var date = new Date(); \r
+ curDate = null;\r
+ do { var curDate = new Date(); }\r
+ while ( curDate - date < ms);\r
+ };\r
+ // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once\r
+ return this.unbind('click').click(_initialize);\r
+ };\r
+})(jQuery); // Call and execute the function immediately passing the jQuery object
\ No newline at end of file