summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--js/lightbox.js32
-rw-r--r--lightbox2.install5
-rw-r--r--lightbox2.module48
3 files changed, 75 insertions, 10 deletions
diff --git a/js/lightbox.js b/js/lightbox.js
index e2075b5..5a02b2f 100644
--- a/js/lightbox.js
+++ b/js/lightbox.js
@@ -41,6 +41,11 @@ var Lightbox = {
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.
@@ -89,6 +94,11 @@ var Lightbox = {
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;
@@ -148,7 +158,6 @@ var Lightbox = {
// Setup onclick handlers.
$('#overlay').click(function() { Lightbox.end(); return false; } ).hide();
- $('#imageData').click(function() { return false; } );
$('#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; } );
@@ -739,26 +748,24 @@ var Lightbox = {
key = String.fromCharCode(keycode).toLowerCase();
// Close lightbox.
- if (key == 'x' || key == 'o' || key == 'c' || keycode == escapeKey) {
+ if (Lightbox.checkKey(Lightbox.keysClose, key, keycode)) {
Lightbox.end('forceClose');
-
- // Display previous image (p, <-).
}
- else if (key == 'p' || keycode == 37) {
+ // 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 (key == 'n' || keycode == 39) {
+ // 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 (key == 'z' && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
+ else if (Lightbox.checkKey(Lightbox.keysZoom, key, keycode) && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
if (Lightbox.isZoomedIn) {
Lightbox.changeData(Lightbox.activeImage, false);
}
@@ -767,7 +774,7 @@ var Lightbox = {
}
}
// Toggle play / pause (space).
- else if (keycode == 32 && Lightbox.isSlideshow) {
+ else if (Lightbox.checkKey(Lightbox.keysPlayPause, key, keycode) && Lightbox.isSlideshow) {
if (Lightbox.isPaused) {
Lightbox.togglePlayPause("lightshowPlay", "lightshowPause");
}
@@ -1021,7 +1028,12 @@ var Lightbox = {
}
}
return false;
+ },
+
+ checkKey: function(keys, key, code) {
+ return (keys.indexOf(key) != -1 || keys.indexOf(code) != -1);
}
+
};
// Initialize the lightbox.
diff --git a/lightbox2.install b/lightbox2.install
index 38c7e50..2eb69fa 100644
--- a/lightbox2.install
+++ b/lightbox2.install
@@ -43,6 +43,11 @@ function lightbox2_uninstall() {
variable_del('lightbox2_border_size');
variable_del('lightbox2_box_color');
variable_del('lightbox2_font_color');
+ variable_del('lightbox2_keys_close');
+ variable_del('lightbox2_keys_previous');
+ variable_del('lightbox2_keys_next');
+ variable_del('lightbox2_keys_zoom');
+ variable_del('lightbox2_keys_play_pause');
variable_del('lightbox2_top_position');
variable_del('lightbox2_overlay_opacity');
variable_del('lightbox2_overlay_color');
diff --git a/lightbox2.module b/lightbox2.module
index 93da266..838079a 100644
--- a/lightbox2.module
+++ b/lightbox2.module
@@ -526,6 +526,49 @@ function lightbox2_general_settings_form() {
'#default_value' => variable_get('lightbox2_js_location', 'header'),
);
+ // Define keyboard shortcuts fieldset.
+ /* ---------------------------------- */
+ $form['advanced_options']['keyboard_shortcuts'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Keyboard Shortcuts'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_close'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Close keys'),
+ '#description' => t("A list of keys (or key codes) that a user may use to close the lightbox. Values should be separated by a space. Defaults to 'c x 27' (c, x, or esc)."),
+ '#default_value' => variable_get('lightbox2_keys_close', 'c x 27'),
+ );
+
+ $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_previous'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Previous keys'),
+ '#description' => t("A list of keys (or key codes) that a user may use to navigate to the previous item in the lightbox. Values should be separated by a space. Defaults to 'p 37' (p or left arrow)."),
+ '#default_value' => variable_get('lightbox2_keys_previous', 'p 37'),
+ );
+
+ $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_next'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Next keys'),
+ '#description' => t("A list of keys (or key codes) that a user may use to navigate to the next item in the lightbox. Values should be separated by a space. Defaults to 'n 39' (n or right arrow)."),
+ '#default_value' => variable_get('lightbox2_keys_next', 'n 39'),
+ );
+
+ $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_zoom'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Zoom keys'),
+ '#description' => t("A list of keys (or key codes) that a user may use to zoom in / out of images in the lightbox. Values should be separated by a space. Defaults to 'z'."),
+ '#default_value' => variable_get('lightbox2_keys_zoom', 'z'),
+ );
+
+ $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_play_pause'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pause / Play keys'),
+ '#description' => t("A list of keys (or key codes) that a user may use to pause / play the lightbox. Values should be separated by a space. Defaults to '32' (spacebar)."),
+ '#default_value' => variable_get('lightbox2_keys_play_pause', '32'),
+ );
// Define border settings fieldset.
/* ---------------------------------- */
@@ -1446,6 +1489,11 @@ function lightbox2_add_files() {
'page_count' => check_plain(variable_get('lightbox2_page_count_str', 'Page !current of !total')),
'lite_press_x_close' => t('press !x to close', array('!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>')),
// Automatic image handling settings.
+ 'keys_close' => variable_get('lightbox2_keys_close', 'c x 27'),
+ 'keys_previous' => variable_get('lightbox2_keys_previous', 'p 37'),
+ 'keys_next' => variable_get('lightbox2_keys_next', 'n 39'),
+ 'keys_zoom' => variable_get('lightbox2_keys_zoom', 'z'),
+ 'keys_play_pause' => variable_get('lightbox2_keys_play_pause', '32'),
'display_image_size' => variable_get('lightbox2_display_image_size', ''),
'image_node_sizes' => $image_node_sizes,
'trigger_lightbox_classes' => $trigger_lightbox_classes,