1/** 2 * jQuery lightBox plugin 3 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/) 4 * and adapted to me for use like a plugin from jQuery. 5 * @name jquery-lightbox-0.5.js 6 * @author Leandro Vieira Pinho - http://leandrovieira.com 7 * @version 0.5 8 * @date April 11, 2008 9 * @category jQuery plugin 10 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com) 11 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US 12 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin 13 */ 14 15// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias 16(function($) { 17 /** 18 * $ is an alias to jQuery object 19 * 20 */ 21 $.fn.lightBox = function(settings) { 22 // Settings to configure the jQuery lightBox plugin how you like 23 settings = jQuery.extend({ 24 // Configuration related to overlay 25 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. 26 overlayOpacity: 0.8, // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9 27 // Configuration related to navigation 28 fixedNavigation: true, // (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface. 29 // Configuration related to images 30 imageLoading: 'images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon 31 imageBtnPrev: 'images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image 32 imageBtnNext: 'images/lightbox-btn-next.gif', // (string) Path and the name of the next button image 33 imageBtnClose: 'images/lightbox-btn-close.gif', // (string) Path and the name of the close btn 34 imageBlank: 'images/lightbox-blank.gif', // (string) Path and the name of a blank image (one pixel) 35 // Configuration related to container image box 36 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 37 containerResizeSpeed: 0, // (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default. 38 // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts. 39 txtImage: '',// (string) Specify text "Image" 40 txtOf: '/', // (string) Specify text "of" 41 // Configuration related to keyboard navigation 42 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. 43 keyToPrev: 'p', // (string) (p = previous) Letter to show the previous image 44 keyToNext: 'n', // (string) (n = next) Letter to show the next image. 45 // Don´t alter these variables in any way 46 imageArray: [], 47 activeImage: 0 48 },settings); 49 // Caching the jQuery object with all elements matched 50 var jQueryMatchedObj = this; // This, in this context, refer to jQuery object 51 /** 52 * Initializing the plugin calling the start function 53 * 54 * @return boolean false 55 */ 56 function _initialize() { 57 _start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked 58 return false; // Avoid the browser following the link 59 } 60 /** 61 * Start the jQuery lightBox plugin 62 * 63 * @param object objClicked The object (link) whick the user have clicked 64 * @param object jQueryMatchedObj The jQuery object with all elements matched 65 */ 66 function _start(objClicked,jQueryMatchedObj) { 67 // Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay. 68 $('embed, object, select').css({ 'visibility' : 'hidden' }); 69 // Call the function to create the markup structure; style some elements; assign events in some elements. 70 _set_interface(); 71 // Unset total images in imageArray 72 settings.imageArray.length = 0; 73 // Unset image active information 74 settings.activeImage = 0; 75 // We have an image set? Or just an image? Let´s see it. 76 if ( jQueryMatchedObj.length == 1 ) { 77 settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title'))); 78 } else { 79 // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references 80 for ( var i = 0; i < jQueryMatchedObj.length; i++ ) { 81 settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title'))); 82 } 83 } 84 while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) { 85 settings.activeImage++; 86 } 87 // Call the function that prepares image exibition 88 _set_image_to_view(); 89 } 90 /** 91 * Create the jQuery lightBox plugin interface 92 * 93 * The HTML markup will be like that: 94 <div id="jquery-overlay"></div> 95 <div id="jquery-lightbox"> 96 <div id="lightbox-container-image-box"> 97 <div id="lightbox-container-image"> 98 <img src="../fotos/XX.jpg" id="lightbox-image"> 99 <div id="lightbox-nav"> 100 <a href="#" id="lightbox-nav-btnPrev"></a> 101 <a href="#" id="lightbox-nav-btnNext"></a> 102 </div> 103 <div id="lightbox-loading"> 104 <a href="#" id="lightbox-loading-link"> 105 <img src="../images/lightbox-ico-loading.gif"> 106 </a> 107 </div> 108 </div> 109 </div> 110 <div id="lightbox-container-image-data-box"> 111 <div id="lightbox-container-image-data"> 112 <div id="lightbox-image-details"> 113 <span id="lightbox-image-details-caption"></span> 114 <span id="lightbox-image-details-currentNumber"></span> 115 </div> 116 <div id="lightbox-secNav"> 117 <a href="#" id="lightbox-secNav-btnClose"> 118 <img src="../images/lightbox-btn-close.gif"> 119 </a> 120 </div> 121 </div> 122 </div> 123 </div> 124 * 125 */ 126 function _set_interface() { 127 // Apply the HTML markup into body tag 128 $('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>'); 129 // Get page sizes 130 var arrPageSizes = ___getPageSize(); 131 // Style overlay and show it 132 $('#jquery-overlay').css({ 133 backgroundColor: settings.overlayBgColor, 134 opacity: settings.overlayOpacity, 135 width: arrPageSizes[0], 136 height: arrPageSizes[1] 137 }).fadeIn(); 138 // Get page scroll 139 var arrPageScroll = ___getPageScroll(); 140 // Calculate top and left offset for the jquery-lightbox div object and show it 141 $('#jquery-lightbox').css({ 142 // CHANGED BY KRASL - top: arrPageScroll[1] + (arrPageSizes[3] / 10), 143 top: arrPageScroll[1] + 10, 144 left: arrPageScroll[0] 145 }).show(); 146 // Assigning click events in elements to close overlay 147 $('#jquery-overlay,#jquery-lightbox').click(function() { 148 _finish(); 149 }); 150 // Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects 151 $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() { 152 _finish(); 153 return false; 154 }); 155 // If window was resized, calculate the new overlay dimensions 156 $(window).resize(function() { 157 // Get page sizes 158 var arrPageSizes = ___getPageSize(); 159 // Style overlay and show it 160 $('#jquery-overlay').css({ 161 width: arrPageSizes[0], 162 height: arrPageSizes[1] 163 }); 164 // Get page scroll 165 var arrPageScroll = ___getPageScroll(); 166 // Calculate top and left offset for the jquery-lightbox div object and show it 167 $('#jquery-lightbox').css({ 168 // CHANGED BY KRASL - top: arrPageScroll[1] + (arrPageSizes[3] / 10), 169 top: arrPageScroll[1] + 10, 170 left: arrPageScroll[0] 171 }); 172 }); 173 } 174 /** 175 * Prepares image exibition; doing a image´s preloader to calculate it´s size 176 * 177 */ 178 function _set_image_to_view() { // show the loading 179 // Show the loading 180 $('#lightbox-loading').show(); 181 if ( settings.fixedNavigation ) { 182 $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide(); 183 } else { 184 // Hide some elements 185 $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide(); 186 } 187 // Image preload process 188 var objImagePreloader = new Image();
189 objImagePreloader.onload = function() { 190 $('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]); 191 // Perfomance an effect in the image container resizing it 192 _resize_container_image_box(objImagePreloader.width,objImagePreloader.height); 193 // clear onLoad, IE behaves irratically with animated gifs otherwise 194 objImagePreloader.onload=function(){}; 195 }; 196 objImagePreloader.src = settings.imageArray[settings.activeImage][0]; 197 }; 198 /** 199 * Perfomance an effect in the image container resizing it 200 * 201 * @param integer intImageWidth The image´s width that will be showed 202 * @param integer intImageHeight The image´s height that will be showed 203 */ 204 function _resize_container_image_box(intImageWidth,intImageHeight) { 205 // Get current width and height 206 var intCurrentWidth = $('#lightbox-container-image-box').width(); 207 var intCurrentHeight = $('#lightbox-container-image-box').height(); 208 // Get the width and height of the selected image plus the padding 209 var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value 210 var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value 211 // Diferences 212 var intDiffW = intCurrentWidth - intWidth; 213 var intDiffH = intCurrentHeight - intHeight; 214 // Perfomance the effect 215 $('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); }); 216 if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) { 217 if ( $.browser.msie ) { 218 ___pause(250); 219 } else { 220 ___pause(100); 221 } 222 } 223 $('#lightbox-container-image-data-box').css({ width: intImageWidth }); 224 $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) }); 225 }; 226 /** 227 * Show the prepared image 228 * 229 */ 230 function _show_image() { 231 $('#lightbox-loading').hide(); 232 $('#lightbox-image').fadeIn(function() { 233 _show_image_data(); 234 _set_navigation(); 235 }); 236 _preload_neighbor_images(); 237 }; 238 /** 239 * Show the image information 240 * 241 */ 242 function _show_image_data() { 243 // CHANGED BY KRASL - $('#lightbox-container-image-data-box').slideDown('fast'); 244 $('#lightbox-container-image-data-box').show(); 245 $('#lightbox-image-details-caption').hide(); 246 if ( settings.imageArray[settings.activeImage][1] ) { 247 $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show(); 248 } 249 // If we have a image set, display 'Image X of X' 250 if ( settings.imageArray.length > 1 ) { 251 $('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show(); 252 } 253 } 254 /** 255 * Display the button navigations 256 * 257 */ 258 function _set_navigation() { 259 $('#lightbox-nav').show(); 260 261 // Instead to define this configuration in CSS file, we define here. And it´s need to IE. Just. 262 $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' }); 263 264 // Show the prev button, if not the first image in set 265 if ( settings.activeImage != 0 ) { 266 if ( settings.fixedNavigation ) { 267 $('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' }) 268 .unbind() 269 .bind('click',function() { 270 settings.activeImage = settings.activeImage - 1; 271 _set_image_to_view(); 272 return false; 273 }); 274 } else { 275 // Show the images button for Next buttons 276 $('#lightbox-nav-btnPrev').unbind().hover(function() { 277 $(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' }); 278 },function() { 279 $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' }); 280 }).show().bind('click',function() { 281 settings.activeImage = settings.activeImage - 1; 282 _set_image_to_view(); 283 return false; 284 });
285 } 286 } 287 288 // Show the next button, if not the last image in set 289 if ( settings.activeImage != ( settings.imageArray.length -1 ) ) { 290 if ( settings.fixedNavigation ) { 291 $('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' }) 292 .unbind() 293 .bind('click',function() { 294 settings.activeImage = settings.activeImage + 1; 295 _set_image_to_view(); 296 return false; 297 }); 298 } else { 299 // Show the images button for Next buttons 300 $('#lightbox-nav-btnNext').unbind().hover(function() { 301 $(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' }); 302 },function() { 303 $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' }); 304 }).show().bind('click',function() { 305 settings.activeImage = settings.activeImage + 1; 306 _set_image_to_view(); 307 return false; 308 }); 309 } 310 } 311 // Enable keyboard navigation 312 _enable_keyboard_navigation(); 313 } 314 /** 315 * Enable a support to keyboard navigation 316 * 317 */ 318 function _enable_keyboard_navigation() { 319 $(document).keydown(function(objEvent) { 320 _keyboard_action(objEvent); 321 }); 322 } 323 /** 324 * Disable the support to keyboard navigation 325 * 326 */ 327 function _disable_keyboard_navigation() { 328 $(document).unbind(); 329 } 330 /** 331 * Perform the keyboard actions 332 * 333 */ 334 function _keyboard_action(objEvent) { 335/* CHANGED BY KRASL 336 // To ie 337 if ( objEvent == null ) { 338 keycode = event.keyCode; 339 escapeKey = 27; 340 // To Mozilla 341 } else { 342 keycode = objEvent.keyCode; 343 escapeKey = objEvent.DOM_VK_ESCAPE; 344 } 345*/ 346var keycode = event.keyCode; 347 348var escapeKey; 349if (event.DOM_VK_ESCAPE) { // mozilla 350 escapeKey = event.DOM_VK_ESCAPE; 351} else { // ie 352 escapeKey = 27; 353} 354 355 // Get the key in lower case form 356 key = String.fromCharCode(keycode).toLowerCase(); 357 // Verify the keys to close the ligthBox 358 if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) { 359 _finish(); 360 } 361 // Verify the key to show the previous image 362 if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) { 363 // If we´re not showing the first image, call the previous 364 if ( settings.activeImage != 0 ) { 365 settings.activeImage = settings.activeImage - 1; 366 _set_image_to_view(); 367 _disable_keyboard_navigation(); 368 } 369 } 370 // Verify the key to show the next image 371 if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) { 372 // If we´re not showing the last image, call the next 373 if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) { 374 settings.activeImage = settings.activeImage + 1; 375 _set_image_to_view(); 376 _disable_keyboard_navigation(); 377 } 378 } 379 } 380 /** 381 * Preload prev and next images being showed 382 * 383 */ 384 function _preload_neighbor_images() { 385 if ( (settings.imageArray.length -1) > settings.activeImage ) { 386 objNext = new Image(); 387 objNext.src = settings.imageArray[settings.activeImage + 1][0]; 388 } 389 if ( settings.activeImage > 0 ) { 390 objPrev = new Image(); 391 objPrev.src = settings.imageArray[settings.activeImage -1][0]; 392 } 393 } 394 /** 395 * Remove jQuery lightBox plugin HTML markup 396 * 397 */ 398 function _finish() { 399 $('#jquery-lightbox').remove(); 400 $('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); }); 401 // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay. 402 $('embed, object, select').css({ 'visibility' : 'visible' }); 403 } 404 /** 405 / THIRD FUNCTION 406 * getPageSize() by quirksmode.com 407 * 408 * @return Array Return an array with page width, height and window width, height 409 */ 410 function ___getPageSize() { 411 var xScroll, yScroll; 412 if (window.innerHeight && window.scrollMaxY) { 413 xScroll = window.innerWidth + window.scrollMaxX; 414 yScroll = window.innerHeight + window.scrollMaxY; 415 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 416 xScroll = document.body.scrollWidth; 417 yScroll = document.body.scrollHeight; 418 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 419 xScroll = document.body.offsetWidth; 420 yScroll = document.body.offsetHeight; 421 } 422 var windowWidth, windowHeight;
423 if (self.innerHeight) { // all except Explorer 424 if(document.documentElement.clientWidth){ 425 windowWidth = document.documentElement.clientWidth; 426 } else { 427 windowWidth = self.innerWidth; 428 } 429 windowHeight = self.innerHeight; 430 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 431 windowWidth = document.documentElement.clientWidth; 432 windowHeight = document.documentElement.clientHeight; 433 } else if (document.body) { // other Explorers 434 windowWidth = document.body.clientWidth; 435 windowHeight = document.body.clientHeight; 436 } 437 // for small pages with total height less then height of the viewport 438 if(yScroll < windowHeight){ 439 pageHeight = windowHeight; 440 } else { 441 pageHeight = yScroll; 442 } 443 // for small pages with total width less then width of the viewport 444 if(xScroll < windowWidth){ 445 pageWidth = xScroll; 446 } else { 447 pageWidth = windowWidth; 448 } 449 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 450 return arrayPageSize; 451 }; 452 /** 453 / THIRD FUNCTION 454 * getPageScroll() by quirksmode.com 455 * 456 * @return Array Return an array with x,y page scroll values. 457 */ 458 function ___getPageScroll() { 459 var xScroll, yScroll; 460 if (self.pageYOffset) { 461 yScroll = self.pageYOffset; 462 xScroll = self.pageXOffset; 463 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict 464 yScroll = document.documentElement.scrollTop; 465 xScroll = document.documentElement.scrollLeft; 466 } else if (document.body) {// all other Explorers 467 yScroll = document.body.scrollTop; 468 xScroll = document.body.scrollLeft; 469 } 470 arrayPageScroll = new Array(xScroll,yScroll); 471 return arrayPageScroll; 472 }; 473 /** 474 * Stop the code execution from a escified time in milisecond 475 * 476 */ 477 function ___pause(ms) { 478 var date = new Date(); 479 curDate = null; 480 do { var curDate = new Date(); } 481 while ( curDate - date < ms); 482 }; 483 // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once 484 return this.unbind('click').click(_initialize); 485 }; 486})(jQuery); // Call and execute the function immediately passing the jQuery object
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.