Simplify reverse sort code.
This commit is contained in:
parent
77e01a7095
commit
cd51c53e40
@ -107,12 +107,8 @@ Index =
|
|||||||
$.on @selectSize, 'change', @cb.size
|
$.on @selectSize, 'change', @cb.size
|
||||||
for select in [@selectMode, @selectSize]
|
for select in [@selectMode, @selectSize]
|
||||||
select.value = Conf[select.name]
|
select.value = Conf[select.name]
|
||||||
@selectSort.value = do ->
|
@selectRev.checked = /-rev$/.test Index.currentSort
|
||||||
if Index.currentSort.slice(-4) is '-rev'
|
@selectSort.value = Index.currentSort.replace /-rev$/, ''
|
||||||
Index.selectRev.checked = true
|
|
||||||
return Index.currentSort.slice(0,-4)
|
|
||||||
else
|
|
||||||
return Index.currentSort
|
|
||||||
|
|
||||||
# Thread container
|
# Thread container
|
||||||
@root = $.el 'div', className: 'board json-index'
|
@root = $.el 'div', className: 'board json-index'
|
||||||
@ -370,10 +366,9 @@ Index =
|
|||||||
else if command is 'index'
|
else if command is 'index'
|
||||||
state.mode = Conf['Previous Index Mode']
|
state.mode = Conf['Previous Index Mode']
|
||||||
state.page = 1
|
state.page = 1
|
||||||
else if (sort = Index.hashCommands.sort[command])
|
else if (sort = Index.hashCommands.sort[command.replace(/-rev$/, '')])
|
||||||
state.sort = sort
|
state.sort = sort
|
||||||
else if command.slice(-4) is '-rev' and (sort = Index.hashCommands.sort[command.slice(0,-4)])
|
state.sort += '-rev' if /-rev$/.test(command)
|
||||||
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
|
||||||
@ -456,13 +451,8 @@ Index =
|
|||||||
$('#hidden-toggle a', Index.navLinks).textContent = 'Show'
|
$('#hidden-toggle a', Index.navLinks).textContent = 'Show'
|
||||||
|
|
||||||
setupSort: ->
|
setupSort: ->
|
||||||
Index.selectRev.checked = Index.currentSort.slice(-4) is '-rev'
|
Index.selectRev.checked = /-rev$/.test Index.currentSort
|
||||||
Index.selectSort.value = do ->
|
Index.selectSort.value = Index.currentSort.replace /-rev$/, ''
|
||||||
if Index.currentSort.slice(-4) is '-rev'
|
|
||||||
Index.selectRev.checked = true
|
|
||||||
return Index.currentSort.slice(0,-4)
|
|
||||||
else
|
|
||||||
return Index.currentSort
|
|
||||||
|
|
||||||
getPagesNum: ->
|
getPagesNum: ->
|
||||||
if Index.search
|
if Index.search
|
||||||
@ -760,12 +750,7 @@ Index =
|
|||||||
sort: ->
|
sort: ->
|
||||||
{liveThreadIDs, liveThreadData} = Index
|
{liveThreadIDs, liveThreadData} = Index
|
||||||
return unless liveThreadData
|
return unless liveThreadData
|
||||||
if Index.currentSort.slice(-4) is '-rev'
|
Index.sortedThreadIDs = switch Index.currentSort.replace(/-rev$/, '')
|
||||||
currentSort = Index.currentSort.slice(0,-4)
|
|
||||||
reverse = true
|
|
||||||
else
|
|
||||||
currentSort = Index.currentSort
|
|
||||||
sorted = switch currentSort
|
|
||||||
when 'lastreply'
|
when 'lastreply'
|
||||||
[liveThreadData...].sort((a, b) ->
|
[liveThreadData...].sort((a, b) ->
|
||||||
a = num[num.length - 1] if (num = a.last_replies)
|
a = num[num.length - 1] if (num = a.last_replies)
|
||||||
@ -784,7 +769,8 @@ 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
|
||||||
Index.sortedThreadIDs = if reverse then [sorted...].reverse() else sorted
|
if /-rev$/.test(Index.currentSort)
|
||||||
|
Index.sortedThreadIDs = [Index.sortedThreadIDs...].reverse()
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user