Add box to reverse index, appends -rev if checked

When box element is toggled, invoke a revised
sort option that appends "-rev" to the sort
dropdown value when box is checked. If this value
changes while box is checked, the new sort is
still reversed.

If "-rev" is already given by previously saved
sort or custom board navigation option, pick the
correct dropdown value and check box
automatically.

Wrap previous sorting implementation, determining
if "-rev" is tacked on and doing the reverse work
at the end.
This commit is contained in:
Koushien 2016-10-28 22:52:43 -07:00
parent a1d2408dad
commit 1c7e85ea7b

View File

@ -95,17 +95,24 @@ Index =
@hideLabel = $ '#hidden-label', @navLinks @hideLabel = $ '#hidden-label', @navLinks
$.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads $.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads
# Drop-down menus # Drop-down menus and reverse sort toggle
@selectRev = $ '#index-rev', @navLinks
@selectMode = $ '#index-mode', @navLinks @selectMode = $ '#index-mode', @navLinks
@selectSort = $ '#index-sort', @navLinks @selectSort = $ '#index-sort', @navLinks
@selectSize = $ '#index-size', @navLinks @selectSize = $ '#index-size', @navLinks
$.on @selectRev, 'change', @cb.sort
$.on @selectMode, 'change', @cb.mode $.on @selectMode, 'change', @cb.mode
$.on @selectSort, 'change', @cb.sort $.on @selectSort, 'change', @cb.sort
$.on @selectSize, 'change', $.cb.value $.on @selectSize, 'change', $.cb.value
$.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 = Index.currentSort @selectSort.value = do ->
if Index.currentSort.slice(-4) is '-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'
@ -252,7 +259,8 @@ Index =
Index.pageLoad false Index.pageLoad false
sort: -> sort: ->
Index.pushState {sort: @value} value = if Index.selectRev.checked then Index.selectSort.value + "-rev" else Index.selectSort.value
Index.pushState {sort: value}
Index.pageLoad false Index.pageLoad false
resort: (e) -> resort: (e) ->
@ -452,7 +460,13 @@ Index =
$('#hidden-toggle a', Index.navLinks).textContent = 'Show' $('#hidden-toggle a', Index.navLinks).textContent = 'Show'
setupSort: -> setupSort: ->
Index.selectSort.value = Index.currentSort Index.selectRev.checked = false
Index.selectSort.value = do ->
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
@ -750,7 +764,13 @@ Index =
sort: -> sort: ->
{liveThreadIDs, liveThreadData} = Index {liveThreadIDs, liveThreadData} = Index
return unless liveThreadData return unless liveThreadData
Index.sortedThreadIDs = switch Index.currentSort Index.sortedThreadIDs = do ->
if Index.currentSort.slice(-4) == "-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)
@ -769,6 +789,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
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