From 6b167d42b940751534a59f7fd7445d1207144cf0 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 13 Dec 2015 02:53:18 -0800 Subject: [PATCH] Fix some bugs with forwardlink indication, and extend it to inlined quotes. #361 --- src/General/Get.coffee | 2 -- src/Quotelinks/QuoteCT.coffee | 2 +- src/Quotelinks/QuoteInline.coffee | 9 +++++---- src/Quotelinks/QuoteOP.coffee | 2 +- src/Quotelinks/QuotePreview.coffee | 12 ++---------- src/classes/Fetcher.coffee | 10 ++++++++-- src/classes/Post.coffee | 5 +++-- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/General/Get.coffee b/src/General/Get.coffee index 636d463e9..f87a17342 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -21,8 +21,6 @@ Get = if index then post.clones[index] else post postFromNode: (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) -> if link.hostname is 'boards.4chan.org' path = link.pathname.split /\/+/ diff --git a/src/Quotelinks/QuoteCT.coffee b/src/Quotelinks/QuoteCT.coffee index fd2de4796..7a32dc8d5 100644 --- a/src/Quotelinks/QuoteCT.coffee +++ b/src/Quotelinks/QuoteCT.coffee @@ -14,7 +14,7 @@ QuoteCT = # Stop there if it's a clone of a post in the same thread. return if @isClone and @thread is @context.thread - {board, thread} = if @isClone then @context else @ + {board, thread} = @context for quotelink in @nodes.quotelinks {boardID, threadID} = Get.postDataFromLink quotelink continue unless threadID # deadlink diff --git a/src/Quotelinks/QuoteInline.coffee b/src/Quotelinks/QuoteInline.coffee index bcfa798f7..df4f1ba4f 100644 --- a/src/Quotelinks/QuoteInline.coffee +++ b/src/Quotelinks/QuoteInline.coffee @@ -34,12 +34,13 @@ QuoteInline = return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 e.preventDefault() {boardID, threadID, postID} = Get.postDataFromLink @ - context = Get.contextFromNode @ + quoter = Get.postFromNode @ + {context} = quoter if $.hasClass @, 'inlined' QuoteInline.rm @, boardID, threadID, postID, context else return if $.x "ancestor::div[@id='pc#{postID}']", @ - QuoteInline.add @, boardID, threadID, postID, context + QuoteInline.add @, boardID, threadID, postID, context, quoter @classList.toggle 'inlined' findRoot: (quotelink, isBacklink) -> @@ -48,7 +49,7 @@ QuoteInline = else $.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' inline = $.el 'div', id: "i#{postID}" @@ -59,7 +60,7 @@ QuoteInline = qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root $.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 context.thread is post.thread diff --git a/src/Quotelinks/QuoteOP.coffee b/src/Quotelinks/QuoteOP.coffee index e673c2f8d..6e0f212b6 100644 --- a/src/Quotelinks/QuoteOP.coffee +++ b/src/Quotelinks/QuoteOP.coffee @@ -24,7 +24,7 @@ QuoteOP = while quotelink = quotelinks[i++] 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. return unless fullID in quotes diff --git a/src/Quotelinks/QuotePreview.coffee b/src/Quotelinks/QuotePreview.coffee index 433de5235..43fc8ab54 100644 --- a/src/Quotelinks/QuotePreview.coffee +++ b/src/Quotelinks/QuotePreview.coffee @@ -24,7 +24,7 @@ QuotePreview = className: 'dialog' $.add Header.hover, qp - new Fetcher boardID, threadID, postID, qp, Get.contextFromNode @ + new Fetcher boardID, threadID, postID, qp, Get.postFromNode(@) UI.hover root: @ @@ -33,20 +33,12 @@ QuotePreview = endEvents: 'mouseout click' cb: QuotePreview.mouseout - return unless origin = g.posts["#{boardID}.#{postID}"] - - if Conf['Quote Highlighting'] + if Conf['Quote Highlighting'] and (origin = g.posts["#{boardID}.#{postID}"]) posts = [origin].concat origin.clones # Remove the clone that's in the qp from the array. posts.pop() for post in posts $.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 mouseout: -> diff --git a/src/classes/Fetcher.coffee b/src/classes/Fetcher.coffee index f4829c3b2..1851f432e 100644 --- a/src/classes/Fetcher.coffee +++ b/src/classes/Fetcher.coffee @@ -1,5 +1,5 @@ class Fetcher - constructor: (@boardID, @threadID, @postID, @root, @context) -> + constructor: (@boardID, @threadID, @postID, @root, @quoter) -> if post = g.posts["#{@boardID}.#{@postID}"] @insert post return @@ -14,7 +14,7 @@ class Fetcher insert: (post) -> # Stop here if the container has been removed while loading. return unless @root.parentNode - clone = post.addClone @context, ($.hasClass @root, 'dialog') + clone = post.addClone @quoter.context, ($.hasClass @root, 'dialog') Main.callbackNodes Clone, [clone] # Get rid of the side arrows/stubs. @@ -22,6 +22,12 @@ class Fetcher $.rmAll nodes.root $.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 $.add @root, nodes.root $.event 'PostsInserted' diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index 97f84fa6a..a960b3e8e 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -26,8 +26,9 @@ class Post @normalizedOriginal = root2 <% } %> - @ID = +root.id[2..] - @fullID = "#{@board}.#{@ID}" + @ID = +root.id[2..] + @fullID = "#{@board}.#{@ID}" + @context = @ post = $ '.post', root info = $ '.postInfo', post