added in "ESC" as one of the keys that will close the lightbox
authorStella Power
Wed, 6 Jun 2007 10:45:13 +0000 (10:45 +0000)
committerStella Power
Wed, 6 Jun 2007 10:45:13 +0000 (10:45 +0000)
js/lightbox.js
js/lightbox_lite.js

index ae7309a..12c1f69 100644 (file)
@@ -306,6 +306,7 @@ Lightbox.prototype = {
                var objBottomNavCloseLink = document.createElement("a");
                objBottomNavCloseLink.setAttribute('id','bottomNavClose');
                objBottomNavCloseLink.setAttribute('href','#');
+               objBottomNavCloseLink.setAttribute('accesskey',"B");
                objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
                objBottomNav.appendChild(objBottomNavCloseLink);
        
@@ -543,10 +544,12 @@ Lightbox.prototype = {
        // Update to 2.02+
        keyboardAction: function(e) {
 
-    if (e == null) { // ie
+               if (e == null) { // ie
                        keycode = event.keyCode;
+                       escapeKey = 27;
                } else { // mozilla
                        keycode = e.which;
+                       escapeKey = e.DOM_VK_ESCAPE;
                }
                
                // Instead of the above code, (starting with 'if ...') Roel replaced it with the code below, 
@@ -562,14 +565,17 @@ Lightbox.prototype = {
 
                key = String.fromCharCode(keycode).toLowerCase();
                
-               if((key == 'x') || (key == 'o') || (key == 'c')){       // close lightbox
+               // close lightbox (x, o, c, ESC)
+               if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){     
                        myLightbox.end();
-               } else if(key == 'p' || keycode == 37 || keycode == 8 || keycode == 100){       // display previous image
+               // display previous image (p, <-, backspace, ????) 
+               } else if(key == 'p' || keycode == 37 || keycode == 8 || keycode == 100){       
                        if(activeImage != 0){
                                myLightbox.disableKeyboardNav();
                                myLightbox.changeImage(activeImage - 1);
                        }
-               } else if(key == 'n' || keycode == 39 || keycode == 32 || keycode == 102){      // display next image
+               // display next image (n, ->, space, ????)
+               } else if(key == 'n' || keycode == 39 || keycode == 32 || keycode == 102){      
                        if(activeImage != (imageArray.length - 1)){
                                myLightbox.disableKeyboardNav();
                                myLightbox.changeImage(activeImage + 1);
index f5cccd4..659eac4 100644 (file)
@@ -142,12 +142,14 @@ function pause(numberMillis) {
 function getKey(e){
        if (e == null) { // ie
                keycode = event.keyCode;
+               escapeKey = 27;
        } else { // mozilla
                keycode = e.which;
+               escapeKey = e.DOM_VK_ESCAPE;
        }
        key = String.fromCharCode(keycode).toLowerCase();
        
-       if(key == 'x'){ hideLightbox(); }
+       if(key == 'x' || key == 'c' || keycode == escapeKey){ hideLightbox(); }
 }