Make reply navigation keybinds work on Tinyboard/vichan. #2171

This commit is contained in:
ccd0 2019-07-22 20:54:10 -07:00
parent 114d234c87
commit 4da095626c
3 changed files with 31 additions and 17 deletions

View File

@ -269,7 +269,11 @@ Keybinds =
key key
post: (thread) -> post: (thread) ->
$('.post.highlight', thread) or $('.op', thread) s = g.SITE.selectors
(
$("#{s.postContainer}#{s.highlightable.reply}.#{g.SITE.classes.highlight}", thread) or
$("#{if g.SITE.isOPContainerThread then s.thread else s.postContainer}#{s.highlightable.op}", thread)
)
qr: (thread) -> qr: (thread) ->
QR.open() QR.open()
@ -318,33 +322,35 @@ Keybinds =
location.href = url location.href = url
hl: (delta, thread) -> hl: (delta, thread) ->
postEl = $ '.reply.highlight', thread replySelector = "#{g.SITE.selectors.postContainer}#{g.SITE.selectors.highlightable.reply}"
{highlight} = g.SITE.classes
postEl = $ "#{replySelector}.#{highlight}", thread
unless delta unless delta
$.rmClass postEl, 'highlight' if postEl $.rmClass postEl, highlight if postEl
return return
if postEl if postEl
{height} = postEl.getBoundingClientRect() {height} = postEl.getBoundingClientRect()
if Header.getTopOf(postEl) >= -height and Header.getBottomOf(postEl) >= -height # We're at least partially visible if Header.getTopOf(postEl) >= -height and Header.getBottomOf(postEl) >= -height # We're at least partially visible
root = postEl.parentNode {root} = Get.postFromNode(postEl).nodes
axis = if delta is +1 axis = if delta is +1
'following' 'following'
else else
'preceding' 'preceding'
return if not (next = $.x "#{axis}-sibling::div[contains(@class,'replyContainer') and not(@hidden) and not(child::div[@class='stub'])][1]/child::div[contains(@class,'reply')]", root) return unless (next = $.x "#{axis}-sibling::#{g.SITE.xpath.replyContainer}[not(@hidden) and not(child::div[@class='stub'])][1]", root)
next = $ replySelector, next unless next.matches(replySelector)
Header.scrollToIfNeeded next, delta is +1 Header.scrollToIfNeeded next, delta is +1
@focus next $.addClass next, highlight
$.rmClass postEl, 'highlight' $.rmClass postEl, highlight
return return
$.rmClass postEl, 'highlight' $.rmClass postEl, highlight
replies = $$ '.reply', thread replies = $$ replySelector, thread
replies.reverse() if delta is -1 replies.reverse() if delta is -1
for reply in replies for reply in replies
if delta is +1 and Header.getTopOf(reply) > 0 or delta is -1 and Header.getBottomOf(reply) > 0 if delta is +1 and Header.getTopOf(reply) > 0 or delta is -1 and Header.getBottomOf(reply) > 0
@focus reply $.addClass reply, highlight
return return
return
focus: (post) ->
$.addClass post, 'highlight'

View File

@ -110,9 +110,13 @@ SW.tinyboard =
prev: '.pages > form > [value=Previous]' prev: '.pages > form > [value=Previous]'
next: '.pages > form > [value=Next]' next: '.pages > form > [value=Next]'
classes:
highlight: 'highlighted'
xpath: xpath:
thread: 'div[starts-with(@id,"thread_")]' thread: 'div[starts-with(@id,"thread_")]'
postContainer: 'div[starts-with(@id,"reply_") or starts-with(@id,"thread_")]' postContainer: 'div[starts-with(@id,"reply_") or starts-with(@id,"thread_")]'
replyContainer: 'div[starts-with(@id,"reply_")]'
regexp: regexp:
quotelink: quotelink:

View File

@ -75,9 +75,13 @@ SW.yotsuba =
prev: '.prev > form > [type=submit]' prev: '.prev > form > [type=submit]'
next: '.next > form > [type=submit]' next: '.next > form > [type=submit]'
classes:
highlight: 'highlight'
xpath: xpath:
thread: 'div[contains(concat(" ",@class," ")," thread ")]' thread: 'div[contains(concat(" ",@class," ")," thread ")]'
postContainer: 'div[contains(@class,"postContainer")]' postContainer: 'div[contains(@class,"postContainer")]'
replyContainer: 'div[contains(@class,"replyContainer")]'
regexp: regexp:
quotelink: quotelink: