]> www.average.org Git - mkgallery.git/blobdiff - include/gallery.js
keyboard controls
[mkgallery.git] / include / gallery.js
index 08097589d49f25d9a5647556e9a46c9ae6d89e15..a870a03eb3d138aa4693df1c8a00beb305061d63 100644 (file)
@@ -16,8 +16,9 @@
 /* Initialize everything, to be called on domready */
 function init_gallery() {
 
-       /* List of lists of img variations. Each image variation is a three-element
-        * array: [width, height, url]. Index of the outer array is the global ID.
+       /* List of lists of img variations. Each image variation is
+        * a three-element array: [width, height, url]. Index of the
+        * outer array is the global ID.
         *
         * [
         *  [ id, title, [
@@ -38,21 +39,21 @@ function init_gallery() {
 
        $$('div.varimages').each(function(el,i){
                rimgs[el.id] = i;
-               vimgs[i] = [];
+               vimgs[i] = [el.id, el.title, []];
                el.getElements('a').each(function(ael,j){
                        dim = /(\d+)[^\d](\d+)/.exec(ael.text);
                        w = dim[1];
                        h = dim[2];
-                       vimgs[i][j]=[w,h,ael.href,el.id,el.title];
+                       vimgs[i][2][j]=[w,h,ael.href];
                });
        });
 
                        /* debugging output
        var msg='loaded '+vimgs.length+' image descriptions:';
        vimgs.each(function(vimg,i){
-               msg+='\nid='+i;
-               vimg.each(function(vimg,i){
-                       msg+='\n     w='+vimg[0]+' h='+vimg[1]+' url='+vimg[2];
+               msg+='\nid='+i+' ('+vimg[0]+') title='+vimg[1];
+               vimg[2].each(function(vv,i){
+                       msg+='\n     w='+vv[0]+' h='+vv[1]+' url='+vv[2];
                });
        });
        alert(msg);
@@ -90,6 +91,20 @@ function init_gallery() {
        };
        var show = new Show(vimgs,showwin,ctl,showparms);
 
+       document.addEvent('keypress', function(ev){
+               if (ev.key == 'esc') {
+                       show.exit();
+               } else if (ev.key == 'left') {
+                       show.prev();
+               } else if (ev.key == 'right') {
+                       show.next();
+               } else if (ev.key == 'space') {
+                       show.toggleplay();
+               } else {
+                       /* alert('keypress: '+ev.key); */
+               }
+       });
+
        /* Update HTML */
 
        $$('.conceal').each(function(el){
@@ -119,4 +134,5 @@ function init_gallery() {
 }
 
 /* Initialization */
-window.addEvent('domready',init_gallery)
+window.addEvent('domready',init_gallery);
+