make navlink ids friendlier to css selectors

css selectors don't want ids to start with numbers,
so change the ids from #n to #pn.
This commit is contained in:
James Campos 2010-11-14 00:02:39 -08:00
parent 8e5c1e292f
commit eea05abfa6
2 changed files with 33 additions and 22 deletions

View File

@ -364,7 +364,11 @@ keyboardNav = (e) ->
unless char in '1234567890GHJKL' unless char in '1234567890GHJKL'
return return
e.preventDefault() e.preventDefault()
hash = Number(location.hash?.substring(1)) or 0 hash = location.hash
if not hash or hash == '#navtop'
position = 0
else
position = Number(hash.substring 2) or 0
count = g.count count = g.count
if char in '1234567890' if char in '1234567890'
temp = Number char temp = Number char
@ -389,12 +393,12 @@ keyboardNav = (e) ->
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 "J" when "J"
temp = hash + count temp = position + count
if temp > 10 then temp = 10 if temp > 10 then temp = 10
location.hash = temp location.hash = 'p' + temp
when "K" when "K"
temp = hash - count temp = position - count
if temp <= 0 then temp = 'navtop' if temp <= 0 then temp = 'navtop' else temp = 'p' + temp
location.hash = temp location.hash = temp
when "L" when "L"
temp = g.PAGENUM + count temp = g.PAGENUM + count
@ -941,13 +945,13 @@ else #not reply
for el in arr for el in arr
span = n 'span', span = n 'span',
className: 'navlinks' className: 'navlinks'
id: _i id: 'p' + _i
if _i if _i
textContent = '' textContent = ''
href = "##{_i - 1}" href = "#p#{_i - 1}"
else if g.PAGENUM else if g.PAGENUM
textContent = '' textContent = ''
href = g.PAGENUM - 1 href = "#{g.PAGENUM - 1}#p0"
else else
textContent = '' textContent = ''
href = "#navtop" href = "#navtop"
@ -957,17 +961,17 @@ else #not reply
href: href href: href
if _i < l1 if _i < l1
textContent = '' textContent = ''
href = "##{_i + 1}" href = "#p#{_i + 1}"
else else
textContent = '' textContent = ''
href = "#{g.PAGENUM + 1}#0" href = "#{g.PAGENUM + 1}#p0"
down = n 'a', down = n 'a',
className: 'pointer' className: 'pointer'
textContent: textContent textContent: textContent
href: href href: href
addTo span, up, tn(' '), down addTo span, up, tn(' '), down
inBefore el, span inBefore el, span
if location.hash is '#0' if location.hash is '#p0'
window.location = window.location window.location = window.location
if getConfig 'Thread Expansion' if getConfig 'Thread Expansion'

View File

@ -445,13 +445,18 @@
return recaptchaReload(); return recaptchaReload();
}; };
keyboardNav = function(e) { keyboardNav = function(e) {
var _i, _len, char, count, hash, temp; var _i, _len, char, count, hash, position, temp;
char = String.fromCharCode(e.keyCode); char = String.fromCharCode(e.keyCode);
if (!((function(){ for (var _i=0, _len='1234567890GHJKL'.length; _i<_len; _i++) { if ('1234567890GHJKL'[_i] === char) return true; } return false; }).call(this))) { if (!((function(){ for (var _i=0, _len='1234567890GHJKL'.length; _i<_len; _i++) { if ('1234567890GHJKL'[_i] === char) return true; } return false; }).call(this))) {
return null; return null;
} }
e.preventDefault(); e.preventDefault();
hash = Number(location.hash == null ? undefined : location.hash.substring(1)) || 0; hash = location.hash;
if (!hash || hash === '#navtop') {
position = 0;
} else {
position = Number(hash.substring(2)) || 0;
}
count = g.count; count = g.count;
if ((function(){ for (var _i=0, _len='1234567890'.length; _i<_len; _i++) { if ('1234567890'[_i] === char) return true; } return false; }).call(this)) { 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); temp = Number(char);
@ -484,16 +489,18 @@
location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1"); location.pathname = ("/" + (g.BOARD) + "/" + (temp) + "#1");
break; break;
case "J": case "J":
temp = hash + count; temp = position + count;
if (temp > 10) { if (temp > 10) {
temp = 10; temp = 10;
} }
location.hash = temp; location.hash = 'p' + temp;
break; break;
case "K": case "K":
temp = hash - count; temp = position - count;
if (temp <= 0) { if (temp <= 0) {
temp = 'navtop'; temp = 'navtop';
} else {
temp = 'p' + temp;
} }
location.hash = temp; location.hash = temp;
break; break;
@ -1212,14 +1219,14 @@
el = _ref[_i]; el = _ref[_i];
span = n('span', { span = n('span', {
className: 'navlinks', className: 'navlinks',
id: _i id: 'p' + _i
}); });
if (_i) { if (_i) {
textContent = '▲'; textContent = '▲';
href = ("#" + (_i - 1)); href = ("#p" + (_i - 1));
} else if (g.PAGENUM) { } else if (g.PAGENUM) {
textContent = '◀'; textContent = '◀';
href = g.PAGENUM - 1; href = ("" + (g.PAGENUM - 1) + "#p0");
} else { } else {
textContent = '▲'; textContent = '▲';
href = "#navtop"; href = "#navtop";
@ -1231,10 +1238,10 @@
}); });
if (_i < l1) { if (_i < l1) {
textContent = '▼'; textContent = '▼';
href = ("#" + (_i + 1)); href = ("#p" + (_i + 1));
} else { } else {
textContent = '▶'; textContent = '▶';
href = ("" + (g.PAGENUM + 1) + "#0"); href = ("" + (g.PAGENUM + 1) + "#p0");
} }
down = n('a', { down = n('a', {
className: 'pointer', className: 'pointer',
@ -1244,7 +1251,7 @@
addTo(span, up, tn(' '), down); addTo(span, up, tn(' '), down);
inBefore(el, span); inBefore(el, span);
} }
if (location.hash === '#0') { if (location.hash === '#p0') {
window.location = window.location; window.location = window.location;
} }
} }