Hi nedash,
Here i have created a sample as per your requirement. So you need to change the desigh as per your requirement and you need to follow the below steps to implement in your code.
Step 1: The main thing is when binding from database you have to assign the image url to href of anchor tag and src/ImageUrl to image tag.
Step 2: Assign attribute as rel to anchor tag with a groupname as i have the group name as group1 in the sample.
Step 3: In document ready function you have to remove the attribute rel from anchor tag if the image src is empty.
Below is the working sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery lightBox plugin</title>
<style type="text/css">
.gallery
{
background-color: #666;
padding: 10px;
width: 110px;
margin-bottom: 10px;
}
.gallery div
{
list-style: none;
}
.gallery div div
{
display: inline;
}
.gallery img
{
border: 5px solid #3e3e3e;
border-width: 5px 5px 20px;
}
.gallery div a:hover img
{
border: 5px solid #fff;
border-width: 5px 5px 20px;
color: #fff;
}
.gallery div a:hover
{
color: #fff;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.lightbox.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.lightbox.css" media="screen" />
<script type="text/javascript">
$(function () {
$('#gallery1 a').each(function () {
if ($(this).find('img').attr('src') == '') {
$(this).removeAttr('rel');
}
});
$('#gallery1 a').lightBox({ fixedNavigation: true });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="gallery1" class="gallery">
<div runat="server">
<div runat="server">
<a href="photos/image1.jpg" rel="lightbox[group1]">
<img src="photos/image1.jpg" height="100px" width="100px" alt="No image" />
</a>
</div>
<div id="Div1" runat="server">
<a href="photos/image2.jpg" rel="lightbox[group1]">
<img src="photos/image2.jpg" height="100px" width="100px" alt="No image" />
</a>
</div>
<div id="Div2" runat="server">
<a href="" rel="lightbox[group1]">
<img src="" height="100px" width="100px" alt="No image" />
</a>
</div>
<div id="Div3" runat="server">
<a href="photos/image3.jpg" rel="lightbox[group1]">
<img src="photos/image3.jpg" height="100px" width="100px" alt="No image" />
</a>
</div>
<div id="Div4" runat="server">
<a href="photos/image4.jpg" rel="lightbox[group1]">
<img src="photos/image4.jpg" height="100px" width="100px" alt="No image" />
</a>
</div>
<div id="Div5" runat="server">
<a href="photos/image5.jpg" rel="lightbox[group1]">
<img src="photos/image5.jpg" height="100px" width="100px" alt="No image" />
</a>
</div>
</div>
</div>
</form>
</body>
</html>
jquery.lightbox.js
(function ($) {
$.fn.lightBox = function (settings) {
// Settings to configure the jQuery lightBox plugin how you like
settings = jQuery.extend({
// Configuration related to overlay
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.
overlayOpacity: 0.8, // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
// Configuration related to navigation
fixedNavigation: false, // (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
// Configuration related to images
/*
imageLoading: '/_scripts/LightBox/images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
imageBtnPrev: '/_scripts/LightBox/images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
imageBtnNext: '/_scripts/LightBox/images/lightbox-btn-next.gif', // (string) Path and the name of the next button image
imageBtnClose: '/_scripts/LightBox/images/lightbox-btn-close.gif', // (string) Path and the name of the close btn
imageBlank: '/_scripts/LightBox/images/lightbox-blank.gif', // (string) Path and the name of a blank image (one pixel)
*/
imageLoading: 'images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
imageBtnPrev: 'images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
imageBtnNext: 'images/lightbox-btn-next.gif', // (string) Path and the name of the next button image
imageBtnClose: 'images/lightbox-btn-close.gif', // (string) Path and the name of the close btn
imageBlank: 'images/lightbox-blank.gif', // (string) Path and the name of a blank image (one pixel)
// Configuration related to container image box
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
containerResizeSpeed: 400, // (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
txtImage: 'Image', // (string) Specify text "Image"
txtOf: 'of', // (string) Specify text "of"
// Configuration related to keyboard navigation
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.
keyToPrev: 'p', // (string) (p = previous) Letter to show the previous image
keyToNext: 'n', // (string) (n = next) Letter to show the next image.
grouping: true, // (boolean) Treats the all the same rel="ligthbox[groupName]" as singular group set *** FULLER
cycle_thru_images: true, // ** Robert Blackwell - if true the next/prev commands cycle around and start again. If false they stop at the 1st and last image respectively
fitToWindow: true, // option to fit preview to window size if the image is too big
showInfo: true, // option to show or hide image info
onOpen: function () {
// Default empty function for when the lightbox is opened
//<-trystant
},
onClose: function () {
// Default empty function for when the lightbox is closed
//<<-trystant
},
// Don�t alter these variables in any way
imageArray: [],
activeImage: 0
}, settings);
// Caching the jQuery object with all elements matched
var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
/**
* Initializing the plugin calling the start function
*
* @return boolean false
*/
function _initialize() {
_start(this, jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
return false; // Avoid the browser following the link
}
/**
* Start the jQuery lightBox plugin
*
* @param object objClicked The object (link) whick the user have clicked
* @param object jQueryMatchedObj The jQuery object with all elements matched
*/
function _start(objClicked, jQueryMatchedObj) {
// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
$('embed, object, select').css({ 'visibility': 'hidden' });
// Call the function to create the markup structure; style some elements; assign events in some elements.
_set_interface();
// Unset total images in imageArray
settings.imageArray.length = 0;
// Unset image active information
settings.activeImage = 0;
/* FULLER */
//alert("fuller ");
var allImages = false;
var rel;
if (settings.grouping) {
//Get rel attribute of clicked element [@Cas]
rel = objClicked.getAttribute('rel'); //[@Cas]
//if rel has the square bracket is a group...
if (rel && rel.indexOf("[") > 0) {
allImages = jQueryMatchedObj;
jQueryMatchedObj = [];
//Search for match rel obj
//alert("rel=" + rel);
allImages.each(function (i, el) {
if (rel == el.getAttribute('rel'))
jQueryMatchedObj.push(el);
});
}
else // if there is not "[" or no rel attribute [@Cas]
{
//No rel attribute or rel without [] group name
jQueryMatchedObj = [];
jQueryMatchedObj.push(objClicked);
}
}
/* F */
/*
I hide this modification by
if (jQueryMatchedObj.length == 1) {
if (settings.captionPosition == 'gallery') //<- CaptionPosition MOD
var position = jQuery(objClicked).parent().next().html();
else
var position = objClicked.getAttribute('title');
settings.imageArray.push(new Array(objClicked.getAttribute('href'), position));
} else {
// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
for (var i = 0; i < jQueryMatchedObj.length; i++) {
if (settings.captionPosition != 'gallery') {
var position = jQueryMatchedObj[i].getAttribute('title');
settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'), position));
} else {
if (i > 1) {
if (!(jQueryMatchedObj[i - 1].getAttribute('href') != jQueryMatchedObj[i].getAttribute('href') && jQuery(jQueryMatchedObj[i - 1]).parent().parent().children().children().attr('href') == jQuery(jQueryMatchedObj[i]).parent().parent().children().children().attr('href'))) {
var position = jQuery(jQueryMatchedObj[i]).parent().next().html();
settings.imageArray.push(new Array(jQuery(jQueryMatchedObj[i]).parent().parent().children().children().attr('href'), position));
}
} else
{
var position = jQuery(jQueryMatchedObj[i]).parent().next().html();
settings.imageArray.push(new Array(jQuery(jQueryMatchedObj[i]).parent().parent().children().children().attr('href'), position));
}
}
}
}
*/
//Debug - matched obj mod
//log(jQueryMatchedObj.length);
// We have an image set? Or just an image? Let?s see it.
if (jQueryMatchedObj.length == 1) {
settings.imageArray.push(new Array(objClicked.getAttribute('href'), objClicked.getAttribute('title')));
} else {
// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
for (var i = 0; i < jQueryMatchedObj.length; i++) {
settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'), jQueryMatchedObj[i].getAttribute('title')));
}
}
//debug
//log(jQueryMatchedObj.length);
while (settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href')) {
settings.activeImage++;
}
/* FULLER */
if (settings.grouping && allImages) {
jQueryMatchedObj = allImages;
allImages = false;
}
/* F */
//Debug alert(settings.activeImage);
// Call the function that prepares image exibition
_set_image_to_view();
// Call the function specified in the onStart configuration setting
settings.onOpen.call(); //<<-trystant
}
//Log alert
function log(msg) {
alert(msg);
}
/**
* Create the jQuery lightBox plugin interface
*
* The HTML markup will be like that:
<div id="jquery-overlay"></div>
<div id="jquery-lightbox">
<div id="lightbox-container-image-box">
<div id="lightbox-container-image">
<img src="../fotos/XX.jpg" id="lightbox-image">
<div 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="../images/lightbox-ico-loading.gif">
</a>
</div>
</div>
</div>
<div id="lightbox-container-image-data-box">
<div id="lightbox-container-image-data">
<div id="lightbox-image-leftNav">
<a href="#" id="lightbox-leftNav-btnPrev">
<img src="../images/lightbox-btn-prev.gif">
</a>
<a href="#" id="lightbox-secNav-btnNext">
<img src="../images/lightbox-btn-next.gif">
</a>
</div>
<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="../images/lightbox-btn-close.gif">
</a>
</div>
</div>
</div>
</div>
*
*/
function _set_interface() {
// Apply the HTML markup into body tag
//$('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>');
// This is the html expanded so I can read it [Robert Mod]
var htmlLightBox =
'<div id="jquery-overlay"></div>\n' +
'<div id="jquery-lightbox">\n' +
' <div id="lightbox-container-image-box">\n' +
' <div id="lightbox-container-image">\n' +
' <img id="lightbox-image">\n' +
' <div style="" id="lightbox-nav">\n' +
' <a href="#" id="lightbox-nav-btnPrev"></a>\n' +
' <a href="#" id="lightbox-nav-btnNext"></a>\n' +
' </div>\n' +
' <div id="lightbox-loading">\n' +
' <a href="#" id="lightbox-loading-link">\n' +
' <img src="' + settings.imageLoading + '"></a>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n' +
' <div id="lightbox-container-image-data-box">\n' +
' <div id="lightbox-container-image-data" >\n' +
' <div id="lightbox-image-details">\n' +
' <span id="lightbox-image-details-caption"></span>\n' +
' <span id="lightbox-image-details-currentNumber"></span>\n' +
' </div>\n' +
' <div id="lightbox-secNav">\n' +
' <a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n' +
'</div>';
$('body').append(htmlLightBox);
// Get page sizes
var arrPageSizes = ___getPageSize();
// Style overlay and show it
$('#jquery-overlay').css({
backgroundColor: settings.overlayBgColor,
opacity: settings.overlayOpacity,
width: arrPageSizes[0],
height: arrPageSizes[1]
}).fadeIn();
// Get page scroll
var arrPageScroll = ___getPageScroll();
// Calculate top and left offset for the jquery-lightbox div object and show it
$('#jquery-lightbox').css({
//top: arrPageScroll[1] + (arrPageSizes[3] / 10), //<<- Originale
// Alfersoft mod
top: arrPageScroll[1] + (arrPageSizes[3] / 20),
left: arrPageScroll[0]
}).show();
// Assigning click events in elements to close overlay
$('#jquery-overlay,#jquery-lightbox').click(function () {
_finish();
});
// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function () {
_finish();
return false;
});
// If window was resized, calculate the new overlay dimensions
$(window).resize(function () {
// Get page sizes
var arrPageSizes = ___getPageSize();
// Style overlay and show it
$('#jquery-overlay').css({
width: arrPageSizes[0],
height: arrPageSizes[1]
});
// Get page scroll
var arrPageScroll = ___getPageScroll();
// Calculate top and left offset for the jquery-lightbox div object and show it
$('#jquery-lightbox').css({
//top: arrPageScroll[1] + (arrPageSizes[3] / 10), < - Original - Altermod
top: arrPageScroll[1] + (arrPageSizes[3] / 20),
left: arrPageScroll[0]
});
});
}
/**
* Prepares image exibition; doing a image�s preloader to calculate it�s size
*
*/
function _set_image_to_view() { // show the loading
//log(settings.activeImage);
//[@Cas Fix] Stop the animation of slidedown of the databox and hide it
//this fix the bug of the data-box when you change the image really fast with the keyboard 22/06/2012
$('#lightbox-container-image-data-box').stop(true, true).hide();
// Show the loading
$('#lightbox-loading').show();
if (settings.fixedNavigation) {
$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
} else {
// Hide some elements
$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
}
// Image preload process
var objImagePreloader = new Image();
objImagePreloader.onload = function () {
$('#lightbox-image').attr('src', settings.imageArray[settings.activeImage][0]);
// Perfomance an effect in the image container resizing it
//@cas Altersoft fit mod with parameter
if (settings.fitToWindow) {
_adjust_image_size(objImagePreloader);
}
else {
_resize_container_image_box(objImagePreloader.width, objImagePreloader.height); // clear onLoad, IE behaves irratically with animated gifs otherwise
}
// clear onLoad, IE behaves irratically with animated gifs otherwise
objImagePreloader.onload = function () { };
};
objImagePreloader.src = settings.imageArray[settings.activeImage][0];
};
/**
* Perfomance an effect in the image container resizing it
*
* @param integer intImageWidth The image�s width that will be showed
* @param integer intImageHeight The image�s height that will be showed
*/
function _resize_container_image_box(intImageWidth, intImageHeight) {
// Get current width and height
var intCurrentWidth = $('#lightbox-container-image-box').width();
var intCurrentHeight = $('#lightbox-container-image-box').height();
// Get the width and height of the selected image plus the padding
var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image�s width and the left and right padding value
var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image�s height and the left and right padding value
// Diferences
var intDiffW = intCurrentWidth - intWidth;
var intDiffH = intCurrentHeight - intHeight;
// Perfomance the effect
$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight }, settings.containerResizeSpeed, function () { _show_image(); });
if ((intDiffW == 0) && (intDiffH == 0)) {
if ($.browser.msie) {
___pause(250);
} else {
___pause(100);
}
}
$('#lightbox-container-image-data-box').css({ width: intImageWidth });
$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
};
/**
* Show the prepared image
*
*/
function _show_image() {
$('#lightbox-loading').hide();
$('#lightbox-image').fadeIn(function () {
_show_image_data();
_set_navigation();
});
_preload_neighbor_images();
};
/**
* Show the image information
*
*/
function _show_image_data() {
//@Cas Fix - the slideDown should be perform AFTER the caption hide/show otw
//the box slideDown to the old calculated height and if you change image from a very long description
//to a small one the detail box slide down to the old height (showing a white space) and after "make a jump" to right height
//$('#lightbox-container-image-data-box').slideDown('fast'); //Original Position
//$('#lightbox-container-image-data-box').slideDown('slow'); //Proof height error - cas
$('#lightbox-image-details-caption').hide();
if (settings.imageArray[settings.activeImage][1]) {
$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
}
// If we have a image set, display 'Image X of X'
//if ( settings.imageArray.length > 1 ) {
if (settings.showInfo && (settings.imageArray.length > 1)) { //<- Alfersoft mod
$('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + (settings.activeImage + 1) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
}
//Cas Fix 22/06/2012
$('#lightbox-container-image-data-box').slideDown('fast');
}
/**
* Display the button navigations
* Display the button navigations - modified by Robert Blackwell to implement cycle_thru_images
*/
function _set_navigation() {
$('#lightbox-nav').show();
// Instead to define this configuration in CSS file, we define here. And it�s need to IE. Just.
$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' });
// Show the prev button, if not the first image in set
if (settings.activeImage != 0 || (settings.imageArray.length > 1 && settings.cycle_thru_images)) { //Robert Mod
if (settings.fixedNavigation) {
$('#lightbox-nav-btnPrev').css({ 'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
.unbind()
.bind('click', function () {
_set_prev_image(); //Robert Cycle Mod
//settings.activeImage = settings.activeImage - 1;
_set_image_to_view();
return false;
});
} else {
// Show the images button for Next buttons
$('#lightbox-nav-btnPrev').unbind().hover(function () {
$(this).css({ 'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
}, function () {
$(this).css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' });
}).show().bind('click', function () {
//settings.activeImage = settings.activeImage - 1;
_set_prev_image(); //Robert Cycle Mod
_set_image_to_view();
return false;
});
}
}
// Show the next button, if not the last image in set
if (settings.activeImage != (settings.imageArray.length - 1) || (settings.imageArray.length > 1 && settings.cycle_thru_images)) { //Robert Cycle Mod
if (settings.fixedNavigation) {
$('#lightbox-nav-btnNext').css({ 'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
.unbind()
.bind('click', function () {
_set_next_image(); //Robert Cycle Mod
//settings.activeImage = settings.activeImage + 1;
_set_image_to_view();
return false;
});
} else {
// Show the images button for Next buttons
$('#lightbox-nav-btnNext').unbind().hover(function () {
$(this).css({ 'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
}, function () {
$(this).css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' });
}).show().bind('click', function () {
/*settings.activeImage = settings.activeImage + 1;*/
_set_next_image(); //Robert Cycle Mod
_set_image_to_view();
return false;
});
}
}
// Enable keyboard navigation
_enable_keyboard_navigation();
}
/**
* Enable a support to keyboard navigation
* Enable a support to keyboard navigation - modified by Robert Blackwell to use named function as handler
* modified bt Claudio Casanovi - fix enter key multiple lightbox activation
*/
function _enable_keyboard_navigation() {
//log("keyboardbind");
// $(document).keydown(function(objEvent) {
// _keyboard_action(objEvent);
// });
$(document).bind("keydown", _keyboard_action); //Robert Blackwell
}
/**
* Disable the support to keyboard navigation
* Disable the support to keyboard navigation. Modified by Robert Blackwell to unhooked named handler
*/
function _disable_keyboard_navigation() {
//log("keyboard - UNbind");
//$(document).unbind();
$(document).unbind("keydown", _keyboard_action); // Robert Blackwell
}
/**
* Perform the keyboard actions
* Formward and back use arrow keys, or n/Next p/Prev
* Close is ESC, Cclose, xX
* Stops the event proagating to other handlers
* On close disconnects itself from the keydown event.
* On Close Calls _final() to remove the popup display
*
*/
function _keyboard_action(objEvent) {
// To ie
if (objEvent == null) {
keycode = event.keyCode;
escapeKey = 27;
// To Mozilla
} else {
keycode = objEvent.keyCode;
// Robert Blackwell - this was not working correctly on Safari
escapeKey = (undefined != objEvent.DOM_VK_ESCAPE) ? objEvent.DOM_VK_ESCAPE : 27;
//escapeKey = objEvent.DOM_VK_ESCAPE;
}
// Get the key in lower case form
key = String.fromCharCode(keycode).toLowerCase();
//log("keyboard action");
//log("Key > " + key + ", keycode > " + keycode);
// Verify the keys to close the ligthBox
if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
_finish();
//Robert Blackwell - unhook the specific handler and stop event propagation
objEvent.stopPropagation();
$(document).unbind("keydown", _keyboard_action);
return false;
}
// Verify the key to show the previous image
if ((key == settings.keyToPrev) || (keycode == 37)) {
// If we�re not showing the first image, call the previous
// Cas - add cycle check, so if cycle is disable I don't make refresh on the
// same image + CasMod 25/06/2012 - disable nav if there is only 1 image also if cycle is activated...
if (settings.activeImage != 0 || (settings.imageArray.length > 1 && settings.cycle_thru_images)) {
/*settings.activeImage = settings.activeImage - 1;*/
_set_prev_image(); //Robert Cycle Mod
_set_image_to_view();
_disable_keyboard_navigation();
// Robert Blackwell stop event propagation
objEvent.stopPropagation();
return false;
}
}
// Verify the key to show the next image
if ((key == settings.keyToNext) || (keycode == 39)) {
//alert("jQueryMatchedObj >"+ jQueryMatchedObj.length);
//alert("settings.imageArray.length >" + settings.imageArray.length);
// If we�re not showing the last image, call the next
if (settings.activeImage != (settings.imageArray.length - 1) || (settings.imageArray.length > 1 && settings.cycle_thru_images)) {
//settings.activeImage = settings.activeImage + 1;
_set_next_image(); //Robert Cycle Mod
_set_image_to_view();
_disable_keyboard_navigation();
// Robert Blackwell - stop event propagation
objEvent.stopPropagation();
return false;
}
}
// Fix Cas - Enter key when lightbox is open cause a new instance of lightbox and all is a mess...
// 22/06/2012
if ((keycode == 13)) { //EnterKey = 13
//Cas Fix - Stop propagation of enter key, so only one instance of lightbox active
objEvent.stopPropagation();
return false;
}
}
/**
* Preload prev and next images being showed
* Cas 25/06/2012 Fix this function to handle correct�y the neighbor with cycle
*/
function _preload_neighbor_images() {
//Load NextImage
if (settings.activeImage < (settings.imageArray.length - 1)) {
objNext = new Image();
objNext.src = settings.imageArray[settings.activeImage + 1][0];
}
else if (settings.cycle_thru_images) {
//CasMod:If the current is last, the next is the first if Cycle is active
objNext = new Image();
objNext.src = settings.imageArray[0][0];
}
//Load PrevImage
if (settings.activeImage > 0) {
objPrev = new Image();
objPrev.src = settings.imageArray[settings.activeImage - 1][0];
}
else if (settings.cycle_thru_images) {
//CasMod:the prev image of the first is the last
objPrev = new Image();
objPrev.src = settings.imageArray[settings.imageArray.length - 1][0];
}
}
/**
* Remove jQuery lightBox plugin HTML markup
*/
function _finish() {
settings.onClose.call(); //<- trystant
$('#jquery-lightbox').remove();
$('#jquery-overlay').fadeOut(function () { $('#jquery-overlay').remove(); });
// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
$('embed, object, select').css({ 'visibility': 'visible' });
_disable_keyboard_navigation(); //Cas Fix [@Cas]
//if you don't detach keyboard event, the next activation
//attach a new handler and the function is called multiple time and skip images...
}
/**
/ THIRD FUNCTION
* getPageSize() by quirksmode.com
*
* @return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
if (document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if (yScroll < windowHeight) {
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if (xScroll < windowWidth) {
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
return arrayPageSize;
};
/**
/ THIRD FUNCTION
* getPageScroll() by quirksmode.com
*
* @return Array Return an array with x,y page scroll values.
*/
function ___getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
arrayPageScroll = new Array(xScroll, yScroll);
return arrayPageScroll;
};
/**
* Stop the code execution from a escified time in milisecond
*
*/
function ___pause(ms) {
var date = new Date();
curDate = null;
do { var curDate = new Date(); }
while (curDate - date < ms);
};
/**
* Robert Blackwell - computes the index of the next image taking settings.cycle_thru_images into account
* @name _next_image
* @returns index value of next image
* @method
*/
function _next_image() {
if (settings.cycle_thru_images)
result = (settings.activeImage == (settings.imageArray.length - 1)) ? 0 : settings.activeImage + 1;
else
result = (settings.activeImage == (settings.imageArray.length - 1)) ? (settings.imageArray.length - 1) : settings.activeImage + 1;
return result;
}
/* Robert Blackwell Aux Function Start */
/**
* Robert Blackwell
* Sets the activeImage value to the next image taking settings.cycle_thru_images into account
*/
function _set_next_image() {
settings.activeImage = _next_image();
}
/**
* Robert Blackwell
* Computes the index of the prev image taking settings.cycle_thru_images into account
*/
function _prev_image() {
if (settings.cycle_thru_images)
result = (settings.activeImage != 0) ? settings.activeImage - 1 : settings.imageArray.length - 1;
else
result = (settings.activeImage != 0) ? settings.activeImage - 1 : 0;
return result;
}
/**
* Robert Blackwell
* Sets the activeImage value to the prev image taking settings.cycle_thru_images into account
*/
function _set_prev_image() {
settings.activeImage = _prev_image();
}
/* Robert Blackwell Aux Function End */
/*********************************************************************************
* alfersoft customization
******************************************************************************** */
function _adjust_image_size(objImagePreloader) {
// get image size
var imgWidth = objImagePreloader.width;
var imgHeight = objImagePreloader.height;
var arrayPageSize = ___getPageSize();
// calculate proportions
var imageProportion = imgWidth / imgHeight;
var winProportion = arrayPageSize[2] / arrayPageSize[3];
if (imageProportion > winProportion) {
// calculate max width base on page width
var maxWidth = arrayPageSize[2] - (settings.containerBorderSize * 2) - (arrayPageSize[2] / 10);
var maxHeight = Math.round(maxWidth / imageProportion);
} else {
// calculate max height base on page height
var maxHeight = arrayPageSize[3] - (settings.containerBorderSize * 2) - (arrayPageSize[3] / 10) - 40;
var maxWidth = Math.round(maxHeight * imageProportion);
}
if (imgWidth > maxWidth || imgHeight > maxHeight) {
imgWidth = maxWidth;
imgHeight = maxHeight;
}
$('#lightbox-image').attr('width', imgWidth);
$('#lightbox-image').attr('height', imgHeight);
_resize_container_image_box(imgWidth, imgHeight);
};
// Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
return this.unbind('click').click(_initialize);
};
})(jQuery); // Call and execute the function immediately passing the jQuery object
jquery.lightbox.css
#jquery-overlay
{
position: absolute;
top: 0;
left: 0;
z-index: 90;
width: 100%;
height: 500px;
}
#jquery-lightbox
{
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 100;
text-align: center;
line-height: 0;
}
#jquery-lightbox a img
{
border: none;
}
#lightbox-container-image-box
{
position: relative;
background-color: #fff;
width: 250px;
height: 250px;
margin: 0 auto;
}
#lightbox-container-image
{
padding: 10px;
}
#lightbox-loading
{
position: absolute;
top: 40%;
left: 0%;
height: 25%;
width: 100%;
text-align: center;
line-height: 0;
}
#lightbox-nav
{
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 10;
}
#lightbox-container-image-box > #lightbox-nav
{
left: 0;
}
#lightbox-nav a
{
outline: none;
}
#lightbox-nav-btnPrev, #lightbox-nav-btnNext
{
width: 49%;
height: 100%;
zoom: 1;
display: block;
}
#lightbox-nav-btnPrev
{
left: 0;
float: left;
}
#lightbox-nav-btnNext
{
right: 0;
float: right;
}
#lightbox-container-image-data-box
{
font: 10px Verdana, Helvetica, sans-serif;
background-color: #fff;
margin: 0 auto;
line-height: 1.4em;
overflow: auto;
width: 100%;
padding: 0 10px 0;
}
#lightbox-container-image-data
{
padding: 0 10px;
color: #666;
}
#lightbox-container-image-data #lightbox-image-details
{
width: 70%;
float: left;
text-align: left;
}
#lightbox-image-details
{
padding-bottom: 1.0em; /* CasFix Issue X */
}
#lightbox-image-details-caption
{
font-weight: bold;
}
#lightbox-image-details-currentNumber
{
display: block;
clear: left; /*padding-bottom: 1.0em; */ /* CasFix Issue X */
}
#lightbox-secNav-btnClose
{
width: 66px;
float: right;
padding-bottom: 0.7em;
}
Screenshot