Index.sortedNodes -> Index.sortedThreads

This commit is contained in:
ccd0 2016-09-16 23:49:31 -07:00
parent f390674ffc
commit cfaa2a86b3

View File

@ -109,7 +109,7 @@ Index =
Index.hat = $ '.board > .thread > img:first-child' Index.hat = $ '.board > .thread > img:first-child'
if Index.hat if Index.hat
if Index.nodes if Index.nodes
for threadRoot in Index.nodes for ID, threadRoot of Index.nodes
$.prepend threadRoot, Index.hat.cloneNode false $.prepend threadRoot, Index.hat.cloneNode false
$.addClass doc, 'hats-enabled' $.addClass doc, 'hats-enabled'
$.addStyle ".catalog-thread::after {background-image: url(#{Index.hat.src});}" $.addStyle ".catalog-thread::after {background-image: url(#{Index.hat.src});}"
@ -413,7 +413,7 @@ Index =
getPagesNum: -> getPagesNum: ->
if Index.search if Index.search
Math.ceil Index.sortedNodes.length / Index.threadsNumPerPage Math.ceil Index.sortedThreads.length / Index.threadsNumPerPage
else else
Index.pagesNum Index.pagesNum
@ -570,14 +570,14 @@ Index =
buildThreads: -> buildThreads: ->
return unless Index.liveThreadData return unless Index.liveThreadData
Index.nodes = [] Index.nodes = {}
threads = [] threads = []
posts = [] posts = []
for threadData, i in Index.liveThreadData for threadData, i in Index.liveThreadData
try try
threadRoot = Build.thread g.BOARD, threadData threadRoot = Build.thread g.BOARD, threadData
$.prepend threadRoot, Index.hat.cloneNode false if Index.hat $.prepend threadRoot, Index.hat.cloneNode false if Index.hat
if thread = g.BOARD.threads[threadData.no] if (thread = g.BOARD.threads[threadData.no])
thread.setCount 'post', threadData.replies + 1, threadData.bumplimit thread.setCount 'post', threadData.replies + 1, threadData.bumplimit
thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit
thread.setStatus 'Sticky', !!threadData.sticky thread.setStatus 'Sticky', !!threadData.sticky
@ -585,7 +585,7 @@ Index =
else else
thread = new Thread threadData.no, g.BOARD thread = new Thread threadData.no, g.BOARD
threads.push thread threads.push thread
Index.nodes.push threadRoot Index.nodes[thread.ID] = threadRoot
unless thread.OP and not thread.OP.isFetchedQuote unless thread.OP and not thread.OP.isFetchedQuote
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD
thread.setPage i // Index.threadsNumPerPage + 1 thread.setPage i // Index.threadsNumPerPage + 1
@ -628,9 +628,7 @@ Index =
Main.callbackNodes 'Post', posts Main.callbackNodes 'Post', posts
buildCatalogViews: -> buildCatalogViews: ->
threads = Index.sortedNodes threads = Index.sortedThreads.filter (thread) -> !thread.isHidden isnt Index.showHiddenThreads
.map((threadRoot) -> Get.threadFromRoot threadRoot)
.filter (thread) -> !thread.isHidden isnt Index.showHiddenThreads
catalogThreads = [] catalogThreads = []
for thread in threads when !thread.catalogView for thread in threads when !thread.catalogView
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
@ -671,12 +669,9 @@ Index =
when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a
when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no
when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no
Index.sortedNodes = sortedNodes = [] Index.sortedThreads = sortedThreadIDs.map (threadID) -> g.BOARD.threads[threadID]
{nodes} = Index if Index.search and (threads = Index.querySearch Index.search)
for threadID in sortedThreadIDs Index.sortedThreads = threads
sortedNodes.push nodes[Index.liveThreadIDs.indexOf(threadID)]
if Index.search and nodes = Index.querySearch(Index.search)
Index.sortedNodes = nodes
# Sticky threads # Sticky threads
Index.sortOnTop (thread) -> thread.isSticky Index.sortOnTop (thread) -> thread.isSticky
# Highlighted threads # Highlighted threads
@ -685,24 +680,24 @@ Index =
Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads'] Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads']
sortOnTop: (match) -> sortOnTop: (match) ->
topNodes = [] topThreads = []
bottomNodes = [] bottomThreads = []
for threadRoot in Index.sortedNodes for thread in Index.sortedThreads
(if match Get.threadFromRoot threadRoot then topNodes else bottomNodes).push threadRoot (if match thread then topThreads else bottomThreads).push thread
Index.sortedNodes = topNodes.concat(bottomNodes) Index.sortedThreads = topThreads.concat bottomThreads
buildIndex: -> buildIndex: ->
return unless Index.liveThreadData return unless Index.liveThreadData
switch Conf['Index Mode'] switch Conf['Index Mode']
when 'all pages' when 'all pages'
nodes = Index.sortedNodes nodes = Index.sortedThreads.map (thread) -> Index.nodes[thread.ID]
when 'catalog' when 'catalog'
nodes = Index.buildCatalogViews() nodes = Index.buildCatalogViews()
Index.sizeCatalogViews nodes Index.sizeCatalogViews nodes
else else
if Index.followedThreadID? if Index.followedThreadID?
i = 0 i = 0
i++ while Index.followedThreadID isnt Get.threadFromRoot(Index.sortedNodes[i]).ID i++ while Index.followedThreadID isnt Index.sortedThreads[i].ID
page = i // Index.threadsNumPerPage + 1 page = i // Index.threadsNumPerPage + 1
if page isnt Index.currentPage if page isnt Index.currentPage
Index.currentPage = page Index.currentPage = page
@ -723,7 +718,7 @@ Index =
buildSinglePage: (pageNum) -> buildSinglePage: (pageNum) ->
nodesPerPage = Index.threadsNumPerPage nodesPerPage = Index.threadsNumPerPage
offset = nodesPerPage * (pageNum - 1) offset = nodesPerPage * (pageNum - 1)
Index.sortedNodes.slice offset, offset + nodesPerPage Index.sortedThreads[offset ... offset + nodesPerPage].map (thread) -> Index.nodes[thread.ID]
buildStructure: (nodes) -> buildStructure: (nodes) ->
for node in nodes for node in nodes
@ -758,8 +753,8 @@ Index =
querySearch: (query) -> querySearch: (query) ->
return unless keywords = query.toLowerCase().match /\S+/g return unless keywords = query.toLowerCase().match /\S+/g
Index.sortedNodes.filter (threadRoot) -> Index.sortedThreads.filter (thread) ->
Index.searchMatch Get.threadFromRoot(threadRoot), keywords Index.searchMatch thread, keywords
searchMatch: (thread, keywords) -> searchMatch: (thread, keywords) ->
{info, file} = thread.OP {info, file} = thread.OP