]> git.defcon.no Git - plsgen/blob - nav.js
Three new features, three bugfixes. Version 0.4 code.
[plsgen] / nav.js
1 var prev = null;
2 var next = null;
3 var index = null;
4
5 var preloaded = [];
6
7 function key_handler ( e )
8 {
9 var key = (window.event) ? event.keyCode : e.keyCode;
10 if ( (key == 37) && (prev != null) )
11 {
12 window.location = prev + '.html';
13 }
14 if ( (key == 39) && (next != null) )
15 {
16 window.location = next + '.html';
17 }
18 if (key == 27) window.location = "index.html";
19 if ( (key == 38) && (index != null) ) window.location = index;
20 return;
21 }
22 function img_preload ( image )
23 {
24 var image_thumb = new Image();
25 image_thumb.src = 'thumb/' + image;
26 preloaded.push(image_thumb);
27
28 var image_view = new Image();
29 image_view.src = 'view/' + image;
30 preloaded.push(image_view);
31 }
32
33 function nav_set_target ( target, direction )
34 {
35 if ( target )
36 {
37 if ( direction == 0 ) prev = target;
38 if ( direction == 1 ) next = target;
39 var img_regx = /.*\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)$/;
40 if ( target.match( img_regx ) )
41 img_preload( target );
42 }
43 }
44
45 function nav_reg_prev ( target )
46 { nav_set_target(target, 0); }
47
48 function nav_reg_next ( target )
49 { nav_set_target(target, 1); }
50
51 function nav_reg_index( target )
52 { index = target; }
53
54 function nav_reg_onkeypress()
55 { document.onkeyup = key_handler; }