From 0eb224e07726c15d86c046540adfe85bd233f5f2 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sat, 2 Nov 2013 18:37:40 +0100 Subject: [PATCH] Simpler summary creation, tiny Build.thread() optimization. --- css/style.css | 3 +++ src/General/Build.coffee | 29 +++++++++++++++------------ src/General/Index.coffee | 1 - src/Miscellaneous/ExpandThread.coffee | 14 ++++++------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/css/style.css b/css/style.css index 751f3b772..4bebe551d 100644 --- a/css/style.css +++ b/css/style.css @@ -367,6 +367,9 @@ a[href="javascript:;"] { :root.index-loading .pagelist { display: none; } +.summary { + text-decoration: none; +} /* Announcement Hiding */ :root.hide-announcement #globalMessage, diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 03cfaa9b1..5c75dff8e 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -259,28 +259,31 @@ Build = container + summary: (boardID, threadID, posts, files) -> + text = [] + text.push "#{posts} post#{if posts > 1 then 's' else ''}" + text.push "and #{files} image repl#{if files > 1 then 'ies' else 'y'}" if files + text.push 'omitted.' + $.el 'a', + className: 'summary' + textContent: text.join ' ' + href: "/#{boardID}/res/#{threadID}" thread: (board, data) -> - root = $.el 'div', - className: 'thread' - id: "t#{data.no}" - Build.spoilerRange[board] = data.custom_spoiler + nodes = [] for obj in [data].concat data.last_replies or [] - $.add root, if post = g.posts["#{board}.#{obj.no}"] + nodes.push if post = board.posts[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 ' ' + 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 root diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 4b22276ae..5b331337a 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -158,7 +158,6 @@ Index = try 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.' diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index fb3a24699..d9efaa2b0 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -10,13 +10,9 @@ ExpandThread = ExpandThread.setButton @ setButton: (thread) -> - return unless span = $.x 'following-sibling::span[contains(@class,"summary")][1]', thread.OP.nodes.root - a = $.el 'a', - textContent: ExpandThread.text '+', span.textContent.match(/\d+/g)... - className: 'summary' - href: 'javascript:;' + return unless a = $.x 'following-sibling::a[contains(@class,"summary")][1]', thread.OP.nodes.root + a.textContent = ExpandThread.text '+', a.textContent.match(/\d+/g)... $.on a, 'click', ExpandThread.cbToggle - $.replace span, a onIndexRefresh: -> for threadID, status of ExpandThread.statuses @@ -33,7 +29,9 @@ ExpandThread = text.push if status is '-' then 'shown' else 'omitted' text.join(' ') + '.' - cbToggle: -> + cbToggle: (e) -> + return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 + e.preventDefault() ExpandThread.toggle Get.threadFromNode @ toggle: (thread) -> @@ -92,7 +90,7 @@ ExpandThread = root = Build.postFromObject postData, thread.board.ID post = new Post root, thread, thread.board filesCount++ if 'file' of post - posts.push post + posts.push post postsRoot.push root Main.callbackNodes Post, posts $.after a, postsRoot