Avoid creating new thread root+<hr> when they already exist.

This commit is contained in:
Mayhem 2013-11-03 17:14:01 +01:00
parent aeea95564c
commit bc0f5fcc3b
3 changed files with 16 additions and 11 deletions

View File

@ -16,10 +16,8 @@ ThreadHiding =
$.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide' $.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide'
onrefresh: -> onrefresh: ->
for threadID, thread of g.BOARD.threads when thread.isHidden for threadID, thread of g.BOARD.threads when thread.isHidden and thread.stub
hasStub = !!thread.stub $.prepend thread.OP.nodes.root.parentNode, thread.stub
ThreadHiding.show thread
ThreadHiding.hide thread, hasStub
return return
syncCatalog: -> syncCatalog: ->

View File

@ -271,6 +271,16 @@ Build =
thread: (board, data) -> thread: (board, data) ->
Build.spoilerRange[board] = data.custom_spoiler Build.spoilerRange[board] = data.custom_spoiler
if (OP = board.posts[data.no]) and parent = OP.nodes.root.parentNode
root = parent
hr = parent.nextElementSibling
$.rmAll root
else
root = $.el 'div',
className: 'thread'
id: "t#{data.no}"
hr = $.el 'hr'
nodes = [] nodes = []
for obj in [data].concat data.last_replies or [] for obj in [data].concat data.last_replies or []
nodes.push if post = board.posts[obj.no] nodes.push if post = board.posts[obj.no]
@ -282,8 +292,5 @@ Build =
if data.omitted_posts if data.omitted_posts
nodes.splice 1, 0, Build.summary board.ID, data.no, data.omitted_posts, data.omitted_images nodes.splice 1, 0, Build.summary board.ID, data.no, data.omitted_posts, data.omitted_images
root = $.el 'div',
className: 'thread'
id: "t#{data.no}"
$.add root, nodes $.add root, nodes
root [root, hr]

View File

@ -188,8 +188,8 @@ Index =
threads = [] threads = []
posts = [] posts = []
for threadData in Index.liveThreadData for threadData in Index.liveThreadData
threadRoot = Build.thread g.BOARD, threadData [threadRoot, hr] = Build.thread g.BOARD, threadData
Index.nodes.push threadRoot, $.el 'hr' Index.nodes.push threadRoot, hr
if thread = g.BOARD.threads[threadData.no] if thread = g.BOARD.threads[threadData.no]
thread.setStatus 'Sticky', !!threadData.sticky thread.setStatus 'Sticky', !!threadData.sticky
thread.setStatus 'Closed', !!threadData.closed thread.setStatus 'Closed', !!threadData.closed
@ -250,6 +250,6 @@ Index =
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)] nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
else else
nodes = Index.sortedNodes nodes = Index.sortedNodes
$.event 'IndexRefresh'
$.rmAll Index.root $.rmAll Index.root
$.event 'IndexRefresh'
$.add Index.root, nodes $.add Index.root, nodes