Consolidate summary text building code.
This commit is contained in:
parent
22ffcd7228
commit
3590fa15f3
@ -150,14 +150,17 @@ Build =
|
|||||||
|
|
||||||
container
|
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) ->
|
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',
|
$.el 'a',
|
||||||
className: 'summary'
|
className: 'summary'
|
||||||
textContent: text.join ' '
|
textContent: Build.summaryText '', posts, files
|
||||||
href: "/#{boardID}/thread/#{threadID}"
|
href: "/#{boardID}/thread/#{threadID}"
|
||||||
|
|
||||||
thread: (board, data, full) ->
|
thread: (board, data, full) ->
|
||||||
|
|||||||
@ -11,7 +11,7 @@ ExpandThread =
|
|||||||
|
|
||||||
setButton: (thread) ->
|
setButton: (thread) ->
|
||||||
return unless a = $.x 'following-sibling::*[contains(@class,"summary")][1]', thread.OP.nodes.root
|
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'
|
a.style.cursor = 'pointer'
|
||||||
$.on a, 'click', ExpandThread.cbToggle
|
$.on a, 'click', ExpandThread.cbToggle
|
||||||
|
|
||||||
@ -28,11 +28,6 @@ ExpandThread =
|
|||||||
g.BOARD.threads.forEach (thread) ->
|
g.BOARD.threads.forEach (thread) ->
|
||||||
ExpandThread.setButton 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) ->
|
cbToggle: (e) ->
|
||||||
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
|
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -48,7 +43,7 @@ ExpandThread =
|
|||||||
|
|
||||||
expand: (thread, a) ->
|
expand: (thread, a) ->
|
||||||
ExpandThread.statuses[thread] = status = {}
|
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", ->
|
status.req = $.cache "//a.4cdn.org/#{thread.board}/thread/#{thread}.json", ->
|
||||||
delete status.req
|
delete status.req
|
||||||
ExpandThread.parse @, thread, a
|
ExpandThread.parse @, thread, a
|
||||||
@ -58,7 +53,7 @@ ExpandThread =
|
|||||||
delete ExpandThread.statuses[thread]
|
delete ExpandThread.statuses[thread]
|
||||||
if status.req
|
if status.req
|
||||||
status.req.abort()
|
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
|
return
|
||||||
|
|
||||||
replies = $$ '.thread > .replyContainer', threadRoot
|
replies = $$ '.thread > .replyContainer', threadRoot
|
||||||
@ -79,7 +74,7 @@ ExpandThread =
|
|||||||
postsCount++
|
postsCount++
|
||||||
filesCount++ if 'file' of Get.postFromRoot reply
|
filesCount++ if 'file' of Get.postFromRoot reply
|
||||||
$.rm reply
|
$.rm reply
|
||||||
a.textContent = ExpandThread.text '+', postsCount, filesCount
|
a.textContent = Build.summaryText '+', postsCount, filesCount
|
||||||
|
|
||||||
parse: (req, thread, a) ->
|
parse: (req, thread, a) ->
|
||||||
if req.status not in [200, 304]
|
if req.status not in [200, 304]
|
||||||
@ -107,4 +102,4 @@ ExpandThread =
|
|||||||
$.event 'PostsInserted'
|
$.event 'PostsInserted'
|
||||||
|
|
||||||
postsCount = postsRoot.length
|
postsCount = postsRoot.length
|
||||||
a.textContent = ExpandThread.text '-', postsCount, filesCount
|
a.textContent = Build.summaryText '-', postsCount, filesCount
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user