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