Refactor page number code; fix off-by-one error and page number on archived threads
This commit is contained in:
parent
724fc03ad5
commit
04fa72aed9
@ -151,12 +151,6 @@ Build =
|
||||
else
|
||||
"/#{boardID}/thread/#{threadID}\#q#{postID}"
|
||||
|
||||
pageIcon = if isOP and g.VIEW is 'index' and Conf['JSON Navigation']
|
||||
pageNum = Math.floor(Index.liveThreadIDs.indexOf(postID) / Index.threadsNumPerPage) + 1
|
||||
<%= html(' <span class="page-num" title="This thread is on page ${pageNum} in the original index.">[${pageNum}]</span>') %>
|
||||
else
|
||||
<%= html('') %>
|
||||
|
||||
sticky = if isSticky
|
||||
<%= html(' <img src="//s.4cdn.org/image/sticky${retina}.gif" alt="Sticky" title="Sticky" class="stickyIcon retina">') %>
|
||||
else
|
||||
@ -181,7 +175,7 @@ Build =
|
||||
'<span class="postNum${desktop2}">' +
|
||||
'<a href="${postLink}" title="Link to this post">No.</a>' +
|
||||
'<a href="${quoteLink}" title="Reply to this post">${postID}</a>' +
|
||||
'&{pageIcon}&{sticky}&{closed}&{replyLink}' +
|
||||
'&{sticky}&{closed}&{replyLink}' +
|
||||
'</span>' +
|
||||
'</div>'
|
||||
) %>
|
||||
|
||||
@ -317,7 +317,6 @@ Index =
|
||||
try
|
||||
threadRoot = Build.thread g.BOARD, threadData
|
||||
if thread = g.BOARD.threads[threadData.no]
|
||||
thread.setPage Math.floor i / Index.threadsNumPerPage
|
||||
thread.setStatus 'Sticky', !!threadData.sticky
|
||||
thread.setStatus 'Closed', !!threadData.closed
|
||||
else
|
||||
@ -326,6 +325,7 @@ Index =
|
||||
Index.nodes.push threadRoot
|
||||
continue if thread.ID of thread.posts
|
||||
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD
|
||||
thread.setPage i // Index.threadsNumPerPage + 1
|
||||
catch err
|
||||
# Skip posts that we failed to parse.
|
||||
errors = [] unless errors
|
||||
|
||||
@ -13,10 +13,12 @@ class Thread
|
||||
g.threads.push @fullID, board.threads.push @, @
|
||||
|
||||
setPage: (pageNum) ->
|
||||
icon = $ '.page-num', @OP.nodes.post
|
||||
for key in ['title', 'textContent']
|
||||
icon[key] = icon[key].replace /\d+/, pageNum
|
||||
return
|
||||
{info} = @OP.nodes
|
||||
unless icon = $ '.page-num', info
|
||||
icon = $.el 'span', className: 'page-num'
|
||||
$.after $('a[title="Reply to this post"]', info), [$.tn(' '), icon]
|
||||
icon.title = "This thread is on page #{pageNum} in the original index."
|
||||
icon.textContent = "[#{pageNum}]"
|
||||
setStatus: (type, status) ->
|
||||
name = "is#{type}"
|
||||
return if @[name] is status
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user