diff --git a/src/General/Main.coffee b/src/General/Main.coffee index a504f76ef..885b09231 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -170,7 +170,7 @@ Main = # Something might have gone wrong! Main.initStyle() - if board = $ '.board' + if g.VIEW is 'thread' and board = $ '.board' threads = [] posts = [] diff --git a/src/Miscellaneous/Index.coffee b/src/Miscellaneous/Index.coffee index 51aadffc3..51050bce2 100644 --- a/src/Miscellaneous/Index.coffee +++ b/src/Miscellaneous/Index.coffee @@ -19,7 +19,7 @@ Index = input = label.el.firstChild input.checked = Conf['Index Mode'] is input.value $.on input, 'change', $.cb.value - $.on input, 'change', @update + $.on input, 'change', @cb.mode sortEntry = el: $.el 'span', textContent: 'Sort by' @@ -31,7 +31,7 @@ Index = input = label.el.firstChild input.checked = Conf['Index Sort'] is input.value $.on input, 'change', $.cb.value - $.on input, 'change', @resort + $.on input, 'change', @cb.sort $.event 'AddMenuEntry', type: 'header' @@ -45,11 +45,15 @@ Index = initReady: -> $.off d, '4chanXInitFinished', Index.initReady Index.root = $ '.board' - Index.liveThreads = $$('.board > .thread', Index.root).map Get.threadFromRoot - Index.resort() - return if Conf['Index Mode'] is 'paged' Index.update() + cb: + mode: -> + Index.buildIndex() + sort: -> + Index.sort() + Index.buildIndex() + update: -> return unless navigator.onLine Index.req?.abort() @@ -86,27 +90,29 @@ Index = Header.scrollTo Index.root if Index.root.getBoundingClientRect().top < 0 parse: (pages) -> - if Conf['Index Mode'] is 'paged' - pageNum = +window.location.pathname.split('/')[2] - dataThr = pages[pageNum].threads - else - dataThr = [] - for page in pages - dataThr.push page.threads... - - nodes = [] - threads = [] - posts = [] - Index.liveThreads = [] - for data in dataThr - threadRoot = Build.thread g.BOARD, data - nodes.push threadRoot, $.el 'hr' - unless thread = g.threads["#{g.BOARD}.#{data.no}"] - thread = new Thread data.no, g.BOARD + Index.parseThreadList pages + Index.buildAll() + Index.sort() + Index.buildIndex() + parseThreadList: (pages) -> + Index.threadsNumPerPage = pages[0].threads.length + Index.liveThreadData = pages.reduce ((arr, next) -> arr.concat next.threads), [] + Index.liveThreadIDs = Index.liveThreadData.map (data) -> data.no + for threadID, thread of g.BOARD.threads when thread.ID not in Index.liveThreadIDs + thread.collect() + return + buildAll: -> + Index.nodes = [] + threads = [] + posts = [] + for threadData in Index.liveThreadData + threadRoot = Build.thread g.BOARD, threadData + Index.nodes.push threadRoot, $.el 'hr' + unless thread = g.BOARD.threads[threadData.no] + thread = new Thread threadData.no, g.BOARD threads.push thread - Index.liveThreads.push thread - for postRoot in $$ '.thread > .postContainer', threadRoot - continue if thread.posts[postRoot.id.match /\d+/] + postRoots = $$ '.thread > .postContainer', threadRoot + for postRoot in postRoots when postRoot.id.match(/\d+/)[0] not of thread.posts try posts.push new Post postRoot, thread, g.BOARD catch err @@ -118,44 +124,35 @@ Index = error: err Main.handleErrors errors if errors - Index.collectDeadThreads() # Add the threads and