ExpandThread tweaking.
Also fix code trying to $.off `ExpandThread.cb.toggle`.
This commit is contained in:
parent
b36cf54d83
commit
63cd0aa164
@ -6,7 +6,7 @@ ExpandThread =
|
||||
name: 'Thread Expansion'
|
||||
cb: @node
|
||||
node: ->
|
||||
return unless span = $ '.summary', @OP.nodes.root.parentNode
|
||||
return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', @OP.nodes.root
|
||||
a = $.el 'a',
|
||||
textContent: "+ #{span.textContent}"
|
||||
className: 'summary'
|
||||
@ -15,8 +15,7 @@ ExpandThread =
|
||||
$.replace span, a
|
||||
|
||||
cbToggle: ->
|
||||
op = Get.postFromRoot @previousElementSibling
|
||||
ExpandThread.toggle op.thread
|
||||
ExpandThread.toggle Get.threadFromRoot @parentNode
|
||||
|
||||
toggle: (thread) ->
|
||||
threadRoot = thread.OP.nodes.root.parentNode
|
||||
@ -24,7 +23,6 @@ ExpandThread =
|
||||
|
||||
switch thread.isExpanded
|
||||
when false, undefined
|
||||
thread.isExpanded = 'loading'
|
||||
for post in $$ '.thread > .postContainer', threadRoot
|
||||
ExpandComment.expand Get.postFromRoot post
|
||||
unless a
|
||||
@ -42,60 +40,58 @@ ExpandThread =
|
||||
|
||||
when true
|
||||
thread.isExpanded = false
|
||||
if a
|
||||
a.textContent = a.textContent.replace '-', '+'
|
||||
#goddamit moot
|
||||
num = if thread.isSticky
|
||||
1
|
||||
else switch g.BOARD.ID
|
||||
# XXX boards config
|
||||
when 'b', 'vg', 'q' then 3
|
||||
when 't' then 1
|
||||
else 5
|
||||
replies = $$('.thread > .replyContainer', threadRoot)[...-num]
|
||||
for reply in replies
|
||||
if Conf['Quote Inlining']
|
||||
# rm clones
|
||||
inlined.click() while inlined = $ '.inlined', reply
|
||||
$.rm reply
|
||||
for post in $$ '.thread > .postContainer', threadRoot
|
||||
#goddamit moot
|
||||
num = if thread.isSticky
|
||||
1
|
||||
else switch g.BOARD.ID
|
||||
# XXX boards config
|
||||
when 'b', 'vg', 'q' then 3
|
||||
when 't' then 1
|
||||
else 5
|
||||
posts = $$ ".thread > .replyContainer", threadRoot
|
||||
for post in [thread.OP.nodes.root].concat posts[-num..]
|
||||
ExpandComment.contract Get.postFromRoot post
|
||||
return unless a
|
||||
a.textContent = a.textContent.replace '-', '+'
|
||||
for reply in posts[...-num]
|
||||
if Conf['Quote Inlining']
|
||||
# rm clones
|
||||
inlined.click() while inlined = $ '.inlined', reply
|
||||
$.rm reply
|
||||
return
|
||||
|
||||
parse: (req, thread, a) ->
|
||||
return if a.textContent[0] is '+'
|
||||
{status} = req
|
||||
if status not in [200, 304]
|
||||
a.textContent = "Error #{req.statusText} (#{status})"
|
||||
$.off a, 'click', ExpandThread.cb.toggle
|
||||
if req.status not in [200, 304]
|
||||
a.textContent = "Error #{req.statusText} (#{req.status})"
|
||||
$.off a, 'click', ExpandThread.cbToggle
|
||||
return
|
||||
|
||||
thread.isExpanded = true
|
||||
a.textContent = a.textContent.replace '× Loading...', '-'
|
||||
|
||||
posts = JSON.parse(req.response).posts
|
||||
if spoilerRange = posts[0].custom_spoiler
|
||||
Build.spoilerRange[g.BOARD] = spoilerRange
|
||||
{posts} = JSON.parse req.response
|
||||
if spoilerRange = posts.shift().custom_spoiler
|
||||
Build.spoilerRange[thread.board] = spoilerRange
|
||||
|
||||
replies = posts[1..]
|
||||
posts = []
|
||||
nodes = []
|
||||
for reply in replies
|
||||
if post = thread.posts[reply.no]
|
||||
nodes.push post.nodes.root
|
||||
postsObj = []
|
||||
postsRoot = []
|
||||
for post in posts
|
||||
if post = thread.posts[post.no]
|
||||
postsRoot.push post.nodes.root
|
||||
continue
|
||||
node = Build.postFromObject reply, thread.board.ID
|
||||
post = new Post node, thread, thread.board
|
||||
link = $ 'a[title="Highlight this post"]', node
|
||||
root = Build.postFromObject post, thread.board.ID
|
||||
post = new Post root, thread, thread.board
|
||||
link = $ 'a[title="Highlight this post"]', root
|
||||
link.href = "res/#{thread}#p#{post}"
|
||||
link.nextSibling.href = "res/#{thread}#q#{post}"
|
||||
posts.push post
|
||||
nodes.push node
|
||||
Main.callbackNodes Post, posts
|
||||
$.after a, nodes
|
||||
postsObj.push post
|
||||
postsRoot.push root
|
||||
Main.callbackNodes Post, postsObj
|
||||
$.after a, postsRoot
|
||||
|
||||
# Enable 4chan features.
|
||||
if Conf['Enable 4chan\'s Extension']
|
||||
$.globalEval "Parser.parseThread(#{thread.ID}, 1, #{nodes.length})"
|
||||
$.globalEval "Parser.parseThread(#{thread.ID}, 1, #{postsRoot.length})"
|
||||
else
|
||||
Fourchan.parseThread thread.ID, 1, nodes.length
|
||||
Fourchan.parseThread thread.ID, 1, postsRoot.length
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user