diff --git a/CHANGELOG.md b/CHANGELOG.md index bd43be2d1..7f9c77613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +Index navigation improvements: + - You can now refresh the index page you are on with the same keybind for refreshing threads. Added a keybind to open the catalog search field on index pages. ### 3.11.5 - *2013-10-03* diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 783a774f5..b229c71a7 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -248,3 +248,27 @@ Build = quote.href = "/#{boardID}/res/#{href}" # Fix pathnames container + + thread: (board, data) -> + root = $.el 'div', + className: 'thread' + id: "t#{data.no}" + + for obj in [data].concat data.last_replies or [] + $.add root, if post = g.posts["#{board}.#{obj.no}"] + post.nodes.root + else + Build.postFromObject obj, board.ID + + # build if necessary + if data.omitted_posts + {omitted_posts, omitted_images} = data + html = [] + html.push "#{omitted_posts} post#{if omitted_posts > 1 then 's' else ''}" + html.push "and #{omitted_images} image repl#{if omitted_images > 1 then 'ies' else 'y'}" if omitted_images + html.push "omitted. Click here to view." + $.after root.firstChild, $.el 'span', + className: 'summary' + innerHTML: html.join ' ' + + root diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 2829eb208..604393db8 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -185,7 +185,7 @@ Main = unless errors errors = [] errors.push - message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped." + message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped." error: err Main.handleErrors errors if errors diff --git a/src/Miscellaneous/Index.coffee b/src/Miscellaneous/Index.coffee index 06aa5b329..a277d76fd 100644 --- a/src/Miscellaneous/Index.coffee +++ b/src/Miscellaneous/Index.coffee @@ -3,7 +3,7 @@ Index = return if g.VIEW isnt 'index' update: -> - # return unless navigator.onLine + return unless navigator.onLine Index.req?.abort() Index.notice?.close() Index.notice = new Notice 'info', 'Refreshing index...' @@ -23,8 +23,9 @@ Index = return try - Index.parse JSON.parse req.response - catch e + Index.parse JSON.parse req.response if req.status is 200 + catch err + c.error err.stack # network error or non-JSON content for example. notice.setType 'error' notice.el.lastElementChild.textContent = 'Index refresh failed.' @@ -38,4 +39,33 @@ Index = Header.scrollTo $.id 'delform' parse: (pages) -> pageNum = +window.location.pathname.split('/')[2] - threads = pages[pageNum].threads + dataThr = pages[pageNum].threads + + nodes = [] + threads = [] + posts = [] + 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 + threads.push thread + for postRoot in $$ '.thread > .postContainer', threadRoot + continue if thread.posts[postRoot.id.match /\d+/] + try + posts.push new Post postRoot, thread, g.BOARD + catch err + # Skip posts that we failed to parse. + unless errors + errors = [] + errors.push + message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped." + error: err + Main.handleErrors errors if errors + + Main.callbackNodes Thread, threads + Main.callbackNodes Post, posts + + board = $ '.board' + $.rmAll board + $.add board, nodes