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:
parent
a1d2408dad
commit
1c7e85ea7b
@ -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,25 +764,32 @@ Index =
|
|||||||
sort: ->
|
sort: ->
|
||||||
{liveThreadIDs, liveThreadData} = Index
|
{liveThreadIDs, liveThreadData} = Index
|
||||||
return unless liveThreadData
|
return unless liveThreadData
|
||||||
Index.sortedThreadIDs = switch Index.currentSort
|
Index.sortedThreadIDs = do ->
|
||||||
when 'lastreply'
|
if Index.currentSort.slice(-4) == "-rev"
|
||||||
[liveThreadData...].sort((a, b) ->
|
currentSort = Index.currentSort.slice(0,-4)
|
||||||
a = num[num.length - 1] if (num = a.last_replies)
|
reverse = true
|
||||||
b = num[num.length - 1] if (num = b.last_replies)
|
else
|
||||||
b.no - a.no
|
currentSort = Index.currentSort
|
||||||
).map (post) -> post.no
|
sorted = switch currentSort
|
||||||
when 'lastlong'
|
when 'lastreply'
|
||||||
lastlong = (thread) ->
|
[liveThreadData...].sort((a, b) ->
|
||||||
for r, i in (thread.last_replies or []) by -1
|
a = num[num.length - 1] if (num = a.last_replies)
|
||||||
return r if r.com and Build.parseComment(r.com).replace(/[^a-z]/ig, '').length >= 100
|
b = num[num.length - 1] if (num = b.last_replies)
|
||||||
thread
|
b.no - a.no
|
||||||
[liveThreadData...].sort((a, b) ->
|
).map (post) -> post.no
|
||||||
lastlong(b).no - lastlong(a).no
|
when 'lastlong'
|
||||||
).map (post) -> post.no
|
lastlong = (thread) ->
|
||||||
when 'bump' then liveThreadIDs
|
for r, i in (thread.last_replies or []) by -1
|
||||||
when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a
|
return r if r.com and Build.parseComment(r.com).replace(/[^a-z]/ig, '').length >= 100
|
||||||
when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no
|
thread
|
||||||
when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no
|
[liveThreadData...].sort((a, b) ->
|
||||||
|
lastlong(b).no - lastlong(a).no
|
||||||
|
).map (post) -> post.no
|
||||||
|
when 'bump' then liveThreadIDs
|
||||||
|
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 '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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user