Newer
Older
/**
* jQuery Lightbox
* @author
* <http://www.huddletogether.com/projects/lightbox2/>
* Also partially based on the jQuery Lightbox by Warren Krewenki
* <http://warren.mesozen.com>
*
* Permission has been granted to Mark Ashmead & other Drupal Lightbox2 module
* maintainers to distribute this file via Drupal.org
* Under GPL license.
*
* Slideshow, iframe and video functionality added by Stella Power.
*/
var Lightbox = {
overlayOpacity : 0.8, // Controls transparency of shadow overlay.
overlayColor : '000', // Controls colour of shadow overlay.
disableCloseClick : true,
// Controls the order of the lightbox resizing animation sequence.
resizeSequence: 0, // 0: simultaneous, 1: width then height, 2: height then width.
resizeSpeed: 'normal', // Controls the speed of the lightbox resizing animation.
fadeInSpeed: 'normal', // Controls the speed of the image and overlay appearance.
slideDownSpeed: 'slow', // Controls the speed of the image details appearance.
Stella Power
committed
minWidth: 240,
borderSize : 10,
boxColor : 'fff',
fontColor : '000',
topPosition : '',
infoHeight: 20,
alternative_layout : false,
Stella Power
committed
total : 0,
disableResize : false,
disableZoom : false,
Stella Power
committed
loopItems : false,
keysClose : ['c', 'x', 27],
keysPrevious : ['p', 37],
keysNext : ['n', 39],
keysZoom : ['z'],
keysPlayPause : [32],
// Slideshow options.
slideInterval : 5000, // In milliseconds.
showPlayPause : true,
autoExit : true,
pauseOnNextClick : false, // True to pause the slideshow when the "Next" button is clicked.
pauseOnPrevClick : true, // True to pause the slideshow when the "Prev" button is clicked.
slideIdCount : 0,
Stella Power
committed
loopSlides : false,
// Video and modal options.
Stella Power
committed
enableVideo : false,
isModal : false,
modalWidth : 400,
modalHeight : 400,
modalHTML : null,
Stella Power
committed
// Iframe options.
isLightframe : false,
iframe_width : 600,
iframe_height : 400,
Stella Power
committed
// Constructor runs on completion of the DOM loading. Calls initList
// and then the function inserts html at the bottom of the page which is used
// to display the shadow overlay and the image container.
initialize: function() {
var s = Drupal.settings.lightbox2;
Lightbox.overlayOpacity = s.overlay_opacity;
Lightbox.overlayColor = s.overlay_color;
Lightbox.disableCloseClick = s.disable_close_click;
Lightbox.resizeSequence = s.resize_sequence;
Lightbox.resizeSpeed = s.resize_speed;
Lightbox.fadeInSpeed = s.fade_in_speed;
Lightbox.slideDownSpeed = s.slide_down_speed;
Lightbox.borderSize = s.border_size;
Lightbox.boxColor = s.box_color;
Lightbox.fontColor = s.font_color;
Lightbox.topPosition = s.top_position;
Lightbox.rtl = s.rtl;
Lightbox.loopItems = s.loop_items;
Lightbox.keysClose = s.keys_close.split(" ");
Lightbox.keysPrevious = s.keys_previous.split(" ");
Lightbox.keysNext = s.keys_next.split(" ");
Lightbox.keysZoom = s.keys_zoom.split(" ");
Lightbox.keysPlayPause = s.keys_play_pause.split(" ");
Lightbox.disableResize = s.disable_resize;
Lightbox.disableZoom = s.disable_zoom;
Lightbox.slideInterval = s.slideshow_interval;
Lightbox.showPlayPause = s.show_play_pause;
Lightbox.autoExit = s.slideshow_automatic_exit;
Lightbox.pauseOnNextClick = s.pause_on_next_click;
Lightbox.pauseOnPrevClick = s.pause_on_previous_click;
Lightbox.loopSlides = s.loop_slides;
Lightbox.alternative_layout = s.use_alt_layout;
Lightbox.iframe_width = s.iframe_width;
Lightbox.iframe_height = s.iframe_height;
Lightbox.iframe_border = s.iframe_border;
Lightbox.enableVideo = s.enable_video;
// Attach lightbox to any links with lightbox rels.
Lightbox.initList();
// Make the lightbox divs.
var output = '<div id="overlay" style="display: none;"></div>\
<div id="lightbox" style="display: none;">\
<div id="outerImageContainer"></div>\
<div id="imageDataContainer" class="clearfix">\
<div id="imageData"></div>\
</div>\
</div>';
var loading = '<div id="loading"><a href="#" id="loadingLink"></a></div>';
var modal = '<div id="modalContainer" style="display: none;"></div>';
Stella Power
committed
var frame = '<div id="frameContainer" style="display: none;"></div>';
var imageContainer = '<div id="imageContainer" style="display: none;"></div>';
var details = '<div id="imageDetails"></div>';
var bottomNav = '<div id="bottomNav"></div>';
var image = '<img id="lightboxImage" />';
var hoverNav = '<div id="hoverNav"><a id="prevLink" href="#"></a><a id="nextLink" href="#"></a></div>';
var frameNav = '<div id="frameHoverNav"><a id="framePrevLink" href="#"></a><a id="frameNextLink" href="#"></a></div>';
var caption = '<span id="caption"></span>';
var numberDisplay = '<span id="numberDisplay"></span>';
var close = '<a id="bottomNavClose" href="#"></a>';
var zoom = '<a id="bottomNavZoom" href="#"></a>';
var zoomOut = '<a id="bottomNavZoomOut" href="#"></a>';
var pause = '<a id="lightshowPause" href="#" style="display: none;"></a>';
var play = '<a id="lightshowPlay" href="#" style="display: none;"></a>';
$("body").append(output);
$('#outerImageContainer').append(modal + frame + imageContainer + loading);
if (!s.use_alt_layout) {
$('#imageContainer').append(image + hoverNav);
$('#imageData').append(frameNav + details + bottomNav);
$('#imageDetails').append(caption + numberDisplay);
$('#bottomNav').append(close + zoom + zoomOut + pause + play);
else {
$('#outerImageContainer').append(bottomNav);
$('#imageContainer').append(image);
$('#bottomNav').append(close + zoom + zoomOut);
$('#imageData').append(hoverNav + details);
$('#imageDetails').append(caption + numberDisplay + pause + play);
}
// Setup onclick handlers.
if (Lightbox.disableCloseClick) {
$('#overlay').click(function() { Lightbox.end(); return false; } ).hide();
}
Stella Power
committed
$('#loadingLink, #bottomNavClose').click(function() { Lightbox.end('forceClose'); return false; } );
$('#prevLink, #framePrevLink').click(function() { Lightbox.changeData(Lightbox.activeImage - 1); return false; } );
$('#nextLink, #frameNextLink').click(function() { Lightbox.changeData(Lightbox.activeImage + 1); return false; } );
$('#bottomNavZoom').click(function() { Lightbox.changeData(Lightbox.activeImage, true); return false; } );
$('#bottomNavZoomOut').click(function() { Lightbox.changeData(Lightbox.activeImage, false); return false; } );
$('#lightshowPause').click(function() { Lightbox.togglePlayPause("lightshowPause", "lightshowPlay"); return false; } );
$('#lightshowPlay').click(function() { Lightbox.togglePlayPause("lightshowPlay", "lightshowPause"); return false; } );
// Fix positioning of Prev and Next links.
$('#prevLink, #nextLink, #framePrevLink, #frameNextLink').css({ 'paddingTop': Lightbox.borderSize + 'px'});
$('#imageContainer, #frameContainer, #modalContainer').css({ 'padding': Lightbox.borderSize + 'px'});
$('#outerImageContainer, #imageDataContainer, #bottomNavClose').css({'backgroundColor': '#' + Lightbox.boxColor, 'color': '#'+Lightbox.fontColor});
if (Lightbox.alternative_layout) {
$('#bottomNavZoom, #bottomNavZoomOut').css({'bottom': Lightbox.borderSize + 'px', 'right': Lightbox.borderSize + 'px'});
}
// Force navigation links to always be displayed
$('#prevLink, #nextLink').addClass("force_show_nav");
}
// Loops through anchor tags looking for 'lightbox', 'lightshow' and
// 'lightframe', etc references and applies onclick events to appropriate
// links. You can rerun after dynamically adding images w/ajax.
// Attach lightbox to any links with rel 'lightbox', 'lightshow' or
// 'lightframe', etc.
$("a[@rel^='lightbox'], area[@rel^='lightbox']").click(function() {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, false, false, false, false);
return false;
});
$("a[@rel^='lightshow'], area[@rel^='lightshow']").click(function() {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, true, false, false, false);
return false;
});
$("a[@rel^='lightframe'], area[@rel^='lightframe']").click(function() {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, false, true, false, false);
Stella Power
committed
if (Lightbox.enableVideo) {
$("a[@rel^='lightvideo'], area[@rel^='lightvideo']").click(function() {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Stella Power
committed
Lightbox.start(this, false, false, true, false);
return false;
});
}
Stella Power
committed
$("a[@rel^='lightmodal'], area[@rel^='lightmodal'], #lightboxAutoModal").click(function() {
Stella Power
committed
$('#lightbox').unbind('click');
Lightbox.start(this, false, false, false, true);
// Display overlay and lightbox. If image is part of a set, add siblings to
start: function(imageLink, slideshow, lightframe, lightvideo, lightmodal) {
Lightbox.isPaused = false;
// Replaces hideSelectBoxes() and hideFlash() calls in original lightbox2.
// Stretch overlay to fill page and fade in.
var arrayPageSize = Lightbox.getPageSize();
$("#overlay").hide().css({
'width': '100%',
'zIndex': '10090',
'height': arrayPageSize[1] + 'px',
'backgroundColor' : '#' + Lightbox.overlayColor
});
// Detect OS X FF2 opacity + flash issue.
if (lightvideo && this.detectMacFF2()) {
$("#overlay").removeClass("overlay_default");
$("#overlay").addClass("overlay_macff2");
}
else {
$("#overlay").removeClass("overlay_macff2");
$("#overlay").addClass("overlay_default");
$("#overlay").css({'opacity' : Lightbox.overlayOpacity});
}
$("#overlay").fadeIn(Lightbox.fadeInSpeed);
Lightbox.isSlideshow = slideshow;
Lightbox.isLightframe = lightframe;
Lightbox.isModal = lightmodal;
Lightbox.imageArray = [];
var anchors = $(imageLink.tagName);
var rel_parts = Lightbox.parseRel(imageLink);
var rel = rel_parts["rel"];
var rel_group = rel_parts["group"];
var title = (rel_parts["title"] ? rel_parts["title"] : imageLink.title);
var rel_style = null;
var i = 0;
Stella Power
committed
if ($(imageLink).attr('id') == 'lightboxAutoModal') {
Stella Power
committed
Lightbox.imageArray.push(['#lightboxAutoModal > *', title, rel_style, 1]);
Stella Power
committed
else {
// Handle lightbox images with no grouping.
if ((rel == 'lightbox' || rel == 'lightshow') && !rel_group) {
Lightbox.imageArray.push([imageLink.href, title]);
}
Stella Power
committed
// Handle iframes with no grouping.
else if ((rel == 'lightframe' || rel == 'lightmodal') && !rel_group) {
Stella Power
committed
Lightbox.imageArray.push([imageLink.href, title, rel_style]);
}
Stella Power
committed
// Handle video.
else if (rel == "lightvideo") {
// rel_group contains style information for videos.
Stella Power
committed
Lightbox.imageArray.push([imageLink.href, title, rel_style]);
}
Stella Power
committed
// Handle iframes and lightbox & slideshow images.
else if (rel == 'lightbox' || rel == 'lightshow' || rel == 'lightframe' || rel == 'lightmodal') {
// Loop through anchors and add them to imageArray.
for (i = 0; i < anchors.length; i++) {
anchor = anchors[i];
if (anchor.href && $(anchor).attr('rel')) {
var rel_data = Lightbox.parseRel(anchor);
var anchor_title = (rel_data["title"] ? rel_data["title"] : anchor.title);
if (rel_data["rel"] == rel) {
if (rel_data["group"] == rel_group) {
if (Lightbox.isLightframe || Lightbox.isModal) {
Stella Power
committed
}
Lightbox.imageArray.push([anchor.href, anchor_title, rel_style]);
}
Stella Power
committed
// Remove duplicates.
for (i = 0; i < Lightbox.imageArray.length; i++) {
for (j = Lightbox.imageArray.length-1; j > i; j--) {
if (Lightbox.imageArray[i][0] == Lightbox.imageArray[j][0]) {
Lightbox.imageArray.splice(j,1);
}
Stella Power
committed
while (Lightbox.imageArray[Lightbox.imageNum][0] != imageLink.href) {
Lightbox.imageNum++;
}
if (Lightbox.isSlideshow && Lightbox.showPlayPause && Lightbox.isPaused) {
$('#lightshowPlay').show();
$('#lightshowPause').hide();
}
// Calculate top and left offset for the lightbox.
var arrayPageScroll = Lightbox.getPageScroll();
var lightboxTop = arrayPageScroll[1] + (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
var lightboxLeft = arrayPageScroll[0];
$('#lightbox').css({
'zIndex': '10500',
'top': lightboxTop + 'px',
'left': lightboxLeft + 'px'
Stella Power
committed
Lightbox.total = Lightbox.imageArray.length;
// Hide most elements and preload image in preparation for resizing image
if (Lightbox.inprogress === false) {
Stella Power
committed
if (Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) {
if (imageNum >= Lightbox.total) imageNum = 0;
if (imageNum < 0) imageNum = Lightbox.total - 1;
}
if (Lightbox.isSlideshow) {
for (var i = 0; i < Lightbox.slideIdCount; i++) {
window.clearTimeout(Lightbox.slideIdArray[i]);
}
}
Lightbox.inprogress = true;
Lightbox.activeImage = imageNum;
if (Lightbox.disableResize && !Lightbox.isSlideshow) {
$('#loading').css({'zIndex': '10500'}).show();
if (!Lightbox.alternative_layout) {
$('#imageContainer').hide();
}
Stella Power
committed
$('#frameContainer, #modalContainer, #lightboxImage').hide();
$('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
$('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
// Preload image content, but not iframe pages.
if (!Lightbox.isLightframe && !Lightbox.isVideo && !Lightbox.isModal) {
imgPreloader = new Image();
imgPreloader.onerror = function() { Lightbox.imgNodeLoadingError(this); };
imgPreloader.onload = function() {
var photo = document.getElementById('lightboxImage');
photo.src = Lightbox.imageArray[Lightbox.activeImage][0];
Stella Power
committed
photo.alt = Lightbox.imageArray[Lightbox.activeImage][1];
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
// Resize code.
var arrayPageSize = Lightbox.getPageSize();
var targ = { w:arrayPageSize[2] - (Lightbox.borderSize * 2), h:arrayPageSize[3] - (Lightbox.borderSize * 6) - (Lightbox.infoHeight * 4) - (arrayPageSize[3] / 10) };
var orig = { w:imgPreloader.width, h:imgPreloader.height };
// Image is very large, so show a smaller version of the larger image
// with zoom button.
var ratio = 1.0; // Shrink image with the same aspect.
$('#bottomNavZoomOut, #bottomNavZoom').hide();
if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
ratio = ((targ.w / orig.w) < (targ.h / orig.h)) ? targ.w / orig.w : targ.h / orig.h;
if (!Lightbox.disableZoom && !Lightbox.isSlideshow) {
$('#bottomNavZoom').css({'zIndex': '10500'}).show();
imageWidth = Math.floor(orig.w * ratio);
imageHeight = Math.floor(orig.h * ratio);
}
else {
$('#bottomNavZoom').hide();
// Only display zoom out button if the image is zoomed in already.
if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
// Only display zoom out button if not a slideshow and if the
// buttons aren't disabled.
if (!Lightbox.disableResize && Lightbox.isSlideshow === false && !Lightbox.disableZoom) {
$('#bottomNavZoomOut').css({'zIndex': '10500'}).show();
photo.style.width = (imageWidth) + 'px';
photo.style.height = (imageHeight) + 'px';
// Clear onLoad, IE behaves irratically with animated gifs otherwise.
imgPreloader.onload = function() {};
};
imgPreloader.src = Lightbox.imageArray[Lightbox.activeImage][0];
Stella Power
committed
imgPreloader.alt = Lightbox.imageArray[Lightbox.activeImage][1];
}
// Set up frame size, etc.
Stella Power
committed
var src = Lightbox.imageArray[Lightbox.activeImage][0];
$('#frameContainer').append('<iframe id="lightboxFrame" style="display: none;" src="'+src+'"></iframe>');
if (!Lightbox.iframe_border) {
$('#lightboxFrame').css({'border': 'none'});
$('#lightboxFrame').attr('frameborder', '0');
}
var iframe = document.getElementById('lightboxFrame');
var iframeStyles = Lightbox.imageArray[Lightbox.activeImage][2];
iframe = Lightbox.setStyles(iframe, iframeStyles);
Lightbox.resizeContainer(parseInt(iframe.width, 10), parseInt(iframe.height, 10));
else if (Lightbox.isVideo || Lightbox.isModal) {
var container = document.getElementById('modalContainer');
var modalStyles = Lightbox.imageArray[Lightbox.activeImage][2];
container = Lightbox.setStyles(container, modalStyles);
if (Lightbox.isVideo) {
Lightbox.modalHeight = parseInt(container.height, 10);
Lightbox.modalWidth = parseInt(container.width, 10);
Lightvideo.startVideo(Lightbox.imageArray[Lightbox.activeImage][0]);
}
Lightbox.resizeContainer(parseInt(container.width, 10), parseInt(container.height, 10));
// imgNodeLoadingError()
imgNodeLoadingError: function(image) {
var original_image = Lightbox.imageArray[Lightbox.activeImage][0];
if (s.display_image_size !== "") {
original_image = original_image.replace(new RegExp("."+s.display_image_size), "");
}
Lightbox.imageArray[Lightbox.activeImage][0] = original_image;
image.onerror = function() { Lightbox.imgLoadingError(image); };
image.src = original_image;
},
// imgLoadingError()
imgLoadingError: function(image) {
var s = Drupal.settings.lightbox2;
Lightbox.imageArray[Lightbox.activeImage][0] = s.default_image;
image.src = s.default_image;
},
// resizeContainer()
resizeContainer: function(imgWidth, imgHeight) {
Stella Power
committed
imgWidth = (imgWidth < Lightbox.minWidth ? Lightbox.minWidth : imgWidth);
this.widthCurrent = $('#outerImageContainer').width();
this.heightCurrent = $('#outerImageContainer').height();
var widthNew = (imgWidth + (Lightbox.borderSize * 2));
var heightNew = (imgHeight + (Lightbox.borderSize * 2));
// Scalars based on change from old to new.
this.xScale = ( widthNew / this.widthCurrent) * 100;
this.yScale = ( heightNew / this.heightCurrent) * 100;
// Calculate size difference between new and old image, and resize if
// necessary.
wDiff = this.widthCurrent - widthNew;
hDiff = this.heightCurrent - heightNew;
$('#modalContainer').css({'width': imgWidth, 'height': imgHeight});
// Detect animation sequence.
if (Lightbox.resizeSequence) {
var animate1 = {width: widthNew};
var animate2 = {height: heightNew};
if (Lightbox.resizeSequence == 2) {
animate1 = {height: heightNew};
animate2 = {width: widthNew};
}
$('#outerImageContainer').animate(animate1, Lightbox.resizeSpeed).animate(animate2, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
}
// Simultaneous.
else {
$('#outerImageContainer').animate({'width': widthNew, 'height': heightNew}, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
}
// If new and old image are same size and no scaling transition is
// necessary. Do a quick pause to prevent image flicker.
if ((hDiff === 0) && (wDiff === 0)) {
if ($.browser.msie) {
Lightbox.pause(250);
}
else {
Lightbox.pause(100);
}
}
var s = Drupal.settings.lightbox2;
if (!s.use_alt_layout) {
$('#prevLink, #nextLink').css({'height': imgHeight + 'px'});
}
$('#imageDataContainer').css({'width': widthNew + 'px'});
// Display image and begin preloading neighbors.
if (Lightbox.isLightframe || Lightbox.isVideo || Lightbox.isModal) {
Lightbox.updateDetails();
if (Lightbox.isLightframe) {
$('#frameContainer').show();
if ($.browser.safari) {
$('#lightboxFrame').css({'zIndex': '10500'}).show();
$('#lightboxFrame').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
if (Lightbox.isVideo) {
$("#modalContainer").html(Lightbox.modalHTML);
$("#modalContainer").click(function() { return false; } );
}
else {
Stella Power
committed
var src = unescape(Lightbox.imageArray[Lightbox.activeImage][0]);
if (Lightbox.imageArray[Lightbox.activeImage][3]) {
$(src).appendTo("#modalContainer");
}
else {
$("#modalContainer").load(src);
}
$('#modalContainer').unbind('click');
}
$('#modalContainer').css({'zIndex': '10500'}).show();
// Handle display of image content.
if ($.browser.safari) {
$('#lightboxImage').css({'zIndex': '10500'}).show();
$('#lightboxImage').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
}
Lightbox.updateDetails();
this.preloadNeighborImages();
Lightbox.inprogress = false;
// Slideshow specific stuff.
Stella Power
committed
if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
if (Lightbox.autoExit) {
Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.end('slideshow');}, Lightbox.slideInterval);
Stella Power
committed
if (!Lightbox.isPaused && Lightbox.total > 1) {
Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.changeData(Lightbox.activeImage + 1);}, Lightbox.slideInterval);
Stella Power
committed
if (Lightbox.showPlayPause && Lightbox.total > 1 && !Lightbox.isPaused) {
$('#lightshowPause').show();
$('#lightshowPlay').hide();
}
Stella Power
committed
else if (Lightbox.showPlayPause && Lightbox.total > 1) {
$('#lightshowPause').hide();
$('#lightshowPlay').show();
}
}
// Adjust the page overlay size.
var arrayPageSize = Lightbox.getPageSize();
var arrayPageScroll = Lightbox.getPageScroll();
var pageHeight = arrayPageSize[1];
if (Lightbox.isZoomedIn && arrayPageSize[1] > arrayPageSize[3]) {
var lightboxTop = (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
pageHeight = pageHeight + arrayPageScroll[1] + lightboxTop;
}
$('#overlay').css({'height': pageHeight + 'px', 'width': arrayPageSize[0] + 'px'});
// Gecko browsers (e.g. Firefox, SeaMonkey, etc) don't handle pdfs as
// expected.
if ($.browser.mozilla) {
if (Lightbox.imageArray[Lightbox.activeImage][0].indexOf(".pdf") != -1) {
setTimeout(function () {
document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
}, 1000);
}
}
},
// updateDetails()
// Display caption, image number, and bottom nav.
updateDetails: function() {
$("#imageDataContainer").hide();
var caption = Lightbox.imageArray[Lightbox.activeImage][1];
Stella Power
committed
if (!caption) caption = ' ';
$('#caption').html(caption).css({'zIndex': '10500'}).show();
// If image is part of set display 'Image x of x'.
Stella Power
committed
if (Lightbox.total > 1) {
var currentImage = Lightbox.activeImage + 1;
if (!Lightbox.isLightframe) {
numberDisplay = s.image_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
}
else {
numberDisplay = s.page_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
}
$('#numberDisplay').html(numberDisplay).css({'zIndex': '10500'}).show();
$("#imageDataContainer").hide().slideDown(Lightbox.slideDownSpeed);
if (Lightbox.rtl == 1) {
Lightbox.updateNav();
},
// updateNav()
// Display appropriate previous and next hover navigation.
updateNav: function() {
$('#hoverNav').css({'zIndex': '10500'}).show();
var prevLink = '#prevLink';
var nextLink = '#nextLink';
// Slideshow is separated as we need to show play / pause button.
Stella Power
committed
if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage !== 0) {
$(prevLink).css({'zIndex': '10500'}).show().click(function() {
if (Lightbox.pauseOnPrevClick) {
Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
}
Lightbox.changeData(Lightbox.activeImage - 1); return false;
// If not last image in set, display next image button.
Stella Power
committed
if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage != (Lightbox.total - 1)) {
$(nextLink).css({'zIndex': '10500'}).show().click(function() {
if (Lightbox.pauseOnNextClick) {
Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
}
Lightbox.changeData(Lightbox.activeImage + 1); return false;
// Safari browsers need to have hide() called again.
Stella Power
committed
else {
if (Lightbox.isLightframe && !Lightbox.alternative_layout) {
$('#hoverNav').css({'zIndex': '10500'}).hide();
$('#frameHoverNav').css({'zIndex': '10500'}).show();
prevLink = '#framePrevLink';
nextLink = '#frameNextLink';
}
// If not first image in set, display prev image button.
Stella Power
committed
if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage !== 0) {
$(prevLink).css({'zIndex': '10500'}).show().click(function() {
Lightbox.changeData(Lightbox.activeImage - 1); return false;
// Safari browsers need to have hide() called again.
// If not last image in set, display next image button.
Stella Power
committed
if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage != (Lightbox.total - 1)) {
$(nextLink).css({'zIndex': '10500'}).show().click(function() {
Lightbox.changeData(Lightbox.activeImage + 1); return false;
// Safari browsers need to have hide() called again.
Stella Power
committed
}
if (!Lightbox.isModal) {
this.enableKeyboardNav();
}
},
// enableKeyboardNav()
enableKeyboardNav: function() {
$(document).bind("keydown", this.keyboardAction);
},
// disableKeyboardNav()
disableKeyboardNav: function() {
$(document).unbind("keydown", this.keyboardAction);
},
// keyboardAction()
keyboardAction: function(e) {
keycode = event.keyCode;
escapeKey = 27;
}
keycode = e.keyCode;
escapeKey = e.DOM_VK_ESCAPE;
}
key = String.fromCharCode(keycode).toLowerCase();
if (Lightbox.checkKey(Lightbox.keysClose, key, keycode)) {
Lightbox.end('forceClose');
// Display previous image (p, <-).
else if (Lightbox.checkKey(Lightbox.keysPrevious, key, keycode)) {
Stella Power
committed
if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage !== 0) {
// Display next image (n, ->).
else if (Lightbox.checkKey(Lightbox.keysNext, key, keycode)) {
Stella Power
committed
if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage != (Lightbox.total - 1)) {
else if (Lightbox.checkKey(Lightbox.keysZoom, key, keycode) && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
}
}
// Toggle play / pause (space).
else if (Lightbox.checkKey(Lightbox.keysPlayPause, key, keycode) && Lightbox.isSlideshow) {
if (Lightbox.isPaused) {
Lightbox.togglePlayPause("lightshowPlay", "lightshowPause");
}
else {
Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
}
},
preloadNeighborImages: function() {
Stella Power
committed
if ((Lightbox.total - 1) > Lightbox.activeImage) {
preloadNextImage = new Image();
preloadNextImage.src = Lightbox.imageArray[Lightbox.activeImage + 1][0];
}
if (Lightbox.activeImage > 0) {
preloadPrevImage = new Image();
preloadPrevImage.src = Lightbox.imageArray[Lightbox.activeImage - 1][0];
}
end: function(caller) {
var closeClick = (caller == 'slideshow' ? false : true);
if (Lightbox.isSlideshow && Lightbox.isPaused && !closeClick) {
return;
}
// To prevent double clicks on navigation links.
if (Lightbox.inprogress === true && caller != 'forceClose') {
return;
}
Lightbox.disableKeyboardNav();
$('#lightbox').hide();
$("#overlay").fadeOut();
Lightbox.isPaused = true;
Lightbox.inprogress = false;
// Replaces calls to showSelectBoxes() and showFlash() in original
// lightbox2.
Lightbox.toggleSelectsFlash('visible');
if (Lightbox.isSlideshow) {
for (var i = 0; i < Lightbox.slideIdCount; i++) {
window.clearTimeout(Lightbox.slideIdArray[i]);
$('#lightshowPause, #lightshowPlay').hide();
else if (Lightbox.isLightframe) {
Stella Power
committed
$('#frameContainer').empty().hide();
else if (Lightbox.isVideo || Lightbox.isModal) {
Stella Power
committed
$('#modalContainer').hide().html("");
},
// getPageScroll()
// Returns array with x,y page scroll values.
getPageScroll : function() {
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;
arrayPageScroll = [xScroll,yScroll];
return arrayPageScroll;
},
// Returns array with page width, height and window width, height.
// Core code from - quirksmode.com.
// Edit for Firefox by pHaez.
getPageSize : function() {
var xScroll, yScroll;
if (document.body.scrollHeight > document.body.offsetHeight) {
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
}
else if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
}
// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari.
else {
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;
}
// Explorer 6 Strict Mode.
else if (document.documentElement && document.documentElement.clientHeight) {
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;
}
pageHeight = yScroll;
}
// For small pages with total width less then width of the viewport.
pageWidth = windowWidth;
pageWidth = xScroll;
arrayPageSize = [pageWidth, pageHeight, windowWidth, windowHeight];
return arrayPageSize;
},
// pause(numberMillis)
pause : function(ms) {
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while (curDate - date < ms);
// toggleSelectsFlash()
// Hide / unhide select lists and flash objects as they appear above the
// lightbox in some browsers.
toggleSelectsFlash: function (state) {
if (state == 'visible') {
$("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").show();
}
else if (state == 'hide') {
$("select:visible, embed:visible, object:visible").addClass("lightbox_hidden");
$("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").hide();
}
},
var parts = [];
Stella Power
committed
parts["rel"] = parts["title"] = parts["group"] = parts["style"] = null;
if (!$(link).attr('rel')) return parts;
parts["rel"] = $(link).attr('rel').match(/\w+/)[0];
if ($(link).attr('rel').match(/\[(.*)\]/)) {
var info = $(link).attr('rel').match(/\[(.*?)\]/)[1].split('|');
parts["group"] = info[0];
parts["style"] = info[1];
}
if ($(link).attr('rel').match(/\[.*\]\[(.*)\]/)) {
parts["title"] = $(link).attr('rel').match(/\[.*\]\[(.*)\]/)[1];
return parts;
},
// setStyles()
setStyles: function(item, styles) {
Stella Power
committed
if (!styles) return item;
item.width = Lightbox.iframe_width;
item.height = Lightbox.iframe_height;
for (var i = 0; i< stylesArray.length; i++) {
if (stylesArray[i].indexOf('width:') >= 0) {
var w = stylesArray[i].replace('width:', '');