(function ($) {
$(function(){
function placeholder_support() {
var i = document.createElement('input');
return 'placeholder' in i;
}
if(!placeholder_support()) {
$('input, textarea').each(function(){
var placeholder = $(this).attr('placeholder');
$(this).focus(function(){
if($(this).val() == placeholder) {
$(this).val('').css('color', '#000000');
}
}).blur(function(){
if($(this).val() == '') {
$(this).val(placeholder).css('color', '#666666');
}
});
if($(this).val() == '') {
$(this).val(placeholder).css('color', '#666666');
}
});
$('form').each(function(){
$(this).submit(function(){
$('input, textarea', this).each(function(){
if($(this).val() == $(this).attr('placeholder')) {
$(this).val('');
}
});
return true;
});
});
}
});
}(jQuery));
;
// Image Node Auto-Format with Auto Image Grouping.
// Original version by Steve McKenzie.
// Altered by Stella Power for jQuery version.
(function ($) {
function parse_url(url, param) {
param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
url = url.replace(/&/, "&");
var regexS = "[\\?&]"+param+"=([^]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
if (results === null) {
return "";
}
else {
return results[1];
}
}
function lightbox2_init_triggers(classes, rel_type, custom_class) {
if (classes == '' || rel_type == 0) {
return;
}
var settings = Drupal.settings.lightbox2;
var link_target = "";
if (settings.node_link_target !== 0) {
link_target = 'target="'+ settings.node_link_target +'"';
}
$("a:has("+classes+")").each(function(i) {
if ((!settings.disable_for_gallery_lists && !settings.disable_for_acidfree_gallery_lists) || (!$(this).parents("td.giAlbumCell").attr("class") && !$(this).parents(".galleries").length && !$(this).parents(".acidfree-folder").length && !$(this).parents(".acidfree-list").length) || ($(this).parents(".galleries").length && !settings.disable_for_gallery_lists) || (($(this).parents(".acidfree-folder").length || $(this).parents(".acidfree-list").length) && !settings.disable_for_acidfree_gallery_lists)) {
var child = $(this).find(classes);
// Ensure the child has a class attribute we can work with.
if ($(child).attr("class")) {
// Set the alt text.
var alt = $(child).attr("alt");
if (!alt) {
alt = "";
}
// Set the image node link text.
var link_text = settings.node_link_text;
var download_link_text = settings.download_link_text;
var rewrite = 1;
// Set the rel attribute.
var rel = "lightbox";
var lightframe = false;
if (rel_type == "lightframe_ungrouped") {
rel = "lightframe[]";
lightframe = true;
}
else if (rel_type == "lightframe") {
lightframe = true;
}
else if (rel_type == "lightbox_ungrouped") {
rel = "lightbox[]";
}
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[" + $(child).attr("class") + "]";
}
// Set the basic href attribute - need to ensure there's no language
// string (e.g. /en) prepended to the URL.
var id = null;
var href = $(child).attr("src");
var download = null;
var orig_href = $(this).attr("href");
var pattern = new RegExp(settings.file_path);
if (orig_href.match(pattern)) {
var lang_pattern = new RegExp(Drupal.settings.basePath + "\\w\\w\\/");
orig_href = orig_href.replace(lang_pattern, Drupal.settings.basePath);
}
var frame_href = orig_href;
// Handle flickr images.
if ($(child).attr("class").match("flickr-photo-img") ||
$(child).attr("class").match("flickr-photoset-img")) {
href = $(child).attr("src").replace("_s.", ".").replace("_t.", ".").replace("_m.", ".").replace("_b.", ".");
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[flickr]";
if ($(child).parents("div.block-flickr").attr("class")) {
id = $(child).parents("div.block-flickr").attr("id");
rel = rel_type + "["+ id +"]";
}
}
download = href;
}
// Handle "image-img_assist_custom" images.
else if ($(child).filter("img[class*=img_assist_custom]").size()) {
// Image assist uses "+" signs for spaces which doesn't work for
// normal links.
if (settings.display_image_size != "original") {
orig_href = orig_href.replace(/\+/, " ");
href = $(child).attr("src").replace(new RegExp("\\.img_assist_custom-[0-9]+x[0-9]+"), ((settings.display_image_size === "")?settings.display_image_size:"."+ settings.display_image_size));
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[node_images]";
}
if (lightframe) {
frame_href = orig_href + "/lightbox2";
}
}
else {
rewrite = 0;
}
}
// Handle "inline" images.
else if ($(child).attr("class").match("inline")) {
href = orig_href;
}
// Handle gallery2 block images.
else if ($(child).attr("class").match("ImageFrame_image") || $(child).attr("class").match("ImageFrame_none")) {
var thumb_id = parse_url(href, "g2_itemId");
var new_id = parse_url(orig_href, "g2_itemId");
if (new_id && thumb_id) {
var g2pattern = new RegExp("g2_itemId="+thumb_id);
var replacement = "g2_itemId="+ new_id;
href = href.replace(g2pattern, replacement);
}
rel = rel_type + "[gallery2]";
if ($(child).parents("div.block-gallery").attr("class")) {
id = $(child).parents("div.block-gallery").attr("id");
rel = rel_type + "["+ id +"]";
}
download = href;
}
// Set the href attribute.
else if (settings.image_node_sizes != '()' && !custom_class) {
if (settings.display_image_size != "original") {
href = $(child).attr("src").replace(new RegExp(settings.image_node_sizes), ((settings.display_image_size === "")?settings.display_image_size:"."+ settings.display_image_size)).replace(/(image\/view\/\d+)(\/[\w\-]*)/, ((settings.display_image_size === "")?"$1/_original":"$1/"+ settings.display_image_size));
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[node_images]";
if ($(child).parents("div.block-multiblock,div.block-image").attr("class")) {
id = $(child).parents("div.block-multiblock,div.block-image").attr("id");
rel = rel_type + "["+ id +"]";
}
}
download = $(child).attr("src").replace(new RegExp(settings.image_node_sizes), "").replace(/(image\/view\/\d+)(\/[\w\-]*)/, "$1/_original");
if (lightframe) {
frame_href = orig_href + "/lightbox2";
}
}
else {
rewrite = 0;
}
}
// Modify the image url.
var img_title = $(child).attr("title");
if (!img_title) {
img_title = $(this).attr("title");
if (!img_title) {
img_title = $(child).attr("alt");
}
$(child).attr({title: img_title});
}
if (lightframe) {
href = frame_href;
}
if (rewrite) {
if (!custom_class) {
var title_link = "";
if (link_text.length) {
title_link = "
"+ link_text + "";
}
if (download_link_text.length && download) {
title_link = title_link + " - " + download_link_text + "";
}
rel = rel + "[" + img_title + title_link + "]";
$(this).attr({
rel: rel,
href: href
});
}
else {
if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
rel = rel_type + "[" + $(child).attr("class") + "]";
if ($(child).parents("div.block-image").attr("class")) {
id = $(child).parents("div.block-image").attr("id");
rel = rel_type + "["+ id +"]";
}
}
rel = rel + "[" + img_title + "]";
$(this).attr({
rel: rel,
href: orig_href
});
}
}
}
}
});
}
function lightbox2_image_nodes() {
var settings = Drupal.settings.lightbox2;
// Don't do it on the image assist popup selection screen.
var img_assist = document.getElementById("img_assist_thumbs");
if (!img_assist) {
// Select the enabled image types.
lightbox2_init_triggers(settings.trigger_lightbox_classes, "lightbox_ungrouped");
lightbox2_init_triggers(settings.custom_trigger_classes, settings.custom_class_handler, true);
lightbox2_init_triggers(settings.trigger_lightbox_group_classes, "lightbox");
lightbox2_init_triggers(settings.trigger_slideshow_classes, "lightshow");
lightbox2_init_triggers(settings.trigger_lightframe_classes, "lightframe_ungrouped");
lightbox2_init_triggers(settings.trigger_lightframe_group_classes, "lightframe");
}
}
Drupal.behaviors.initAutoLightbox = {
attach: function(context, settings) {
lightbox2_image_nodes();
}
};
//End jQuery block
}(jQuery));
;
/* $Id: lightbox.js,v 1.5.2.6.2.136 2010/09/24 08:39:40 snpower Exp $ */
/**
* jQuery Lightbox
* @author
* Stella Power,
*
* Based on Lightbox v2.03.3 by Lokesh Dhakar
*
* Also partially based on the jQuery Lightbox by Warren Krewenki
*
*
* 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;
(function($) {
Lightbox = {
auto_modal : false,
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 appearance.
slideDownSpeed: 'slow', // Controls the speed of the image details appearance.
minWidth: 240,
borderSize : 10,
boxColor : 'fff',
fontColor : '000',
topPosition : '',
infoHeight: 20,
alternative_layout : false,
imageArray : [],
imageNum : null,
total : 0,
activeImage : null,
inprogress : false,
disableResize : false,
disableZoom : false,
isZoomedIn : false,
rtl : false,
loopItems : false,
keysClose : ['c', 'x', 27],
keysPrevious : ['p', 37],
keysNext : ['n', 39],
keysZoom : ['z'],
keysPlayPause : [32],
// Slideshow options.
slideInterval : 5000, // In milliseconds.
showPlayPause : true,
autoStart : 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.
slideIdArray : [],
slideIdCount : 0,
isSlideshow : false,
isPaused : false,
loopSlides : false,
// Iframe options.
isLightframe : false,
iframe_width : 600,
iframe_height : 400,
iframe_border : 1,
// Video and modal options.
enableVideo : false,
flvPlayer : '/flvplayer.swf',
flvFlashvars : '',
isModal : false,
isVideo : false,
videoId : false,
modalWidth : 400,
modalHeight : 400,
modalHTML : null,
// initialize()
// Constructor runs on completion of the DOM loading.
// 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.showCaption = s.show_caption;
Lightbox.autoStart = s.slideshow_automatic_start;
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;
if (s.enable_video) {
Lightbox.flvPlayer = s.flvPlayer;
Lightbox.flvFlashvars = s.flvFlashvars;
}
// Make the lightbox divs.
var layout_class = (s.use_alt_layout ? 'lightbox2-alt-layout' : 'lightbox2-orig-layout');
var output = '\
';
var loading = '';
var modal = '';
var frame = '';
var imageContainer = '';
var details = '';
var bottomNav = '';
var image = '';
var hoverNav = '';
var frameNav = '';
var hoverNav = '';
var frameNav = '';
var caption = '';
var numberDisplay = '';
var close = '';
var zoom = '';
var zoomOut = '';
var pause = '';
var play = '';
$("body").append(output);
$('#outerImageContainer').append(modal + frame + imageContainer + loading);
if (!s.use_alt_layout) {
$('#imageContainer').append(image + hoverNav);
$('#imageData').append(details + bottomNav);
$('#imageDetails').append(caption + numberDisplay);
$('#bottomNav').append(frameNav + 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) {
$('#lightbox2-overlay').click(function() { Lightbox.end(); return false; } ).hide();
}
$('#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.
$('#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'});
}
else if (Lightbox.rtl == 1 && Drupal.settings.lightbox2.useragent.search('MSIE') !== -1) {
$('#bottomNavZoom, #bottomNavZoomOut').css({'left': '0px'});
}
// Force navigation links to always be displayed
if (s.force_show_nav) {
$('#prevLink, #nextLink').addClass("force_show_nav");
}
},
// initList()
// 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.
initList : function(context) {
if (context == undefined || context == null) {
context = document;
}
// Attach lightbox to any links with rel 'lightbox', 'lightshow' or
// 'lightframe', etc.
$("a[rel^='lightbox']:not(.lightbox-processed), area[rel^='lightbox']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, false, false, false, false);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
$("a[rel^='lightshow']:not(.lightbox-processed), area[rel^='lightshow']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, true, false, false, false);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
$("a[rel^='lightframe']:not(.lightbox-processed), area[rel^='lightframe']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, false, true, false, false);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
if (Lightbox.enableVideo) {
$("a[rel^='lightvideo']:not(.lightbox-processed), area[rel^='lightvideo']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
if (Lightbox.disableCloseClick) {
$('#lightbox').unbind('click');
$('#lightbox').click(function() { Lightbox.end('forceClose'); } );
}
Lightbox.start(this, false, false, true, false);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
}
$("a[rel^='lightmodal']:not(.lightbox-processed), area[rel^='lightmodal']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
$('#lightbox').unbind('click');
// Add classes from the link to the lightbox div - don't include lightbox-processed
$('#lightbox').addClass($(this).attr('class'));
$('#lightbox').removeClass('lightbox-processed');
Lightbox.start(this, false, false, false, true);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
$("#lightboxAutoModal:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
Lightbox.auto_modal = true;
$('#lightbox').unbind('click');
Lightbox.start(this, false, false, false, true);
if (e.preventDefault) { e.preventDefault(); }
return false;
});
},
// start()
// Display overlay and lightbox. If image is part of a set, add siblings to
// imageArray.
start: function(imageLink, slideshow, lightframe, lightvideo, lightmodal) {
Lightbox.isPaused = !Lightbox.autoStart;
// Replaces hideSelectBoxes() and hideFlash() calls in original lightbox2.
Lightbox.toggleSelectsFlash('hide');
// Stretch overlay to fill page and fade in.
var arrayPageSize = Lightbox.getPageSize();
$("#lightbox2-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()) {
$("#lightbox2-overlay").removeClass("overlay_default");
$("#lightbox2-overlay").addClass("overlay_macff2");
$("#lightbox2-overlay").css({'opacity' : null});
}
else {
$("#lightbox2-overlay").removeClass("overlay_macff2");
$("#lightbox2-overlay").addClass("overlay_default");
$("#lightbox2-overlay").css({'opacity' : Lightbox.overlayOpacity});
}
$("#lightbox2-overlay").fadeIn(Lightbox.fadeInSpeed);
Lightbox.isSlideshow = slideshow;
Lightbox.isLightframe = lightframe;
Lightbox.isVideo = lightvideo;
Lightbox.isModal = lightmodal;
Lightbox.imageArray = [];
Lightbox.imageNum = 0;
var anchors = $(imageLink.tagName);
var anchor = null;
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;
if (rel_parts["flashvars"]) {
Lightbox.flvFlashvars = Lightbox.flvFlashvars + '&' + rel_parts["flashvars"];
}
// Set the title for image alternative text.
var alt = imageLink.title;
if (!alt) {
var img = $(imageLink).find("img");
if (img && $(img).attr("alt")) {
alt = $(img).attr("alt");
}
else {
alt = title;
}
}
if ($(imageLink).attr('id') == 'lightboxAutoModal') {
rel_style = rel_parts["style"];
Lightbox.imageArray.push(['#lightboxAutoModal > *', title, alt, rel_style, 1]);
}
else {
// Handle lightbox images with no grouping.
if ((rel == 'lightbox' || rel == 'lightshow') && !rel_group) {
Lightbox.imageArray.push([imageLink.href, title, alt]);
}
// Handle other items with no grouping.
else if (!rel_group) {
rel_style = rel_parts["style"];
Lightbox.imageArray.push([imageLink.href, title, alt, rel_style]);
}
// Handle grouped items.
else {
// Loop through anchors and add them to imageArray.
for (i = 0; i < anchors.length; i++) {
anchor = anchors[i];
if (anchor.href && typeof(anchor.href) == "string" && $(anchor).attr('rel')) {
var rel_data = Lightbox.parseRel(anchor);
var anchor_title = (rel_data["title"] ? rel_data["title"] : anchor.title);
img_alt = anchor.title;
if (!img_alt) {
var anchor_img = $(anchor).find("img");
if (anchor_img && $(anchor_img).attr("alt")) {
img_alt = $(anchor_img).attr("alt");
}
else {
img_alt = title;
}
}
if (rel_data["rel"] == rel) {
if (rel_data["group"] == rel_group) {
if (Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) {
rel_style = rel_data["style"];
}
Lightbox.imageArray.push([anchor.href, anchor_title, img_alt, rel_style]);
}
}
}
}
// 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);
}
}
}
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];
$('#frameContainer, #modalContainer, #lightboxImage').hide();
$('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
$('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
$('#outerImageContainer').css({'width': '250px', 'height': '250px'});
$('#lightbox').css({
'zIndex': '10500',
'top': lightboxTop + 'px',
'left': lightboxLeft + 'px'
}).show();
Lightbox.total = Lightbox.imageArray.length;
Lightbox.changeData(Lightbox.imageNum);
},
// changeData()
// Hide most elements and preload image in preparation for resizing image
// container.
changeData: function(imageNum, zoomIn) {
if (Lightbox.inprogress === false) {
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) {
zoomIn = true;
}
Lightbox.isZoomedIn = zoomIn;
// Hide elements during transition.
$('#loading').css({'zIndex': '10500'}).show();
if (!Lightbox.alternative_layout) {
$('#imageContainer').hide();
}
$('#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) {
$("#lightbox #imageDataContainer").removeClass('lightbox2-alt-layout-data');
imgPreloader = new Image();
imgPreloader.onerror = function() { Lightbox.imgNodeLoadingError(this); };
imgPreloader.onload = function() {
var photo = document.getElementById('lightboxImage');
photo.src = Lightbox.imageArray[Lightbox.activeImage][0];
photo.alt = Lightbox.imageArray[Lightbox.activeImage][2];
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.
if (zoomIn !== true) {
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';
Lightbox.resizeContainer(imageWidth, imageHeight);
// Clear onLoad, IE behaves irratically with animated gifs otherwise.
imgPreloader.onload = function() {};
};
imgPreloader.src = Lightbox.imageArray[Lightbox.activeImage][0];
imgPreloader.alt = Lightbox.imageArray[Lightbox.activeImage][2];
}
// Set up frame size, etc.
else if (Lightbox.isLightframe) {
$("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
var src = Lightbox.imageArray[Lightbox.activeImage][0];
$('#frameContainer').html('');
// Enable swf support in Gecko browsers.
if (Drupal.settings.lightbox2.useragent.search('Mozilla') !== -1 && src.indexOf('.swf') != -1) {
setTimeout(function () {
document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
}, 1000);
}
if (!Lightbox.iframe_border) {
$('#lightboxFrame').css({'border': 'none'});
$('#lightboxFrame').attr('frameborder', '0');
}
var iframe = document.getElementById('lightboxFrame');
var iframeStyles = Lightbox.imageArray[Lightbox.activeImage][3];
iframe = Lightbox.setStyles(iframe, iframeStyles);
Lightbox.resizeContainer(parseInt(iframe.width, 10), parseInt(iframe.height, 10));
}
else if (Lightbox.isVideo || Lightbox.isModal) {
$("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
var container = document.getElementById('modalContainer');
var modalStyles = Lightbox.imageArray[Lightbox.activeImage][3];
container = Lightbox.setStyles(container, modalStyles);
if (Lightbox.isVideo) {
Lightbox.modalHeight = parseInt(container.height, 10) - 10;
Lightbox.modalWidth = parseInt(container.width, 10) - 10;
Lightvideo.startVideo(Lightbox.imageArray[Lightbox.activeImage][0]);
}
Lightbox.resizeContainer(parseInt(container.width, 10), parseInt(container.height, 10));
}
}
},
// imgNodeLoadingError()
imgNodeLoadingError: function(image) {
var s = Drupal.settings.lightbox2;
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) {
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 (Drupal.settings.lightbox2.useragent.search('MSIE') !== -1) {
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'});
},
// showData()
// Display image and begin preloading neighbors.
showData: function() {
$('#loading').hide();
if (Lightbox.isLightframe || Lightbox.isVideo || Lightbox.isModal) {
Lightbox.updateDetails();
if (Lightbox.isLightframe) {
$('#frameContainer').show();
if (Drupal.settings.lightbox2.useragent.search('Safari') !== -1 || Lightbox.fadeInSpeed === 0) {
$('#lightboxFrame').css({'zIndex': '10500'}).show();
}
else {
$('#lightboxFrame').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
}
}
else {
if (Lightbox.isVideo) {
$("#modalContainer").html(Lightbox.modalHTML).click(function(){return false;}).css('zIndex', '10500').show();
}
else {
var src = unescape(Lightbox.imageArray[Lightbox.activeImage][0]);
if (Lightbox.imageArray[Lightbox.activeImage][4]) {
$(src).appendTo("#modalContainer");
$('#modalContainer').css({'zIndex': '10500'}).show();
}
else {
// Use a callback to show the new image, otherwise you get flicker.
$("#modalContainer").hide().load(src, function () {$('#modalContainer').css({'zIndex': '10500'}).show();});
}
$('#modalContainer').unbind('click');
}
// This might be needed in the Lightframe section above.
//$('#modalContainer').css({'zIndex': '10500'}).show();
}
}
// Handle display of image content.
else {
$('#imageContainer').show();
if (Drupal.settings.lightbox2.useragent.search('Safari') !== -1 || Lightbox.fadeInSpeed === 0) {
$('#lightboxImage').css({'zIndex': '10500'}).show();
}
else {
$('#lightboxImage').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
}
Lightbox.updateDetails();
this.preloadNeighborImages();
}
Lightbox.inprogress = false;
// Slideshow specific stuff.
if (Lightbox.isSlideshow) {
if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
if (Lightbox.autoExit) {
Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.end('slideshow');}, Lightbox.slideInterval);
}
}
else {
if (!Lightbox.isPaused && Lightbox.total > 1) {
Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.changeData(Lightbox.activeImage + 1);}, Lightbox.slideInterval);
}
}
if (Lightbox.showPlayPause && Lightbox.total > 1 && !Lightbox.isPaused) {
$('#lightshowPause').show();
$('#lightshowPlay').hide();
}
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;
}
$('#lightbox2-overlay').css({'height': pageHeight + 'px', 'width': arrayPageSize[0] + 'px'});
// Gecko browsers (e.g. Firefox, SeaMonkey, etc) don't handle pdfs as
// expected.
if (Drupal.settings.lightbox2.useragent.search('Mozilla') !== -1) {
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 s = Drupal.settings.lightbox2;
if (s.show_caption) {
var caption = Lightbox.filterXSS(Lightbox.imageArray[Lightbox.activeImage][1]);
if (!caption) caption = '';
$('#caption').html(caption).css({'zIndex': '10500'}).show();
}
// If image is part of set display 'Image x of x'.
var numberDisplay = null;
if (s.image_count && Lightbox.total > 1) {
var currentImage = Lightbox.activeImage + 1;
if (!Lightbox.isLightframe && !Lightbox.isModal && !Lightbox.isVideo) {
numberDisplay = s.image_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
}
else if (Lightbox.isVideo) {
numberDisplay = s.video_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();
}
else {
$('#numberDisplay').hide();
}
$("#imageDataContainer").hide().slideDown(Lightbox.slideDownSpeed, function() {
$("#bottomNav").show();
});
if (Lightbox.rtl == 1) {
$("#bottomNav").css({'float': 'left'});
}
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.
if (Lightbox.isSlideshow) {
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;
});
}
else {
$(prevLink).hide();
}
// If not last image in set, display next image button.
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.
else {
$(nextLink).hide();
}
}
// All other types of content.
else {
if ((Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) && !Lightbox.alternative_layout) {
$('#frameHoverNav').css({'zIndex': '10500'}).show();
$('#hoverNav').css({'zIndex': '10500'}).hide();
prevLink = '#framePrevLink';
nextLink = '#frameNextLink';
}
// If not first image in set, display prev image button.
if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage !== 0) {
// Unbind any other click handlers, otherwise this adds a new click handler
// each time the arrow is clicked.
$(prevLink).css({'zIndex': '10500'}).show().unbind().click(function() {
Lightbox.changeData(Lightbox.activeImage - 1); return false;
});
}
// Safari browsers need to have hide() called again.
else {
$(prevLink).hide();
}
// If not last image in set, display next image button.
if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage != (Lightbox.total - 1)) {
// Unbind any other click handlers, otherwise this adds a new click handler
// each time the arrow is clicked.
$(nextLink).css({'zIndex': '10500'}).show().unbind().click(function() {
Lightbox.changeData(Lightbox.activeImage + 1); return false;
});
}
// Safari browsers need to have hide() called again.
else {
$(nextLink).hide();
}
}
// Don't enable keyboard shortcuts so forms will work.
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) {
if (e === null) { // IE.
keycode = event.keyCode;
escapeKey = 27;
}
else { // Mozilla.
keycode = e.keyCode;
escapeKey = e.DOM_VK_ESCAPE;
}
key = String.fromCharCode(keycode).toLowerCase();
// Close lightbox.
if (Lightbox.checkKey(Lightbox.keysClose, key, keycode)) {
Lightbox.end('forceClose');
}
// Display previous image (p, <-).
else if (Lightbox.checkKey(Lightbox.keysPrevious, key, keycode)) {
if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage !== 0) {
Lightbox.changeData(Lightbox.activeImage - 1);
}
}
// Display next image (n, ->).
else if (Lightbox.checkKey(Lightbox.keysNext, key, keycode)) {
if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage != (Lightbox.total - 1)) {
Lightbox.changeData(Lightbox.activeImage + 1);
}
}
// Zoom in.
else if (Lightbox.checkKey(Lightbox.keysZoom, key, keycode) && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
if (Lightbox.isZoomedIn) {
Lightbox.changeData(Lightbox.activeImage, false);
}
else if (!Lightbox.isZoomedIn) {
Lightbox.changeData(Lightbox.activeImage, true);
}
return false;
}
// 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");
}
return false;
}
},
preloadNeighborImages: function() {
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();
$("#lightbox2-overlay").fadeOut();
Lightbox.isPaused = true;
Lightbox.inprogress = false;
Lightbox.imageArray = [];
Lightbox.imageNum = 0;
// 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) {
$('#frameContainer').empty().hide();
}
else if (Lightbox.isVideo || Lightbox.isModal) {
if (!Lightbox.auto_modal) {
$('#modalContainer').hide().html("");
}
Lightbox.auto_modal = false;
}
},
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com.
getPageScroll : function() {
var xScroll, yScroll;
if (self.pageYOffset || self.pageXOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
}
else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) { // 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 = [xScroll,yScroll];
return arrayPageScroll;
},
// getPageSize()
// 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 (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 than height of the viewport.
if (yScroll < windowHeight) {
pageHeight = windowHeight;
}
else {
pageHeight = yScroll;
}
// For small pages with total width less than width of the viewport.
if (xScroll < windowWidth) {
pageWidth = xScroll;
}
else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(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").not('#lightboxAutoModal select, #lightboxAutoModal embed, #lightboxAutoModal object').addClass("lightbox_hidden");
$("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").hide();
}
},
// parseRel()
parseRel: function (link) {
var parts = [];
parts["rel"] = parts["title"] = parts["group"] = parts["style"] = parts["flashvars"] = 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 (parts["style"] != undefined && parts["style"].match(/flashvars:\s?(.*?);/)) {
parts["flashvars"] = parts["style"].match(/flashvars:\s?(.*?);/)[1];
}
}
if ($(link).attr('rel').match(/\[.*\]\[([\s\S]*)\]/)) {
var title = $(link).attr('rel').match(/\[.*\]\[([\s\S]*)\]/)[1];
parts["title"] = title.replace(/\n/g, '
');
}
return parts;
},
// setStyles()
setStyles: function(item, styles) {
item.width = Lightbox.iframe_width;
item.height = Lightbox.iframe_height;
item.scrolling = "auto";
if (!styles) return item;
var stylesArray = styles.split(';');
for (var i = 0; i< stylesArray.length; i++) {
if (stylesArray[i].indexOf('width:') >= 0) {
var w = stylesArray[i].replace('width:', '');
item.width = jQuery.trim(w);
}
else if (stylesArray[i].indexOf('height:') >= 0) {
var h = stylesArray[i].replace('height:', '');
item.height = jQuery.trim(h);
}
else if (stylesArray[i].indexOf('scrolling:') >= 0) {
var scrolling = stylesArray[i].replace('scrolling:', '');
item.scrolling = jQuery.trim(scrolling);
}
else if (stylesArray[i].indexOf('overflow:') >= 0) {
var overflow = stylesArray[i].replace('overflow:', '');
item.overflow = jQuery.trim(overflow);
}
}
return item;
},
// togglePlayPause()
// Hide the pause / play button as appropriate. If pausing the slideshow also
// clear the timers, otherwise move onto the next image.
togglePlayPause: function(hideId, showId) {
if (Lightbox.isSlideshow && hideId == "lightshowPause") {
for (var i = 0; i < Lightbox.slideIdCount; i++) {
window.clearTimeout(Lightbox.slideIdArray[i]);
}
}
$('#' + hideId).hide();
$('#' + showId).show();
if (hideId == "lightshowPlay") {
Lightbox.isPaused = false;
if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
Lightbox.end();
}
else if (Lightbox.total > 1) {
Lightbox.changeData(Lightbox.activeImage + 1);
}
}
else {
Lightbox.isPaused = true;
}
},
triggerLightbox: function (rel_type, rel_group) {
if (rel_type.length) {
if (rel_group && rel_group.length) {
$("a[rel^='" + rel_type +"\[" + rel_group + "\]'], area[rel^='" + rel_type +"\[" + rel_group + "\]']").eq(0).trigger("click");
}
else {
$("a[rel^='" + rel_type +"'], area[rel^='" + rel_type +"']").eq(0).trigger("click");
}
}
},
detectMacFF2: function() {
var ua = navigator.userAgent.toLowerCase();
if (/firefox[\/\s](\d+\.\d+)/.test(ua)) {
var ffversion = new Number(RegExp.$1);
if (ffversion < 3 && ua.indexOf('mac') != -1) {
return true;
}
}
return false;
},
checkKey: function(keys, key, code) {
return (jQuery.inArray(key, keys) != -1 || jQuery.inArray(String(code), keys) != -1);
},
filterXSS: function(str, allowed_tags) {
var output = "";
var prefix = Drupal.settings.pathPrefix;
if (!prefix) prefix = '';
$.ajax({
url: Drupal.settings.basePath + prefix + '?q=system/lightbox2/filter-xss',
data: {
'string' : str,
'allowed_tags' : allowed_tags
},
type: "POST",
async: false,
dataType: "json",
success: function(data) {
output = data;
}
});
return output;
}
};
// Initialize the lightbox.
Drupal.behaviors.initLightbox = {
attach: function(context) {
$('body:not(.lightbox-processed)', context).addClass('lightbox-processed').each(function() {
Lightbox.initialize();
return false; // Break the each loop.
});
// Attach lightbox to any links with lightbox rels.
Lightbox.initList(context);
$('#lightboxAutoModal', context).triggerHandler('click');
}
};
})(jQuery);
;
(function ($) {
/**
* A progressbar object. Initialized with the given id. Must be inserted into
* the DOM afterwards through progressBar.element.
*
* method is the function which will perform the HTTP request to get the
* progress bar state. Either "GET" or "POST".
*
* e.g. pb = new progressBar('myProgressBar');
* some_element.appendChild(pb.element);
*/
Drupal.progressBar = function (id, updateCallback, method, errorCallback) {
var pb = this;
this.id = id;
this.method = method || 'GET';
this.updateCallback = updateCallback;
this.errorCallback = errorCallback;
// The WAI-ARIA setting aria-live="polite" will announce changes after users
// have completed their current activity and not interrupt the screen reader.
this.element = $('').attr('id', id);
this.element.html('' +
'' +
'
');
};
/**
* Set the percentage and status message for the progressbar.
*/
Drupal.progressBar.prototype.setProgress = function (percentage, message) {
if (percentage >= 0 && percentage <= 100) {
$('div.filled', this.element).css('width', percentage + '%');
$('div.percentage', this.element).html(percentage + '%');
}
$('div.message', this.element).html(message);
if (this.updateCallback) {
this.updateCallback(percentage, message, this);
}
};
/**
* Start monitoring progress via Ajax.
*/
Drupal.progressBar.prototype.startMonitoring = function (uri, delay) {
this.delay = delay;
this.uri = uri;
this.sendPing();
};
/**
* Stop monitoring progress via Ajax.
*/
Drupal.progressBar.prototype.stopMonitoring = function () {
clearTimeout(this.timer);
// This allows monitoring to be stopped from within the callback.
this.uri = null;
};
/**
* Request progress data from server.
*/
Drupal.progressBar.prototype.sendPing = function () {
if (this.timer) {
clearTimeout(this.timer);
}
if (this.uri) {
var pb = this;
// When doing a post request, you need non-null data. Otherwise a
// HTTP 411 or HTTP 406 (with Apache mod_security) error may result.
$.ajax({
type: this.method,
url: this.uri,
data: '',
dataType: 'json',
success: function (progress) {
// Display errors.
if (progress.status == 0) {
pb.displayError(progress.data);
return;
}
// Update display.
pb.setProgress(progress.percentage, progress.message);
// Schedule next timer.
pb.timer = setTimeout(function () { pb.sendPing(); }, pb.delay);
},
error: function (xmlhttp) {
pb.displayError(Drupal.ajaxError(xmlhttp, pb.uri));
}
});
}
};
/**
* Display errors on the page.
*/
Drupal.progressBar.prototype.displayError = function (string) {
var error = $('').html(string);
$(this.element).before(error).hide();
if (this.errorCallback) {
this.errorCallback(this);
}
};
})(jQuery);
;
(function ($) {
Drupal.behaviors.textarea = {
attach: function (context, settings) {
$('.form-textarea-wrapper.resizable', context).once('textarea', function () {
var staticOffset = null;
var textarea = $(this).addClass('resizable-textarea').find('textarea');
var grippie = $('').mousedown(startDrag);
grippie.insertAfter(textarea);
function startDrag(e) {
staticOffset = textarea.height() - e.pageY;
textarea.css('opacity', 0.25);
$(document).mousemove(performDrag).mouseup(endDrag);
return false;
}
function performDrag(e) {
textarea.height(Math.max(32, staticOffset + e.pageY) + 'px');
return false;
}
function endDrag(e) {
$(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);
textarea.css('opacity', 1);
}
});
}
};
})(jQuery);
;
/**
* @file
* JavaScript behaviors for the front-end display of webforms.
*/
(function ($) {
"use strict";
Drupal.behaviors.webform = Drupal.behaviors.webform || {};
Drupal.behaviors.webform.attach = function (context) {
// Calendar datepicker behavior.
Drupal.webform.datepicker(context);
// Conditional logic.
if (Drupal.settings.webform && Drupal.settings.webform.conditionals) {
Drupal.webform.conditional(context);
}
};
Drupal.webform = Drupal.webform || {};
Drupal.webform.datepicker = function (context) {
$('div.webform-datepicker').each(function () {
var $webformDatepicker = $(this);
var $calendar = $webformDatepicker.find('input.webform-calendar');
// Ensure the page we're on actually contains a datepicker.
if ($calendar.length == 0) {
return;
}
var startDate = $calendar[0].className.replace(/.*webform-calendar-start-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
var endDate = $calendar[0].className.replace(/.*webform-calendar-end-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
var firstDay = $calendar[0].className.replace(/.*webform-calendar-day-(\d).*/, '$1');
// Convert date strings into actual Date objects.
startDate = new Date(startDate[0], startDate[1] - 1, startDate[2]);
endDate = new Date(endDate[0], endDate[1] - 1, endDate[2]);
// Ensure that start comes before end for datepicker.
if (startDate > endDate) {
var laterDate = startDate;
startDate = endDate;
endDate = laterDate;
}
var startYear = startDate.getFullYear();
var endYear = endDate.getFullYear();
// Set up the jQuery datepicker element.
$calendar.datepicker({
dateFormat: 'yy-mm-dd',
yearRange: startYear + ':' + endYear,
firstDay: parseInt(firstDay),
minDate: startDate,
maxDate: endDate,
onSelect: function (dateText, inst) {
var date = dateText.split('-');
$webformDatepicker.find('select.year, input.year').val(+date[0]).trigger('change');
$webformDatepicker.find('select.month').val(+date[1]).trigger('change');
$webformDatepicker.find('select.day').val(+date[2]).trigger('change');
},
beforeShow: function (input, inst) {
// Get the select list values.
var year = $webformDatepicker.find('select.year, input.year').val();
var month = $webformDatepicker.find('select.month').val();
var day = $webformDatepicker.find('select.day').val();
// If empty, default to the current year/month/day in the popup.
var today = new Date();
year = year ? year : today.getFullYear();
month = month ? month : today.getMonth() + 1;
day = day ? day : today.getDate();
// Make sure that the default year fits in the available options.
year = (year < startYear || year > endYear) ? startYear : year;
// jQuery UI Datepicker will read the input field and base its date
// off of that, even though in our case the input field is a button.
$(input).val(year + '-' + month + '-' + day);
}
});
// Prevent the calendar button from submitting the form.
$calendar.click(function (event) {
// This event is triggered also when pressing enter when the focus is on
// previous webform components, but we only want to do something when
// we are on the calendar component. By checking the event client x/y
// position we known if it was the user clicking. For keyboard navigators
// simply the focus handles the date picker so we don't have to do
// anything special for them.
if (event.clientX !== 0 && event.clientY !== 0) {
// Focus is only necessary for Safari. But it has no impact on other
// browsers.
$(this).focus();
event.preventDefault();
}
});
// Clear date on backspace or delete.
$calendar.keyup(function (e) {
if (e.keyCode == 8 || e.keyCode == 46) {
$.datepicker._clearDate(this);
}
});
});
};
Drupal.webform.conditional = function (context) {
// Add the bindings to each webform on the page.
$.each(Drupal.settings.webform.conditionals, function (formKey, settings) {
var $form = $('.' + formKey + ':not(.webform-conditional-processed)');
$form.each(function (index, currentForm) {
var $currentForm = $(currentForm);
$currentForm.addClass('webform-conditional-processed');
$currentForm.bind('change', {'settings': settings}, Drupal.webform.conditionalCheck);
// Trigger all the elements that cause conditionals on this form.
Drupal.webform.doConditions($currentForm, settings);
});
});
};
/**
* Event handler to respond to field changes in a form.
*
* This event is bound to the entire form, not individual fields.
*/
Drupal.webform.conditionalCheck = function (e) {
var $triggerElement = $(e.target).closest('.webform-component');
if (!$triggerElement.length) {
return;
}
var $form = $triggerElement.closest('form');
var triggerElementKey = $triggerElement.attr('class').match(/webform-component--[^ ]+/)[0];
var settings = e.data.settings;
if (settings.sourceMap[triggerElementKey]) {
Drupal.webform.doConditions($form, settings);
}
};
/**
* Processes all conditional.
*/
Drupal.webform.doConditions = function ($form, settings) {
var stackPointer;
var resultStack;
/**
* Initializes an execution stack for a conditional group's rules.
*
* Also initializes sub-conditional rules.
*/
function executionStackInitialize(andor) {
stackPointer = -1;
resultStack = [];
executionStackPush(andor);
}
/**
* Starts a new subconditional for the given and/or operator.
*/
function executionStackPush(andor) {
resultStack[++stackPointer] = {
results: [],
andor: andor,
};
}
/**
* Adds a rule's result to the current sub-conditional.
*/
function executionStackAccumulate(result) {
resultStack[stackPointer]['results'].push(result);
}
/**
* Finishes a sub-conditional and adds the result to the parent stack frame.
*/
function executionStackPop() {
// Calculate the and/or result.
var stackFrame = resultStack[stackPointer];
// Pop stack and protect against stack underflow.
stackPointer = Math.max(0, stackPointer - 1);
var $conditionalResults = stackFrame['results'];
var filteredResults = $.map($conditionalResults, function (val) {
return val ? val : null;
});
return stackFrame['andor'] === 'or'
? filteredResults.length > 0
: filteredResults.length === $conditionalResults.length;
}
// Track what has been set/hidden for each target component's elements.
// Hidden elements must be disabled because if they are required and don't
// have a value, they will prevent submission due to html5 validation.
// Each execution of the conditionals adds a temporary class
// webform-disabled-flag so that elements hidden or set can be disabled and
// also be prevented from being re-enabled by another conditional (such as a
// parent fieldset). After processing conditionals, this temporary class
// must be removed in preparation for the next execution of the
// conditionals.
$.each(settings.ruleGroups, function (rgid_key, rule_group) {
var ruleGroup = settings.ruleGroups[rgid_key];
// Perform the comparison callback and build the results for this group.
executionStackInitialize(ruleGroup['andor']);
$.each(ruleGroup['rules'], function (m, rule) {
switch (rule['source_type']) {
case 'component':
var elementKey = rule['source'];
var element = $form.find('.' + elementKey)[0];
var existingValue = settings.values[elementKey] ? settings.values[elementKey] : null;
executionStackAccumulate(window['Drupal']['webform'][rule.callback](element, existingValue, rule['value']));
break;
case 'conditional_start':
executionStackPush(rule['andor']);
break;
case 'conditional_end':
executionStackAccumulate(executionStackPop());
break;
}
});
var conditionalResult = executionStackPop();
$.each(ruleGroup['actions'], function (aid, action) {
var $target = $form.find('.' + action['target']);
var actionResult = action['invert'] ? !conditionalResult : conditionalResult;
switch (action['action']) {
case 'show':
var changed = actionResult != Drupal.webform.isVisible($target);
if (actionResult) {
$target.find('.webform-conditional-disabled:not(.webform-disabled-flag)')
.removeClass('webform-conditional-disabled')
.webformProp('disabled', false);
$target
.removeClass('webform-conditional-hidden')
.show();
$form.find('.chosen-disabled').prev().trigger('chosen:updated.chosen');
}
else {
$target
.hide()
.addClass('webform-conditional-hidden')
.find(':input')
.addClass('webform-conditional-disabled webform-disabled-flag')
.webformProp('disabled', true);
}
if (changed && $target.is('tr')) {
Drupal.webform.restripeTable($target.closest('table').first());
}
break;
case 'require':
var $requiredSpan = $target.find('.form-required, .form-optional').first();
if (actionResult != $requiredSpan.hasClass('form-required')) {
var $targetInputElements = $target.find("input:text,textarea,input[type='email'],select,input:radio,input:checkbox,input:file");
// Rather than hide the required tag, remove it so that other
// jQuery can respond via Drupal behaviors.
Drupal.detachBehaviors($requiredSpan);
$targetInputElements
.webformProp('required', actionResult)
.toggleClass('required', actionResult);
if (actionResult) {
$requiredSpan.replaceWith('*');
}
else {
$requiredSpan.replaceWith('');
}
Drupal.attachBehaviors($requiredSpan);
}
break;
case 'set':
var $texts = $target.find("input:text,textarea,input[type='email']");
var $selects = $target.find('select,select option,input:radio,input:checkbox');
var $markups = $target.filter('.webform-component-markup');
if (actionResult) {
var multiple = $.map(action['argument'].split(','), $.trim);
$selects
.webformVal(multiple)
.webformProp('disabled', true)
.addClass('webform-disabled-flag');
$texts
.val([action['argument']])
.webformProp('readonly', true)
.addClass('webform-disabled-flag');
// A special case is made for markup. It is sanitized with
// filter_xss_admin on the server. otherwise text() should be used
// to avoid an XSS vulnerability. text() however would preclude
// the use of tags like or .
$markups.html(action['argument']);
}
else {
$selects.not('.webform-disabled-flag')
.webformProp('disabled', false);
$texts.not('.webform-disabled-flag')
.webformProp('readonly', false);
// Markup not set? Then restore original markup as provided in
// the attribute data-webform-markup.
$markups.each(function () {
var $this = $(this);
var original = $this.data('webform-markup');
if (original !== undefined) {
$this.html(original);
}
});
}
break;
}
}); // End look on each action for one conditional.
}); // End loop on each conditional.
$form.find('.webform-disabled-flag').removeClass('webform-disabled-flag');
};
/**
* Event handler to prevent propagation of events.
*
* Typically click for disabling radio and checkboxes.
*/
Drupal.webform.stopEvent = function () {
return false;
};
Drupal.webform.conditionalOperatorStringEqual = function (element, existingValue, ruleValue) {
var returnValue = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase() === ruleValue.toLowerCase()) {
returnValue = true;
return false; // break.
}
});
return returnValue;
};
Drupal.webform.conditionalOperatorStringNotEqual = function (element, existingValue, ruleValue) {
var found = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase() === ruleValue.toLowerCase()) {
found = true;
}
});
return !found;
};
Drupal.webform.conditionalOperatorStringContains = function (element, existingValue, ruleValue) {
var returnValue = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) > -1) {
returnValue = true;
return false; // break.
}
});
return returnValue;
};
Drupal.webform.conditionalOperatorStringDoesNotContain = function (element, existingValue, ruleValue) {
var found = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) > -1) {
found = true;
}
});
return !found;
};
Drupal.webform.conditionalOperatorStringBeginsWith = function (element, existingValue, ruleValue) {
var returnValue = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) === 0) {
returnValue = true;
return false; // break.
}
});
return returnValue;
};
Drupal.webform.conditionalOperatorStringEndsWith = function (element, existingValue, ruleValue) {
var returnValue = false;
var currentValue = Drupal.webform.stringValue(element, existingValue);
$.each(currentValue, function (n, value) {
if (value.toLowerCase().lastIndexOf(ruleValue.toLowerCase()) === value.length - ruleValue.length) {
returnValue = true;
return false; // break.
}
});
return returnValue;
};
Drupal.webform.conditionalOperatorStringEmpty = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
var returnValue = true;
$.each(currentValue, function (n, value) {
if (value !== '') {
returnValue = false;
return false; // break.
}
});
return returnValue;
};
Drupal.webform.conditionalOperatorStringNotEmpty = function (element, existingValue, ruleValue) {
return !Drupal.webform.conditionalOperatorStringEmpty(element, existingValue, ruleValue);
};
Drupal.webform.conditionalOperatorSelectGreaterThan = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
return Drupal.webform.compare_select(currentValue[0], ruleValue, element) > 0;
};
Drupal.webform.conditionalOperatorSelectGreaterThanEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
var comparison = Drupal.webform.compare_select(currentValue[0], ruleValue, element);
return comparison > 0 || comparison === 0;
};
Drupal.webform.conditionalOperatorSelectLessThan = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
return Drupal.webform.compare_select(currentValue[0], ruleValue, element) < 0;
};
Drupal.webform.conditionalOperatorSelectLessThanEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
var comparison = Drupal.webform.compare_select(currentValue[0], ruleValue, element);
return comparison < 0 || comparison === 0;
};
Drupal.webform.conditionalOperatorNumericEqual = function (element, existingValue, ruleValue) {
// See float comparison: http://php.net/manual/en/language.types.float.php
var currentValue = Drupal.webform.stringValue(element, existingValue);
var epsilon = 0.000001;
// An empty string does not match any number.
return currentValue[0] === '' ? false : (Math.abs(parseFloat(currentValue[0]) - parseFloat(ruleValue)) < epsilon);
};
Drupal.webform.conditionalOperatorNumericNotEqual = function (element, existingValue, ruleValue) {
// See float comparison: http://php.net/manual/en/language.types.float.php
var currentValue = Drupal.webform.stringValue(element, existingValue);
var epsilon = 0.000001;
// An empty string does not match any number.
return currentValue[0] === '' ? true : (Math.abs(parseFloat(currentValue[0]) - parseFloat(ruleValue)) >= epsilon);
};
Drupal.webform.conditionalOperatorNumericGreaterThan = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
return parseFloat(currentValue[0]) > parseFloat(ruleValue);
};
Drupal.webform.conditionalOperatorNumericGreaterThanEqual = function (element, existingValue, ruleValue) {
return Drupal.webform.conditionalOperatorNumericGreaterThan(element, existingValue, ruleValue) ||
Drupal.webform.conditionalOperatorNumericEqual(element, existingValue, ruleValue);
};
Drupal.webform.conditionalOperatorNumericLessThan = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.stringValue(element, existingValue);
return parseFloat(currentValue[0]) < parseFloat(ruleValue);
};
Drupal.webform.conditionalOperatorNumericLessThanEqual = function (element, existingValue, ruleValue) {
return Drupal.webform.conditionalOperatorNumericLessThan(element, existingValue, ruleValue) ||
Drupal.webform.conditionalOperatorNumericEqual(element, existingValue, ruleValue);
};
Drupal.webform.conditionalOperatorDateEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.dateValue(element, existingValue);
return currentValue === ruleValue;
};
Drupal.webform.conditionalOperatorDateNotEqual = function (element, existingValue, ruleValue) {
return !Drupal.webform.conditionalOperatorDateEqual(element, existingValue, ruleValue);
};
Drupal.webform.conditionalOperatorDateBefore = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.dateValue(element, existingValue);
return (currentValue !== false) && currentValue < ruleValue;
};
Drupal.webform.conditionalOperatorDateBeforeEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.dateValue(element, existingValue);
return (currentValue !== false) && (currentValue < ruleValue || currentValue === ruleValue);
};
Drupal.webform.conditionalOperatorDateAfter = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.dateValue(element, existingValue);
return (currentValue !== false) && currentValue > ruleValue;
};
Drupal.webform.conditionalOperatorDateAfterEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.dateValue(element, existingValue);
return (currentValue !== false) && (currentValue > ruleValue || currentValue === ruleValue);
};
Drupal.webform.conditionalOperatorTimeEqual = function (element, existingValue, ruleValue) {
var currentValue = Drupal.webform.timeValue(element, existingValue);
return currentValue === ruleValue;
};
Drupal.webform.conditionalOperatorTimeNotEqual = function (element, existingValue, ruleValue) {
return !Drupal.webform.conditionalOperatorTimeEqual(element, existingValue, ruleValue);
};
Drupal.webform.conditionalOperatorTimeBefore = function (element, existingValue, ruleValue) {
// Date and time operators intentionally exclusive for "before".
var currentValue = Drupal.webform.timeValue(element, existingValue);
return (currentValue !== false) && (currentValue < ruleValue);
};
Drupal.webform.conditionalOperatorTimeBeforeEqual = function (element, existingValue, ruleValue) {
// Date and time operators intentionally exclusive for "before".
var currentValue = Drupal.webform.timeValue(element, existingValue);
return (currentValue !== false) && (currentValue < ruleValue || currentValue === ruleValue);
};
Drupal.webform.conditionalOperatorTimeAfter = function (element, existingValue, ruleValue) {
// Date and time operators intentionally inclusive for "after".
var currentValue = Drupal.webform.timeValue(element, existingValue);
return (currentValue !== false) && (currentValue > ruleValue);
};
Drupal.webform.conditionalOperatorTimeAfterEqual = function (element, existingValue, ruleValue) {
// Date and time operators intentionally inclusive for "after".
var currentValue = Drupal.webform.timeValue(element, existingValue);
return (currentValue !== false) && (currentValue > ruleValue || currentValue === ruleValue);
};
/**
* Utility function to compare values of a select component.
*
* @param string a
* First select option key to compare
* @param string b
* Second select option key to compare
* @param array options
* Associative array where the a and b are within the keys
*
* @return integer based upon position of $a and $b in $options
* -N if $a above (<) $b
* 0 if $a = $b
* +N if $a is below (>) $b
*/
Drupal.webform.compare_select = function (a, b, element) {
var optionList = [];
$('option,input:radio,input:checkbox', element).each(function () {
optionList.push($(this).val());
});
var a_position = optionList.indexOf(a);
var b_position = optionList.indexOf(b);
return (a_position < 0 || b_position < 0) ? null : a_position - b_position;
};
/**
* Utility to return current visibility.
*
* Uses actual visibility, except for hidden components which use the applied
* disabled class.
*/
Drupal.webform.isVisible = function ($element) {
return $element.hasClass('webform-component-hidden')
? !$element.find('input').first().hasClass('webform-conditional-disabled')
: $element.closest('.webform-conditional-hidden').length == 0;
};
/**
* Function to get a string value from a select/radios/text/etc. field.
*/
Drupal.webform.stringValue = function (element, existingValue) {
var value = [];
if (element) {
var $element = $(element);
if (Drupal.webform.isVisible($element)) {
// Checkboxes and radios.
$element.find('input[type=checkbox]:checked,input[type=radio]:checked').each(function () {
value.push(this.value);
});
// Select lists.
if (!value.length) {
var selectValue = $element.find('select').val();
if (selectValue) {
if ($.isArray(selectValue)) {
value = selectValue;
}
else {
value.push(selectValue);
}
}
}
// Simple text fields. This check is done last so that the select list
// in select-or-other fields comes before the "other" text field.
if (!value.length) {
$element.find('input:not([type=checkbox],[type=radio]),textarea').each(function () {
value.push(this.value);
});
}
}
}
else {
switch ($.type(existingValue)) {
case 'array':
value = existingValue;
break;
case 'string':
value.push(existingValue);
break;
}
}
return value;
};
/**
* Utility function to calculate a second-based timestamp from a time field.
*/
Drupal.webform.dateValue = function (element, existingValue) {
var value = false;
if (element) {
var $element = $(element);
if (Drupal.webform.isVisible($element)) {
var day = $element.find('[name*=day]').val();
var month = $element.find('[name*=month]').val();
var year = $element.find('[name*=year]').val();
// Months are 0 indexed in JavaScript.
if (month) {
month--;
}
if (year !== '' && month !== '' && day !== '') {
value = Date.UTC(year, month, day) / 1000;
}
}
}
else {
if ($.type(existingValue) === 'array' && existingValue.length) {
existingValue = existingValue[0];
}
if ($.type(existingValue) === 'string') {
existingValue = existingValue.split('-');
}
if (existingValue.length === 3) {
value = Date.UTC(existingValue[0], existingValue[1], existingValue[2]) / 1000;
}
}
return value;
};
/**
* Utility function to calculate a millisecond timestamp from a time field.
*/
Drupal.webform.timeValue = function (element, existingValue) {
var value = false;
if (element) {
var $element = $(element);
if (Drupal.webform.isVisible($element)) {
var hour = $element.find('[name*=hour]').val();
var minute = $element.find('[name*=minute]').val();
var ampm = $element.find('[name*=ampm]:checked').val();
// Convert to integers if set.
hour = (hour === '') ? hour : parseInt(hour);
minute = (minute === '') ? minute : parseInt(minute);
if (hour !== '') {
hour = (hour < 12 && ampm == 'pm') ? hour + 12 : hour;
hour = (hour === 12 && ampm == 'am') ? 0 : hour;
}
if (hour !== '' && minute !== '') {
value = Date.UTC(1970, 0, 1, hour, minute) / 1000;
}
}
}
else {
if ($.type(existingValue) === 'array' && existingValue.length) {
existingValue = existingValue[0];
}
if ($.type(existingValue) === 'string') {
existingValue = existingValue.split(':');
}
if (existingValue.length >= 2) {
value = Date.UTC(1970, 0, 1, existingValue[0], existingValue[1]) / 1000;
}
}
return value;
};
/**
* Make a prop shim for jQuery < 1.9.
*/
$.fn.webformProp = $.fn.webformProp || function (name, value) {
if (value) {
return $.fn.prop ? this.prop(name, true) : this.attr(name, true);
}
else {
return $.fn.prop ? this.prop(name, false) : this.removeAttr(name);
}
};
/**
* Make a multi-valued val() function.
*
* This is for setting checkboxes, radios, and select elements.
*/
$.fn.webformVal = function (values) {
this.each(function () {
var $this = $(this);
var value = $this.val();
var on = $.inArray($this.val(), values) != -1;
if (this.nodeName == 'OPTION') {
$this.webformProp('selected', on ? value : false);
}
else {
$this.val(on ? [value] : false);
}
});
return this;
};
/**
* Given a table's DOM element, restripe the odd/even classes.
*/
Drupal.webform.restripeTable = function (table) {
// :even and :odd are reversed because jQuery counts from 0 and
// we count from 1, so we're out of sync.
// Match immediate children of the parent element to allow nesting.
$('> tbody > tr, > tr', table)
.filter(':visible:odd').filter('.odd')
.removeClass('odd').addClass('even')
.end().end()
.filter(':visible:even').filter('.even')
.removeClass('even').addClass('odd');
};
})(jQuery);
;