Revise reverse sort implementation details

On setup, immediately check box if '-rev'
appended to current sort.

For custom board navigation, prefer to account for
'-rev' option in processHash().

Bring sorting work outside nested function.
This commit is contained in:
Koushien 2016-10-29 12:00:25 -07:00
parent 1c7e85ea7b
commit 1d0d7f3f2c

View File

@ -351,17 +351,11 @@ Index =
'catalog': 'catalog' 'catalog': 'catalog'
sort: sort:
'bump-order': 'bump' 'bump-order': 'bump'
'bump-order-rev': 'bump-rev'
'last-reply': 'lastreply' 'last-reply': 'lastreply'
'last-reply-rev': 'lastreply-rev'
'last-long-reply': 'lastlong' 'last-long-reply': 'lastlong'
'last-long-reply-rev': 'lastlong-rev'
'creation-date': 'birth' 'creation-date': 'birth'
'creation-date-rev': 'birth-rev'
'reply-count': 'replycount' 'reply-count': 'replycount'
'reply-count-rev': 'replycount-rev'
'file-count': 'filecount' 'file-count': 'filecount'
'file-count-rev': 'filecount-rev'
processHash: -> processHash: ->
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304
@ -378,6 +372,8 @@ Index =
state.page = 1 state.page = 1
else if (sort = Index.hashCommands.sort[command]) else if (sort = Index.hashCommands.sort[command])
state.sort = sort state.sort = sort
else if (sort = Index.hashCommands.sort[command.slice(0,-4)])
state.sort = sort + '-rev'
else if /^s=/.test command else if /^s=/.test command
state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim()
else else
@ -460,7 +456,7 @@ Index =
$('#hidden-toggle a', Index.navLinks).textContent = 'Show' $('#hidden-toggle a', Index.navLinks).textContent = 'Show'
setupSort: -> setupSort: ->
Index.selectRev.checked = false Index.selectRev.checked = Index.currentSort.slice(-4) is '-rev'
Index.selectSort.value = do -> Index.selectSort.value = do ->
if Index.currentSort.slice(-4) is '-rev' if Index.currentSort.slice(-4) is '-rev'
Index.selectRev.checked = true Index.selectRev.checked = true
@ -764,8 +760,7 @@ Index =
sort: -> sort: ->
{liveThreadIDs, liveThreadData} = Index {liveThreadIDs, liveThreadData} = Index
return unless liveThreadData return unless liveThreadData
Index.sortedThreadIDs = do -> if Index.currentSort.slice(-4) is '-rev'
if Index.currentSort.slice(-4) == "-rev"
currentSort = Index.currentSort.slice(0,-4) currentSort = Index.currentSort.slice(0,-4)
reverse = true reverse = true
else else
@ -789,7 +784,7 @@ Index =
when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a
when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no
when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no
return if reverse then [sorted...].reverse() else sorted Index.sortedThreadIDs = if reverse then [sorted...].reverse() else sorted
if Index.search and (threadIDs = Index.querySearch Index.search) if Index.search and (threadIDs = Index.querySearch Index.search)
Index.sortedThreadIDs = threadIDs Index.sortedThreadIDs = threadIDs
# Sticky threads # Sticky threads