From 3590fa15f35d6c9b15047508c761d308aa1a55aa Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 2 Apr 2016 20:27:20 -0700 Subject: [PATCH] Consolidate summary text building code. --- src/General/Build.coffee | 13 ++++++++----- src/Miscellaneous/ExpandThread.coffee | 15 +++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index de8358661..83c96fd10 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -150,14 +150,17 @@ Build = container + summaryText: (status, posts, files) -> + text = '' + text += "#{status} " if status + text += "#{posts} post#{if posts > 1 then 's' else ''}" + text += " and #{files} image repl#{if files > 1 then 'ies' else 'y'}" if +files + text += " #{if status is '-' then 'shown' else 'omitted'}." + 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 ' ' + textContent: Build.summaryText '', posts, files href: "/#{boardID}/thread/#{threadID}" thread: (board, data, full) -> diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index d36ff6e41..623ac5c83 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -11,7 +11,7 @@ ExpandThread = setButton: (thread) -> return unless a = $.x 'following-sibling::*[contains(@class,"summary")][1]', thread.OP.nodes.root - a.textContent = ExpandThread.text '+', a.textContent.match(/\d+/g)... + a.textContent = Build.summaryText '+', a.textContent.match(/\d+/g)... a.style.cursor = 'pointer' $.on a, 'click', ExpandThread.cbToggle @@ -28,11 +28,6 @@ ExpandThread = g.BOARD.threads.forEach (thread) -> ExpandThread.setButton thread - text: (status, posts, files) -> - "#{status} #{posts} post#{if posts > 1 then 's' else ''}" + - (if +files then " and #{files} image repl#{if files > 1 then 'ies' else 'y'}" else "") + - " #{if status is '-' then 'shown' else 'omitted'}." - cbToggle: (e) -> return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 e.preventDefault() @@ -48,7 +43,7 @@ ExpandThread = expand: (thread, a) -> ExpandThread.statuses[thread] = status = {} - a.textContent = ExpandThread.text '...', a.textContent.match(/\d+/g)... + a.textContent = Build.summaryText '...', a.textContent.match(/\d+/g)... status.req = $.cache "//a.4cdn.org/#{thread.board}/thread/#{thread}.json", -> delete status.req ExpandThread.parse @, thread, a @@ -58,7 +53,7 @@ ExpandThread = delete ExpandThread.statuses[thread] if status.req status.req.abort() - a.textContent = ExpandThread.text '+', a.textContent.match(/\d+/g)... if a + a.textContent = Build.summaryText '+', a.textContent.match(/\d+/g)... if a return replies = $$ '.thread > .replyContainer', threadRoot @@ -79,7 +74,7 @@ ExpandThread = postsCount++ filesCount++ if 'file' of Get.postFromRoot reply $.rm reply - a.textContent = ExpandThread.text '+', postsCount, filesCount + a.textContent = Build.summaryText '+', postsCount, filesCount parse: (req, thread, a) -> if req.status not in [200, 304] @@ -107,4 +102,4 @@ ExpandThread = $.event 'PostsInserted' postsCount = postsRoot.length - a.textContent = ExpandThread.text '-', postsCount, filesCount + a.textContent = Build.summaryText '-', postsCount, filesCount