convert keycode to char; e.preventDefault()
This commit is contained in:
parent
03836a2ab5
commit
bb377d194b
@ -360,17 +360,21 @@ iframeLoad = ->
|
|||||||
recaptchaReload()
|
recaptchaReload()
|
||||||
|
|
||||||
keyboardNav = (e) ->
|
keyboardNav = (e) ->
|
||||||
hash = Number(location.hash?.substring(1)) or 0
|
|
||||||
kc = e.keyCode
|
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
|
count = g.count
|
||||||
if 48 <= kc <= 57 # 0 - 9
|
if char in '1234567890'
|
||||||
temp = kc - 48
|
temp = Number char
|
||||||
if temp is 0 and count is 0 # special - immediately go to page 0
|
if temp is 0 and count is 0 # special - immediately go to page 0
|
||||||
location.pathname = "/#{g.BOARD}/#1"
|
location.pathname = "/#{g.BOARD}/#1"
|
||||||
else
|
else
|
||||||
g.count = (count * 10) + temp
|
g.count = (count * 10) + temp
|
||||||
return
|
return
|
||||||
if kc is 71 #g
|
if char is "G"
|
||||||
if count
|
if count
|
||||||
temp = if count > 15 then 15 else count
|
temp = if count > 15 then 15 else count
|
||||||
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
||||||
@ -380,20 +384,20 @@ keyboardNav = (e) ->
|
|||||||
else
|
else
|
||||||
location.hash = 'navtop'
|
location.hash = 'navtop'
|
||||||
count or= 1
|
count or= 1
|
||||||
switch kc
|
switch char
|
||||||
when 72 #h
|
when "H"
|
||||||
temp = g.PAGENUM - count
|
temp = g.PAGENUM - count
|
||||||
if temp < 0 then temp = 0
|
if temp < 0 then temp = 0
|
||||||
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
||||||
when 74 #j
|
when "J"
|
||||||
temp = hash + count
|
temp = hash + count
|
||||||
if temp > 10 then temp = 10
|
if temp > 10 then temp = 10
|
||||||
location.hash = temp
|
location.hash = temp
|
||||||
when 75 #k
|
when "K"
|
||||||
temp = hash - count
|
temp = hash - count
|
||||||
if temp <= 0 then temp = 'navtop'
|
if temp <= 0 then temp = 'navtop'
|
||||||
location.hash = temp
|
location.hash = temp
|
||||||
when 76 #l
|
when "L"
|
||||||
temp = g.PAGENUM + count
|
temp = g.PAGENUM + count
|
||||||
if temp > 15 then temp = 15
|
if temp > 15 then temp = 15
|
||||||
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
||||||
|
|||||||
25
4chan_x.js
25
4chan_x.js
@ -445,12 +445,17 @@
|
|||||||
return recaptchaReload();
|
return recaptchaReload();
|
||||||
};
|
};
|
||||||
keyboardNav = function(e) {
|
keyboardNav = function(e) {
|
||||||
var count, hash, kc, temp;
|
var _i, _len, char, count, hash, kc, temp;
|
||||||
hash = Number(location.hash == null ? undefined : location.hash.substring(1)) || 0;
|
|
||||||
kc = e.keyCode;
|
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;
|
count = g.count;
|
||||||
if ((48 <= kc) && (kc <= 57)) {
|
if ((function(){ for (var _i=0, _len='1234567890'.length; _i<_len; _i++) { if ('1234567890'[_i] === char) return true; } return false; }).call(this)) {
|
||||||
temp = kc - 48;
|
temp = Number(char);
|
||||||
if (temp === 0 && count === 0) {
|
if (temp === 0 && count === 0) {
|
||||||
location.pathname = ("/" + (g.BOARD) + "/#1");
|
location.pathname = ("/" + (g.BOARD) + "/#1");
|
||||||
} else {
|
} else {
|
||||||
@ -458,7 +463,7 @@
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (kc === 71) {
|
if (char === "G") {
|
||||||
if (count) {
|
if (count) {
|
||||||
temp = count > 15 ? 15 : count;
|
temp = count > 15 ? 15 : count;
|
||||||
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
|
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
|
||||||
@ -471,29 +476,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
count || (count = 1);
|
count || (count = 1);
|
||||||
switch (kc) {
|
switch (char) {
|
||||||
case 72:
|
case "H":
|
||||||
temp = g.PAGENUM - count;
|
temp = g.PAGENUM - count;
|
||||||
if (temp < 0) {
|
if (temp < 0) {
|
||||||
temp = 0;
|
temp = 0;
|
||||||
}
|
}
|
||||||
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
|
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
|
||||||
break;
|
break;
|
||||||
case 74:
|
case "J":
|
||||||
temp = hash + count;
|
temp = hash + count;
|
||||||
if (temp > 10) {
|
if (temp > 10) {
|
||||||
temp = 10;
|
temp = 10;
|
||||||
}
|
}
|
||||||
location.hash = temp;
|
location.hash = temp;
|
||||||
break;
|
break;
|
||||||
case 75:
|
case "K":
|
||||||
temp = hash - count;
|
temp = hash - count;
|
||||||
if (temp <= 0) {
|
if (temp <= 0) {
|
||||||
temp = 'navtop';
|
temp = 'navtop';
|
||||||
}
|
}
|
||||||
location.hash = temp;
|
location.hash = temp;
|
||||||
break;
|
break;
|
||||||
case 76:
|
case "L":
|
||||||
temp = g.PAGENUM + count;
|
temp = g.PAGENUM + count;
|
||||||
if (temp > 15) {
|
if (temp > 15) {
|
||||||
temp = 15;
|
temp = 15;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user