Mercurial > hg > index.fcgi > www > www-1
annotate pics/np_keys.js @ 25:8314130afe1d
add javascript to handle next/prev/up shortcut keys
author | paulo@twcdns.fastsearch.net |
---|---|
date | Tue, 26 Apr 2011 00:18:06 -0700 |
parents | |
children |
rev | line source |
---|---|
paulo@25 | 1 function getKeypress(e) { |
paulo@25 | 2 c = null |
paulo@25 | 3 |
paulo@25 | 4 if (e.which == null) |
paulo@25 | 5 c = String.fromCharCode(e.keyCode); // IE |
paulo@25 | 6 else if (e.which != 0 && e.charCode != 0) |
paulo@25 | 7 c = String.fromCharCode(e.which); // All others |
paulo@25 | 8 |
paulo@25 | 9 if (c != null) { |
paulo@25 | 10 if (c == 'n') |
paulo@25 | 11 goHref('next'); |
paulo@25 | 12 else if (c == 'p') |
paulo@25 | 13 goHref('prev'); |
paulo@25 | 14 else if (c == 'u') |
paulo@25 | 15 goHref('up'); |
paulo@25 | 16 } |
paulo@25 | 17 } |
paulo@25 | 18 |
paulo@25 | 19 function goHref(id) { |
paulo@25 | 20 window.location.href = document.getElementById(id).href; |
paulo@25 | 21 } |
paulo@25 | 22 |
paulo@25 | 23 document.onkeypress = getKeypress |