Fix some bugs with forwardlink indication, and extend it to inlined quotes. #361

This commit is contained in:
ccd0 2015-12-13 02:53:18 -08:00
parent 77142c23db
commit 6b167d42b9
7 changed files with 20 additions and 22 deletions

View File

@ -21,8 +21,6 @@ Get =
if index then post.clones[index] else post if index then post.clones[index] else post
postFromNode: (root) -> postFromNode: (root) ->
Get.postFromRoot $.x '(ancestor::div[contains(@class,"postContainer")][1]|following::div[contains(@class,"postContainer")][1])', root Get.postFromRoot $.x '(ancestor::div[contains(@class,"postContainer")][1]|following::div[contains(@class,"postContainer")][1])', root
contextFromNode: (node) ->
Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', node
postDataFromLink: (link) -> postDataFromLink: (link) ->
if link.hostname is 'boards.4chan.org' if link.hostname is 'boards.4chan.org'
path = link.pathname.split /\/+/ path = link.pathname.split /\/+/

View File

@ -14,7 +14,7 @@ QuoteCT =
# Stop there if it's a clone of a post in the same thread. # Stop there if it's a clone of a post in the same thread.
return if @isClone and @thread is @context.thread return if @isClone and @thread is @context.thread
{board, thread} = if @isClone then @context else @ {board, thread} = @context
for quotelink in @nodes.quotelinks for quotelink in @nodes.quotelinks
{boardID, threadID} = Get.postDataFromLink quotelink {boardID, threadID} = Get.postDataFromLink quotelink
continue unless threadID # deadlink continue unless threadID # deadlink

View File

@ -34,12 +34,13 @@ QuoteInline =
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
e.preventDefault() e.preventDefault()
{boardID, threadID, postID} = Get.postDataFromLink @ {boardID, threadID, postID} = Get.postDataFromLink @
context = Get.contextFromNode @ quoter = Get.postFromNode @
{context} = quoter
if $.hasClass @, 'inlined' if $.hasClass @, 'inlined'
QuoteInline.rm @, boardID, threadID, postID, context QuoteInline.rm @, boardID, threadID, postID, context
else else
return if $.x "ancestor::div[@id='pc#{postID}']", @ return if $.x "ancestor::div[@id='pc#{postID}']", @
QuoteInline.add @, boardID, threadID, postID, context QuoteInline.add @, boardID, threadID, postID, context, quoter
@classList.toggle 'inlined' @classList.toggle 'inlined'
findRoot: (quotelink, isBacklink) -> findRoot: (quotelink, isBacklink) ->
@ -48,7 +49,7 @@ QuoteInline =
else else
$.x 'ancestor-or-self::*[parent::blockquote][1]', quotelink $.x 'ancestor-or-self::*[parent::blockquote][1]', quotelink
add: (quotelink, boardID, threadID, postID, context) -> add: (quotelink, boardID, threadID, postID, context, quoter) ->
isBacklink = $.hasClass quotelink, 'backlink' isBacklink = $.hasClass quotelink, 'backlink'
inline = $.el 'div', inline = $.el 'div',
id: "i#{postID}" id: "i#{postID}"
@ -59,7 +60,7 @@ QuoteInline =
qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root
$.addClass qroot, 'hasInline' $.addClass qroot, 'hasInline'
new Fetcher boardID, threadID, postID, inline, context new Fetcher boardID, threadID, postID, inline, quoter
return unless (post = g.posts["#{boardID}.#{postID}"]) and return unless (post = g.posts["#{boardID}.#{postID}"]) and
context.thread is post.thread context.thread is post.thread

View File

@ -24,7 +24,7 @@ QuoteOP =
while quotelink = quotelinks[i++] while quotelink = quotelinks[i++]
quotelink.textContent = quotelink.textContent.replace QuoteOP.text, '' quotelink.textContent = quotelink.textContent.replace QuoteOP.text, ''
{fullID} = (if @isClone then @context else @).thread {fullID} = @context.thread
# add (OP) to quotes quoting this context's OP. # add (OP) to quotes quoting this context's OP.
return unless fullID in quotes return unless fullID in quotes

View File

@ -24,7 +24,7 @@ QuotePreview =
className: 'dialog' className: 'dialog'
$.add Header.hover, qp $.add Header.hover, qp
new Fetcher boardID, threadID, postID, qp, Get.contextFromNode @ new Fetcher boardID, threadID, postID, qp, Get.postFromNode(@)
UI.hover UI.hover
root: @ root: @
@ -33,20 +33,12 @@ QuotePreview =
endEvents: 'mouseout click' endEvents: 'mouseout click'
cb: QuotePreview.mouseout cb: QuotePreview.mouseout
return unless origin = g.posts["#{boardID}.#{postID}"] if Conf['Quote Highlighting'] and (origin = g.posts["#{boardID}.#{postID}"])
if Conf['Quote Highlighting']
posts = [origin].concat origin.clones posts = [origin].concat origin.clones
# Remove the clone that's in the qp from the array. # Remove the clone that's in the qp from the array.
posts.pop() posts.pop()
for post in posts for post in posts
$.addClass post.nodes.post, 'qphl' $.addClass post.nodes.post, 'qphl'
quoterID = $.x('ancestor::*[@id][1]', @).id.match(/\d+$/)[0]
clone = Get.postFromRoot qp.firstChild
for quote in clone.nodes.quotelinks.concat [clone.nodes.backlinks...]
if quote.hash[2..] is quoterID
$.addClass quote, 'forwardlink'
return return
mouseout: -> mouseout: ->

View File

@ -1,5 +1,5 @@
class Fetcher class Fetcher
constructor: (@boardID, @threadID, @postID, @root, @context) -> constructor: (@boardID, @threadID, @postID, @root, @quoter) ->
if post = g.posts["#{@boardID}.#{@postID}"] if post = g.posts["#{@boardID}.#{@postID}"]
@insert post @insert post
return return
@ -14,7 +14,7 @@ class Fetcher
insert: (post) -> insert: (post) ->
# Stop here if the container has been removed while loading. # Stop here if the container has been removed while loading.
return unless @root.parentNode return unless @root.parentNode
clone = post.addClone @context, ($.hasClass @root, 'dialog') clone = post.addClone @quoter.context, ($.hasClass @root, 'dialog')
Main.callbackNodes Clone, [clone] Main.callbackNodes Clone, [clone]
# Get rid of the side arrows/stubs. # Get rid of the side arrows/stubs.
@ -22,6 +22,12 @@ class Fetcher
$.rmAll nodes.root $.rmAll nodes.root
$.add nodes.root, nodes.post $.add nodes.root, nodes.post
# Indicate links to the containing post.
quoterURL = "/#{@quoter.board}/thread/#{@quoter.thread}#p#{@quoter}"
for quote in clone.nodes.quotelinks.concat [clone.nodes.backlinks...]
if quote.pathname + quote.hash is quoterURL
$.addClass quote, 'forwardlink'
$.rmAll @root $.rmAll @root
$.add @root, nodes.root $.add @root, nodes.root
$.event 'PostsInserted' $.event 'PostsInserted'

View File

@ -26,8 +26,9 @@ class Post
@normalizedOriginal = root2 @normalizedOriginal = root2
<% } %> <% } %>
@ID = +root.id[2..] @ID = +root.id[2..]
@fullID = "#{@board}.#{@ID}" @fullID = "#{@board}.#{@ID}"
@context = @
post = $ '.post', root post = $ '.post', root
info = $ '.postInfo', post info = $ '.postInfo', post