Force stub menu to work

This commit is contained in:
Zixaphir 2013-08-09 18:52:49 -07:00
parent da2a99c0ca
commit 22f4dd698a
8 changed files with 237 additions and 166 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -109,11 +109,12 @@ PostHiding =
PostHiding.hide post, makeStub, replies PostHiding.hide post, makeStub, replies
else if replies else if replies
Recursive.apply PostHiding.hide, post, makeStub, true Recursive.apply PostHiding.hide, post, makeStub, true
Recursive.add PostHiding.hide, post, makeStub, true Recursive.add PostHiding.hide, post, makeStub, true
else else
return return
PostHiding.saveHiddenState post, true, thisPost, makeStub, replies PostHiding.saveHiddenState post, true, thisPost, makeStub, replies
$.event 'CloseMenu' $.event 'CloseMenu'
show: -> show: ->
parent = @parentNode parent = @parentNode
thisPost = $('input[name=thisPost]', parent).checked thisPost = $('input[name=thisPost]', parent).checked
@ -123,12 +124,13 @@ PostHiding =
PostHiding.show post, replies PostHiding.show post, replies
else if replies else if replies
Recursive.apply PostHiding.show, post, true Recursive.apply PostHiding.show, post, true
Recursive.rm PostHiding.hide, post, true Recursive.rm PostHiding.hide, post, true
else else
return return
if data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID} if data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
PostHiding.saveHiddenState post, !(thisPost and replies), !thisPost, data.makeStub, !replies PostHiding.saveHiddenState post, !(thisPost and replies), !thisPost, data.makeStub, !replies
$.event 'CloseMenu' $.event 'CloseMenu'
hideStub: -> hideStub: ->
{post} = PostHiding.menu {post} = PostHiding.menu
post.nodes.root.hidden = true post.nodes.root.hidden = true
@ -159,10 +161,8 @@ PostHiding =
toggle: -> toggle: ->
post = Get.postFromNode @ post = Get.postFromNode @
if post.isHidden
PostHiding.show post PostHiding[(if post.isHidden then 'show' else 'hide')] post
else
PostHiding.hide post
PostHiding.saveHiddenState post, post.isHidden PostHiding.saveHiddenState post, post.isHidden
hide: (post, makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) -> hide: (post, makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) ->
@ -171,7 +171,7 @@ PostHiding =
if hideRecursively if hideRecursively
Recursive.apply PostHiding.hide, post, makeStub, true Recursive.apply PostHiding.hide, post, makeStub, true
Recursive.add PostHiding.hide, post, makeStub, true Recursive.add PostHiding.hide, post, makeStub, true
for quotelink in Get.allQuotelinksLinkingTo post for quotelink in Get.allQuotelinksLinkingTo post
$.addClass quotelink, 'filtered' $.addClass quotelink, 'filtered'
@ -185,13 +185,14 @@ PostHiding =
if Conf['Anonymize'] if Conf['Anonymize']
'Anonymous' 'Anonymous'
else else
$('.nameBlock', post.nodes.info).textContent post.info.name
$.add a, $.tn " #{postInfo}" $.add a, $.tn " #{postInfo}"
post.nodes.stub = $.el 'div', post.nodes.stub = $.el 'div',
className: 'stub' className: 'stub'
$.add post.nodes.stub, a $.add post.nodes.stub, unless Conf['Menu']
if Conf['Menu'] a
$.add post.nodes.stub, [$.tn(' '), Menu.makeButton post] else
[a, $.tn(' '), button = Menu.makeButton post]
$.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

