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
|
else
|
||||||
"/#{boardID}/thread/#{threadID}\#q#{postID}"
|
"/#{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
|
sticky = if isSticky
|
||||||
<%= html(' <img src="//s.4cdn.org/image/sticky${retina}.gif" alt="Sticky" title="Sticky" class="stickyIcon retina">') %>
|
<%= html(' <img src="//s.4cdn.org/image/sticky${retina}.gif" alt="Sticky" title="Sticky" class="stickyIcon retina">') %>
|
||||||
else
|
else
|
||||||
@ -181,7 +175,7 @@ Build =
|
|||||||
'<span class="postNum${desktop2}">' +
|
'<span class="postNum${desktop2}">' +
|
||||||
'<a href="${postLink}" title="Link to this post">No.</a>' +
|
'<a href="${postLink}" title="Link to this post">No.</a>' +
|
||||||
'<a href="${quoteLink}" title="Reply to this post">${postID}</a>' +
|
'<a href="${quoteLink}" title="Reply to this post">${postID}</a>' +
|
||||||
'&{pageIcon}&{sticky}&{closed}&{replyLink}' +
|
'&{sticky}&{closed}&{replyLink}' +
|
||||||
'</span>' +
|
'</span>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
) %>
|
) %>
|
||||||
|
|||||||
@ -317,7 +317,6 @@ Index =
|
|||||||
try
|
try
|
||||||
threadRoot = Build.thread g.BOARD, threadData
|
threadRoot = Build.thread g.BOARD, threadData
|
||||||
if thread = g.BOARD.threads[threadData.no]
|
if thread = g.BOARD.threads[threadData.no]
|
||||||
thread.setPage Math.floor i / Index.threadsNumPerPage
|
|
||||||
thread.setStatus 'Sticky', !!threadData.sticky
|
thread.setStatus 'Sticky', !!threadData.sticky
|
||||||
thread.setStatus 'Closed', !!threadData.closed
|
thread.setStatus 'Closed', !!threadData.closed
|
||||||
else
|
else
|
||||||
@ -326,6 +325,7 @@ Index =
|
|||||||
Index.nodes.push threadRoot
|
Index.nodes.push threadRoot
|
||||||
continue if thread.ID of thread.posts
|
continue if thread.ID of thread.posts
|
||||||
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD
|
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD
|
||||||
|
thread.setPage i // Index.threadsNumPerPage + 1
|
||||||
catch err
|
catch err
|
||||||
# Skip posts that we failed to parse.
|
# Skip posts that we failed to parse.
|
||||||
errors = [] unless errors
|
errors = [] unless errors
|
||||||
|
|||||||
@ -13,10 +13,12 @@ class Thread
|
|||||||
g.threads.push @fullID, board.threads.push @, @
|
g.threads.push @fullID, board.threads.push @, @
|
||||||
|
|
||||||
setPage: (pageNum) ->
|
setPage: (pageNum) ->
|
||||||
icon = $ '.page-num', @OP.nodes.post
|
{info} = @OP.nodes
|
||||||
for key in ['title', 'textContent']
|
unless icon = $ '.page-num', info
|
||||||
icon[key] = icon[key].replace /\d+/, pageNum
|
icon = $.el 'span', className: 'page-num'
|
||||||
return
|
$.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) ->
|
setStatus: (type, status) ->
|
||||||
name = "is#{type}"
|
name = "is#{type}"
|
||||||
return if @[name] is status
|
return if @[name] is status
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user