From 3581a235e75b4ee15177221596534af2bbada435 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 13 Aug 2013 16:29:54 +0200 Subject: [PATCH] Fix post menus in stubs. Also removed some old arguments, fixed some semantics, added Get.threadFromNode, and used it. --- src/Filtering/PostHiding.coffee | 2 +- src/Filtering/ThreadHiding.coffee | 2 +- src/General/Get.coffee | 10 ++++++---- src/Menu/Menu.coffee | 20 ++++++++++++++------ src/Miscellaneous/ExpandThread.coffee | 2 +- src/Posting/QR.coffee | 2 +- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Filtering/PostHiding.coffee b/src/Filtering/PostHiding.coffee index bfa586e50..74bef51d8 100644 --- a/src/Filtering/PostHiding.coffee +++ b/src/Filtering/PostHiding.coffee @@ -166,7 +166,7 @@ PostHiding = className: 'stub' $.add post.nodes.stub, a if Conf['Menu'] - $.add post.nodes.stub, [$.tn(' '), Menu.makeButton post] + $.add post.nodes.stub, [$.tn(' '), Menu.makeButton()] $.prepend post.nodes.root, post.nodes.stub show: (post, showRecursively=Conf['Recursive Hiding']) -> diff --git a/src/Filtering/ThreadHiding.coffee b/src/Filtering/ThreadHiding.coffee index 49d3607f3..65fd05f0a 100644 --- a/src/Filtering/ThreadHiding.coffee +++ b/src/Filtering/ThreadHiding.coffee @@ -151,7 +151,7 @@ ThreadHiding = className: 'stub' $.add thread.stub, a if Conf['Menu'] - $.add thread.stub, [$.tn(' '), Menu.makeButton OP] + $.add thread.stub, [$.tn(' '), Menu.makeButton()] $.prepend threadRoot, thread.stub show: (thread) -> diff --git a/src/General/Get.coffee b/src/General/Get.coffee index fe2a056b0..d5f2334a0 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -10,6 +10,8 @@ Get = "/#{thread.board}/ - #{excerpt}" threadFromRoot: (root) -> g.threads["#{g.BOARD}.#{root.id[1..]}"] + threadFromNode: (node) -> + Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node postFromRoot: (root) -> link = $ 'a[title="Highlight this post"]', root boardID = link.pathname.split('/')[1] @@ -17,10 +19,10 @@ Get = index = root.dataset.clone post = g.posts["#{boardID}.#{postID}"] if index then post.clones[index] else post - postFromNode: (root) -> - Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', root - contextFromNode: (quotelink) -> - Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', quotelink + postFromNode: (node) -> + Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', node + 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/Menu/Menu.coffee b/src/Menu/Menu.coffee index 0c5bc4af9..94ed4896d 100644 --- a/src/Menu/Menu.coffee +++ b/src/Menu/Menu.coffee @@ -10,10 +10,10 @@ Menu = node: -> if @isClone button = $ '.menu-button', @nodes.info - else - button = Menu.makeButton @ - $.add @nodes.info, [$.tn('\u00A0'), button] - $.on button, 'click', Menu.toggle + $.on button, 'click', Menu.toggle + return + button = Menu.makeButton() + $.add @nodes.info, [$.tn('\u00A0'), button] makeButton: do -> a = null @@ -22,7 +22,15 @@ Menu = className: 'menu-button' innerHTML: '[]' href: 'javascript:;' - a.cloneNode true + button = a.cloneNode true + $.on button, 'click', Menu.toggle + button toggle: (e) -> - Menu.menu.toggle e, @, Get.postFromNode @ + try + # Posts, inlined posts, hidden replies. + post = Get.postFromNode @ + catch + # Hidden threads. + post = Get.threadFromNode(@).OP + Menu.menu.toggle e, @, post diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index c18bd8088..513a24368 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -23,7 +23,7 @@ ExpandThread = text.join(' ') + '.' cbToggle: -> - ExpandThread.toggle Get.threadFromRoot @parentNode + ExpandThread.toggle Get.threadFromNode @ toggle: (thread) -> threadRoot = thread.OP.nodes.root.parentNode diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 7c6d0afdf..88a226a9e 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -340,7 +340,7 @@ QR = $.addClass QR.nodes.el, 'dump' QR.cooldown.auto = true {com, thread} = QR.nodes - thread.value = Get.contextFromNode(@).thread unless com.value + thread.value = Get.threadFromNode @ unless com.value caretPos = com.selectionStart # Replace selection for text.