Refactor reply navigation. Close #217.

This commit is contained in:
Nicolas Stepien 2012-03-06 19:17:12 +01:00
parent ad5746c693
commit a1ed6c59b0
3 changed files with 74 additions and 94 deletions

View File

@ -1050,10 +1050,10 @@
Keybinds.open(thread, true); Keybinds.open(thread, true);
break; break;
case conf.nextReply: case conf.nextReply:
Keybinds.hl.next(thread); Keybinds.hl(+1, thread);
break; break;
case conf.previousReply: case conf.previousReply:
Keybinds.hl.prev(thread); Keybinds.hl(-1, thread);
break; break;
case conf.hide: case conf.hide:
ThreadHiding.toggle(thread); ThreadHiding.toggle(thread);
@ -1159,58 +1159,45 @@
return location.href = url; return location.href = url;
} }
}, },
hl: { hl: function(delta, thread) {
next: function(thread) { var next, rect, replies, reply, td, _i, _len;
var next, rect, replies, reply, td, top, _i, _len; if (td = $('.replyhl', thread)) {
if (td = $('td.replyhl', thread)) {
td.className = 'reply'; td.className = 'reply';
td.removeAttribute('tabindex');
rect = td.getBoundingClientRect(); rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.bottom >= 0 && rect.top <= d.body.clientHeight) {
next = $.x('following::td[@class="reply"]', td); next = delta === +1 ? $.x('following::td[@class="reply"]', td) : $.x('preceding::td[@class="reply"]', td);
if ($.x('ancestor::div[@class="thread"]', next) !== thread) return; }
if (!next) {
td.className = 'replyhl';
td.tabIndex = 0;
next.focus();
return;
}
if (!(g.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) {
return;
}
rect = next.getBoundingClientRect(); rect = next.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top < 0 || rect.bottom > d.body.clientHeight) {
next.scrollIntoView(delta === -1);
}
next.className = 'replyhl'; next.className = 'replyhl';
} next.tabIndex = 0;
next.focus();
return; return;
} }
} replies = $$('.reply', thread);
replies = $$('td.reply', thread); if (delta === -1) replies.reverse();
for (_i = 0, _len = replies.length; _i < _len; _i++) { for (_i = 0, _len = replies.length; _i < _len; _i++) {
reply = replies[_i]; reply = replies[_i];
top = reply.getBoundingClientRect().top; rect = reply.getBoundingClientRect();
if (top > 0) { if (delta === +1 && rect.top >= 0 || delta === -1 && rect.bottom <= d.body.clientHeight) {
reply.className = 'replyhl'; reply.className = 'replyhl';
reply.tabIndex = 0;
reply.focus();
return; return;
} }
} }
},
prev: function(thread) {
var bot, height, prev, rect, replies, reply, td, _i, _len;
if (td = $('td.replyhl', thread)) {
td.className = 'reply';
rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
prev = $.x('preceding::td[@class="reply"][1]', td);
rect = prev.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
prev.className = 'replyhl';
}
return;
}
}
replies = $$('td.reply', thread);
replies.reverse();
height = d.body.clientHeight;
for (_i = 0, _len = replies.length; _i < _len; _i++) {
reply = replies[_i];
bot = reply.getBoundingClientRect().bottom;
if (bot < height) {
reply.className = 'replyhl';
return;
}
}
}
} }
}; };
@ -1247,7 +1234,6 @@
return Nav.scroll(+1); return Nav.scroll(+1);
} }
}, },
threads: [],
getThread: function(full) { getThread: function(full) {
var bottom, i, rect, thread, _len, _ref; var bottom, i, rect, thread, _len, _ref;
Nav.threads = $$('.thread:not([hidden])'); Nav.threads = $$('.thread:not([hidden])');
@ -1261,7 +1247,7 @@
return thread; return thread;
} }
} }
return null; return $('form[name=delform]');
}, },
scroll: function(delta) { scroll: function(delta) {
var i, rect, thread, top, _ref, _ref2; var i, rect, thread, top, _ref, _ref2;

View File

@ -4,6 +4,7 @@ master
Threads will now be updated instantly after posting through the QR. Threads will now be updated instantly after posting through the QR.
Your own posts will not count toward the unread count after posting through the QR. Your own posts will not count toward the unread count after posting through the QR.
QR thumbnails of high-res pictures will not slow down anymore. QR thumbnails of high-res pictures will not slow down anymore.
Reply navigation keybinds will now scroll as you navigate.
- noface - noface
Add unique ID to filter. Add unique ID to filter.

View File

@ -888,9 +888,9 @@ Keybinds =
Keybinds.open thread, true Keybinds.open thread, true
# Reply Navigation # Reply Navigation
when conf.nextReply when conf.nextReply
Keybinds.hl.next thread Keybinds.hl +1, thread
when conf.previousReply when conf.previousReply
Keybinds.hl.prev thread Keybinds.hl -1, thread
when conf.hide when conf.hide
ThreadHiding.toggle thread ThreadHiding.toggle thread
else else
@ -943,44 +943,39 @@ Keybinds =
else else
location.href = url location.href = url
hl: hl: (delta, thread) ->
next: (thread) -> if td = $ '.replyhl', thread
if td = $ 'td.replyhl', thread
td.className = 'reply' td.className = 'reply'
td.removeAttribute 'tabindex'
rect = td.getBoundingClientRect() rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're fully visible if rect.bottom >= 0 and rect.top <= d.body.clientHeight # We're at least partially visible
next = $.x 'following::td[@class="reply"]', td next =
return if $.x('ancestor::div[@class="thread"]', next) isnt thread if delta is +1
$.x 'following::td[@class="reply"]', td
else
$.x 'preceding::td[@class="reply"]', td
unless next
td.className = 'replyhl'
td.tabIndex = 0
next.focus()
return
return unless g.REPLY or $.x('ancestor::div[@class="thread"]', next) is thread
rect = next.getBoundingClientRect() rect = next.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next if rect.top < 0 or rect.bottom > d.body.clientHeight
next.scrollIntoView delta is -1
next.className = 'replyhl' next.className = 'replyhl'
next.tabIndex = 0
next.focus()
return return
replies = $$ 'td.reply', thread replies = $$ '.reply', thread
replies.reverse() if delta is -1
for reply in replies for reply in replies
top = reply.getBoundingClientRect().top rect = reply.getBoundingClientRect()
if top > 0 if delta is +1 and rect.top >= 0 or delta is -1 and rect.bottom <= d.body.clientHeight
reply.className = 'replyhl'
return
prev: (thread) ->
if td = $ 'td.replyhl', thread
td.className = 'reply'
rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're fully visible
prev = $.x 'preceding::td[@class="reply"][1]', td
rect = prev.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev
prev.className = 'replyhl'
return
replies = $$ 'td.reply', thread
replies.reverse()
height = d.body.clientHeight
for reply in replies
bot = reply.getBoundingClientRect().bottom
if bot < height
reply.className = 'replyhl' reply.className = 'replyhl'
reply.tabIndex = 0
reply.focus()
return return
Nav = Nav =
@ -1013,8 +1008,6 @@ Nav =
else else
Nav.scroll +1 Nav.scroll +1
threads: []
getThread: (full) -> getThread: (full) ->
Nav.threads = $$ '.thread:not([hidden])' Nav.threads = $$ '.thread:not([hidden])'
for thread, i in Nav.threads for thread, i in Nav.threads
@ -1024,7 +1017,7 @@ Nav =
if full if full
return [thread, i, rect] return [thread, i, rect]
return thread return thread
return null return $ 'form[name=delform]'
scroll: (delta) -> scroll: (delta) ->
[thread, i, rect] = Nav.getThread true [thread, i, rect] = Nav.getThread true