Fix post menus in stubs.

Also removed some old arguments, fixed some semantics, added Get.threadFromNode, and used it.
This commit is contained in:
Mayhem 2013-08-13 16:29:54 +02:00
parent 6769610899
commit 3581a235e7
6 changed files with 24 additions and 14 deletions

View File

@ -166,7 +166,7 @@ PostHiding =
className: 'stub' className: 'stub'
$.add post.nodes.stub, a $.add post.nodes.stub, a
if Conf['Menu'] 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 $.prepend post.nodes.root, post.nodes.stub
show: (post, showRecursively=Conf['Recursive Hiding']) -> show: (post, showRecursively=Conf['Recursive Hiding']) ->

View File

@ -151,7 +151,7 @@ ThreadHiding =
className: 'stub' className: 'stub'
$.add thread.stub, a $.add thread.stub, a
if Conf['Menu'] if Conf['Menu']
$.add thread.stub, [$.tn(' '), Menu.makeButton OP] $.add thread.stub, [$.tn(' '), Menu.makeButton()]
$.prepend threadRoot, thread.stub $.prepend threadRoot, thread.stub
show: (thread) -> show: (thread) ->

View File

@ -10,6 +10,8 @@ Get =
"/#{thread.board}/ - #{excerpt}" "/#{thread.board}/ - #{excerpt}"
threadFromRoot: (root) -> threadFromRoot: (root) ->
g.threads["#{g.BOARD}.#{root.id[1..]}"] g.threads["#{g.BOARD}.#{root.id[1..]}"]
threadFromNode: (node) ->
Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node
postFromRoot: (root) -> postFromRoot: (root) ->
link = $ 'a[title="Highlight this post"]', root link = $ 'a[title="Highlight this post"]', root
boardID = link.pathname.split('/')[1] boardID = link.pathname.split('/')[1]
@ -17,10 +19,10 @@ Get =
index = root.dataset.clone index = root.dataset.clone
post = g.posts["#{boardID}.#{postID}"] post = g.posts["#{boardID}.#{postID}"]
if index then post.clones[index] else post if index then post.clones[index] else post
postFromNode: (root) -> postFromNode: (node) ->
Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', root Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', node
contextFromNode: (quotelink) -> contextFromNode: (node) ->
Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', quotelink 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

@ -10,10 +10,10 @@ Menu =
node: -> node: ->
if @isClone if @isClone
button = $ '.menu-button', @nodes.info button = $ '.menu-button', @nodes.info
else $.on button, 'click', Menu.toggle
button = Menu.makeButton @ return
$.add @nodes.info, [$.tn('\u00A0'), button] button = Menu.makeButton()
$.on button, 'click', Menu.toggle $.add @nodes.info, [$.tn('\u00A0'), button]
makeButton: do -> makeButton: do ->
a = null a = null
@ -22,7 +22,15 @@ Menu =
className: 'menu-button' className: 'menu-button'
innerHTML: '[<i></i>]' innerHTML: '[<i></i>]'
href: 'javascript:;' href: 'javascript:;'
a.cloneNode true button = a.cloneNode true
$.on button, 'click', Menu.toggle
button
toggle: (e) -> 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

View File

@ -23,7 +23,7 @@ ExpandThread =
text.join(' ') + '.' text.join(' ') + '.'
cbToggle: -> cbToggle: ->
ExpandThread.toggle Get.threadFromRoot @parentNode ExpandThread.toggle Get.threadFromNode @
toggle: (thread) -> toggle: (thread) ->
threadRoot = thread.OP.nodes.root.parentNode threadRoot = thread.OP.nodes.root.parentNode

View File

@ -340,7 +340,7 @@ QR =
$.addClass QR.nodes.el, 'dump' $.addClass QR.nodes.el, 'dump'
QR.cooldown.auto = true QR.cooldown.auto = true
{com, thread} = QR.nodes {com, thread} = QR.nodes
thread.value = Get.contextFromNode(@).thread unless com.value thread.value = Get.threadFromNode @ unless com.value
caretPos = com.selectionStart caretPos = com.selectionStart
# Replace selection for text. # Replace selection for text.