@ -59,10 +59,16 @@ ThreadHiding =
init: -> init: ->
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding Link'] return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding Link']
div = $.el 'div', hide = $.el 'div',
className: 'hide-thread-link' className: 'hide-thread-link'
textContent: 'Hide thread' textContent: 'Hide thread'
show = $.el 'a',
className: 'show-thread-link'
textContent: 'Show thread'
href: 'javascript:;'
$.on show, 'click', ThreadHiding.menu.show
apply = $.el 'a', apply = $.el 'a',
textContent: 'Apply' textContent: 'Apply'
href: 'javascript:;' href: 'javascript:;'
@ -78,7 +84,7 @@ ThreadHiding =
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
type: 'post' type: 'post'
el: div el: hide
order: 20 order: 20
open: ({thread, isReply}) -> open: ({thread, isReply}) ->
if isReply or thread.isHidden if isReply or thread.isHidden
@ -87,6 +93,16 @@ ThreadHiding =
true true
subEntries: [el: apply; el: makeStub] subEntries: [el: apply; el: makeStub]
$.event 'AddMenuEntry',
type: 'post'
el: show
order: 20
open: ({thread, isReply}) ->
if isReply or !thread.isHidden
return false
ThreadHiding.menu.thread = thread
true
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
type: 'post' type: 'post'
el: hideStubLink el: hideStubLink
@ -102,6 +118,13 @@ ThreadHiding =
ThreadHiding.hide thread, makeStub ThreadHiding.hide thread, makeStub
ThreadHiding.saveHiddenState thread, makeStub ThreadHiding.saveHiddenState thread, makeStub
$.event 'CloseMenu' $.event 'CloseMenu'
show: ->
{thread} = ThreadHiding.menu
ThreadHiding.show thread
ThreadHiding.saveHiddenState thread
$.event 'CloseMenu'
hideStub: -> hideStub: ->
{thread} = ThreadHiding.menu {thread} = ThreadHiding.menu
ThreadHiding.hide thread, false ThreadHiding.hide thread, false
@ -150,24 +173,28 @@ ThreadHiding =
threadRoot.hidden = threadRoot.nextElementSibling.hidden = true # <hr> threadRoot.hidden = threadRoot.nextElementSibling.hidden = true # <hr>
return return
numReplies = 0 numReplies = (
if span = $ '.summary', threadRoot if span = $ '.summary', threadRoot
numReplies = +span.textContent.match /\d+/ +span.textContent.match /\d+/
numReplies += $$('.opContainer ~ .replyContainer', threadRoot).length else
numReplies = if numReplies is 1 then '1 reply' else "#{numReplies} replies" 0
) +
$$('.opContainer ~ .replyContainer', threadRoot).length
numReplies = if numReplies is 1 then '1 reply' else "#{numReplies or 'no'} replies"
opInfo = opInfo =
if Conf['Anonymize'] if Conf['Anonymize']
'Anonymous' 'Anonymous'
else else
$('.nameBlock', OP.nodes.info).textContent OP.info.name
a = ThreadHiding.makeButton thread, 'show' a = ThreadHiding.makeButton thread, 'show'
$.add a, $.tn " #{opInfo} (#{numReplies})" $.add a, $.tn " #{opInfo} (#{numReplies})"
thread.stub = $.el 'div', thread.stub = $.el 'div',
className: 'stub' className: 'stub'
$.add thread.stub, a $.add thread.stub, unless Conf['Menu']
if Conf['Menu'] a
$.add thread.stub, [$.tn(' '), Menu.makeButton OP] else
[a, $.tn(' '), button = Menu.makeButton OP]
$.prepend threadRoot, thread.stub $.prepend threadRoot, thread.stub
show: (thread) -> show: (thread) ->

View File

@ -18,7 +18,7 @@ Get =
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: (root) ->
Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', root Get.postFromRoot $.x '(ancestor::div[contains(@class,"postContainer")]|following::div[contains(@class,"postContainer")])[1]', root
contextFromNode: (quotelink) -> contextFromNode: (quotelink) ->
Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', quotelink Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', quotelink
postDataFromLink: (link) -> postDataFromLink: (link) ->

View File

@ -1168,6 +1168,7 @@ a.useremail:last-of-type {
.fit-width-replies .stub { .fit-width-replies .stub {
display: block; display: block;
text-align: right; text-align: right;
clear: both;
} }
/* Element Replacing: */ /* Element Replacing: */
/* Checkboxes */ /* Checkboxes */

View File

@ -1,4 +1,9 @@
Menu = Menu = do ->
a = $.el 'a',
className: 'menu-button brackets-wrap'
innerHTML: '<span class=drop-marker></span>'
href: 'javascript:;'
init: -> init: ->
return if g.VIEW is 'catalog' or !Conf['Menu'] return if g.VIEW is 'catalog' or !Conf['Menu']
@ -11,18 +16,15 @@ Menu =
if @isClone if @isClone
button = $ '.menu-button', @nodes.info button = $ '.menu-button', @nodes.info
else else
button = Menu.makeButton @ button = a.cloneNode true
$.add @nodes.info, [$.tn('\u00A0'), button] $.add @nodes.info, [$.tn('\u00A0'), button]
$.on button, 'click', Menu.toggle $.on button, 'click', Menu.toggle
makeButton: do -> makeButton: ->
a = null el = a.cloneNode true
-> $.on el, 'click', Menu.toggle
a or= $.el 'a', el
className: 'menu-button brackets-wrap'
innerHTML: '<span class=drop-marker></span>'
href: 'javascript:;'
a.cloneNode true
toggle: (e) -> toggle: (e) ->
Menu.menu.toggle e, @, Get.postFromNode @ Menu.menu.toggle e, @, Get.postFromNode @

View File

@ -33,7 +33,7 @@ QuoteYou =
cb: cb:
seek: (type) -> seek: (type) ->
return unlses Conf['Mark Quotes of You'] and Conf['Quick Reply'] return unless Conf['Mark Quotes of You']
$.rmClass $('.highlight'), 'highlight' $.rmClass $('.highlight'), 'highlight'
unless QuoteYou.lastRead unless QuoteYou.lastRead