convert keycode to char; e.preventDefault()

This commit is contained in:
James Campos 2010-11-13 22:23:16 -08:00
parent 03836a2ab5
commit bb377d194b
2 changed files with 28 additions and 19 deletions

View File

@ -360,17 +360,21 @@ iframeLoad = ->
recaptchaReload()
keyboardNav = (e) ->
hash = Number(location.hash?.substring(1)) or 0
kc = e.keyCode
char = String.fromCharCode kc
unless char in '1234567890GHJKL'
return
e.preventDefault()
hash = Number(location.hash?.substring(1)) or 0
count = g.count
if 48 <= kc <= 57 # 0 - 9
temp = kc - 48
if char in '1234567890'
temp = Number char
if temp is 0 and count is 0 # special - immediately go to page 0
location.pathname = "/#{g.BOARD}/#1"
else
g.count = (count * 10) + temp
return
if kc is 71 #g
if char is "G"
if count
temp = if count > 15 then 15 else count
location.pathname = "/#{g.BOARD}/#{temp}#1"
@ -380,20 +384,20 @@ keyboardNav = (e) ->
else
location.hash = 'navtop'
count or= 1
switch kc
when 72 #h
switch char
when "H"
temp = g.PAGENUM - count
if temp < 0 then temp = 0
location.pathname = "/#{g.BOARD}/#{temp}#1"
when 74 #j
when "J"
temp = hash + count
if temp > 10 then temp = 10
location.hash = temp
when 75 #k
when "K"
temp = hash - count
if temp <= 0 then temp = 'navtop'
location.hash = temp
when 76 #l
when "L"
temp = g.PAGENUM + count
if temp > 15 then temp = 15
location.pathname = "/#{g.BOARD}/#{temp}#1"

View File

@ -445,12 +445,17 @@
return recaptchaReload();
};
keyboardNav = function(e) {
var count, hash, kc, temp;
hash = Number(location.hash == null ? undefined : location.hash.substring(1)) || 0;
var _i, _len, char, count, hash, kc, temp;
kc = e.keyCode;
char = String.fromCharCode(kc);
if (!((function(){ for (var _i=0, _len='1234567890GHJKL'.length; _i<_len; _i++) { if ('1234567890GHJKL'[_i] === char) return true; } return false; }).call(this))) {
return null;
}
e.preventDefault();
hash = Number(location.hash == null ? undefined : location.hash.substring(1)) || 0;
count = g.count;
if ((48 <= kc) && (kc <= 57)) {
temp = kc - 48;
if ((function(){ for (var _i=0, _len='1234567890'.length; _i<_len; _i++) { if ('1234567890'[_i] === char) return true; } return false; }).call(this)) {
temp = Number(char);
if (temp === 0 && count === 0) {
location.pathname = ("/" + (g.BOARD) + "/#1");
} else {
@ -458,7 +463,7 @@
}
return null;
}
if (kc === 71) {
if (char === "G") {
if (count) {
temp = count > 15 ? 15 : count;
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
@ -471,29 +476,29 @@
}
}
count || (count = 1);
switch (kc) {
case 72:
switch (char) {
case "H":
temp = g.PAGENUM - count;
if (temp < 0) {
temp = 0;
}
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
break;
case 74:
case "J":
temp = hash + count;
if (temp > 10) {
temp = 10;
}
location.hash = temp;
break;
case 75:
case "K":
temp = hash - count;
if (temp <= 0) {
temp = 'navtop';
}
location.hash = temp;
break;
case 76:
case "L":
temp = g.PAGENUM + count;
if (temp > 15) {
temp = 15;