Support setting sort type of each board independently. #178
This commit is contained in:
parent
e2636be9e8
commit
95190ca96f
@ -739,7 +739,6 @@ Config =
|
|||||||
Index:
|
Index:
|
||||||
'Index Mode': 'paged'
|
'Index Mode': 'paged'
|
||||||
'Previous Index Mode': 'paged'
|
'Previous Index Mode': 'paged'
|
||||||
'Index Sort': 'bump'
|
|
||||||
'Index Size': 'small'
|
'Index Size': 'small'
|
||||||
'Show Replies': true
|
'Show Replies': true
|
||||||
'Pin Watched Threads': false
|
'Pin Watched Threads': false
|
||||||
|
|||||||
@ -12,8 +12,12 @@ Index =
|
|||||||
@search = history.state?.searched or ''
|
@search = history.state?.searched or ''
|
||||||
if history.state?.mode
|
if history.state?.mode
|
||||||
Conf['Index Mode'] = history.state?.mode
|
Conf['Index Mode'] = history.state?.mode
|
||||||
if history.state?.sort
|
@currentSort = history.state?.sort
|
||||||
Conf['Index Sort'] = history.state?.sort
|
@currentSort or=
|
||||||
|
if typeof Conf['Index Sort'] is 'object'
|
||||||
|
Conf['Index Sort'][g.BOARD.ID] or 'bump'
|
||||||
|
else
|
||||||
|
Conf['Index Sort']
|
||||||
@currentPage = @getCurrentPage()
|
@currentPage = @getCurrentPage()
|
||||||
@processHash()
|
@processHash()
|
||||||
|
|
||||||
@ -32,9 +36,11 @@ Index =
|
|||||||
|
|
||||||
# Header "Index Navigation" submenu
|
# Header "Index Navigation" submenu
|
||||||
repliesEntry = el: UI.checkbox 'Show Replies', 'Show replies'
|
repliesEntry = el: UI.checkbox 'Show Replies', 'Show replies'
|
||||||
|
sortEntry = el: UI.checkbox 'Per-Board Sort Type', 'Per-board sort type', (typeof Conf['Index Sort'] is 'object')
|
||||||
pinEntry = el: UI.checkbox 'Pin Watched Threads', 'Pin watched threads'
|
pinEntry = el: UI.checkbox 'Pin Watched Threads', 'Pin watched threads'
|
||||||
anchorEntry = el: UI.checkbox 'Anchor Hidden Threads', 'Anchor hidden threads'
|
anchorEntry = el: UI.checkbox 'Anchor Hidden Threads', 'Anchor hidden threads'
|
||||||
refNavEntry = el: UI.checkbox 'Refreshed Navigation', 'Refreshed navigation'
|
refNavEntry = el: UI.checkbox 'Refreshed Navigation', 'Refreshed navigation'
|
||||||
|
sortEntry.el.title = 'Set the sorting order of each board independently.'
|
||||||
pinEntry.el.title = 'Move watched threads to the start of the index.'
|
pinEntry.el.title = 'Move watched threads to the start of the index.'
|
||||||
anchorEntry.el.title = 'Move hidden threads to the end of the index.'
|
anchorEntry.el.title = 'Move hidden threads to the end of the index.'
|
||||||
refNavEntry.el.title = 'Refresh index when navigating through pages.'
|
refNavEntry.el.title = 'Refresh index when navigating through pages.'
|
||||||
@ -47,12 +53,13 @@ Index =
|
|||||||
$.on input, 'change', @cb.replies
|
$.on input, 'change', @cb.replies
|
||||||
when 'Pin Watched Threads', 'Anchor Hidden Threads'
|
when 'Pin Watched Threads', 'Anchor Hidden Threads'
|
||||||
$.on input, 'change', @cb.resort
|
$.on input, 'change', @cb.resort
|
||||||
|
$.on sortEntry.el.firstChild, 'change', @cb.perBoardSort
|
||||||
|
|
||||||
Header.menu.addEntry
|
Header.menu.addEntry
|
||||||
el: $.el 'span',
|
el: $.el 'span',
|
||||||
textContent: 'Index Navigation'
|
textContent: 'Index Navigation'
|
||||||
order: 100
|
order: 100
|
||||||
subEntries: [repliesEntry, pinEntry, anchorEntry, refNavEntry]
|
subEntries: [repliesEntry, sortEntry, pinEntry, anchorEntry, refNavEntry]
|
||||||
|
|
||||||
# Navigation links at top of index
|
# Navigation links at top of index
|
||||||
@navLinks = $.el 'div', className: 'navLinks json-index'
|
@navLinks = $.el 'div', className: 'navLinks json-index'
|
||||||
@ -79,8 +86,9 @@ Index =
|
|||||||
$.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, @selectSort, @selectSize]
|
for select in [@selectMode, @selectSize]
|
||||||
select.value = Conf[select.name]
|
select.value = Conf[select.name]
|
||||||
|
@selectSort.value = Index.currentSort
|
||||||
|
|
||||||
# Thread container
|
# Thread container
|
||||||
@root = $.el 'div', className: 'board json-index'
|
@root = $.el 'div', className: 'board json-index'
|
||||||
@ -223,6 +231,10 @@ Index =
|
|||||||
Index.sort()
|
Index.sort()
|
||||||
Index.buildIndex()
|
Index.buildIndex()
|
||||||
|
|
||||||
|
perBoardSort: ->
|
||||||
|
Conf['Index Sort'] = if @checked then {} else ''
|
||||||
|
Index.saveSort()
|
||||||
|
|
||||||
size: (e) ->
|
size: (e) ->
|
||||||
if Conf['Index Mode'] isnt 'catalog'
|
if Conf['Index Mode'] isnt 'catalog'
|
||||||
$.rmClass Index.root, 'catalog-small'
|
$.rmClass Index.root, 'catalog-small'
|
||||||
@ -340,7 +352,7 @@ Index =
|
|||||||
hash or= ''
|
hash or= ''
|
||||||
history[if replace then 'replaceState' else 'pushState']
|
history[if replace then 'replaceState' else 'pushState']
|
||||||
mode: Conf['Index Mode']
|
mode: Conf['Index Mode']
|
||||||
sort: Conf['Index Sort']
|
sort: Index.currentSort
|
||||||
searched: Index.search
|
searched: Index.search
|
||||||
oldpage: pageBeforeSearch
|
oldpage: pageBeforeSearch
|
||||||
, '', "#{location.protocol}//#{location.host}#{pathname}#{hash}"
|
, '', "#{location.protocol}//#{location.host}#{pathname}#{hash}"
|
||||||
@ -356,10 +368,10 @@ Index =
|
|||||||
unless mode is 'catalog' or Conf['Previous Index Mode'] is mode
|
unless mode is 'catalog' or Conf['Previous Index Mode'] is mode
|
||||||
Conf['Previous Index Mode'] = mode
|
Conf['Previous Index Mode'] = mode
|
||||||
$.set 'Previous Index Mode', mode
|
$.set 'Previous Index Mode', mode
|
||||||
if sort? and sort isnt Conf['Index Sort']
|
if sort? and sort isnt Index.currentSort
|
||||||
Index.changed.sort = true
|
Index.changed.sort = true
|
||||||
Conf['Index Sort'] = sort
|
Index.currentSort = sort
|
||||||
$.set 'Index Sort', sort
|
Index.saveSort()
|
||||||
page = 1 if Conf['Index Mode'] in ['all pages', 'catalog']
|
page = 1 if Conf['Index Mode'] in ['all pages', 'catalog']
|
||||||
if page? and page isnt Index.currentPage
|
if page? and page isnt Index.currentPage
|
||||||
Index.changed.page = true
|
Index.changed.page = true
|
||||||
@ -367,6 +379,13 @@ Index =
|
|||||||
if hash?
|
if hash?
|
||||||
Index.changed.hash = true
|
Index.changed.hash = true
|
||||||
|
|
||||||
|
saveSort: ->
|
||||||
|
if typeof Conf['Index Sort'] is 'object'
|
||||||
|
Conf['Index Sort'][g.BOARD.ID] = Index.currentSort
|
||||||
|
else
|
||||||
|
Conf['Index Sort'] = Index.currentSort
|
||||||
|
$.set 'Index Sort', Conf['Index Sort']
|
||||||
|
|
||||||
pageLoad: (scroll=true) ->
|
pageLoad: (scroll=true) ->
|
||||||
return unless Index.liveThreadData
|
return unless Index.liveThreadData
|
||||||
{threads, search, mode, sort, page, hash} = Index.changed
|
{threads, search, mode, sort, page, hash} = Index.changed
|
||||||
@ -390,7 +409,7 @@ Index =
|
|||||||
$('#hidden-toggle a', Index.navLinks).textContent = 'Show'
|
$('#hidden-toggle a', Index.navLinks).textContent = 'Show'
|
||||||
|
|
||||||
setupSort: ->
|
setupSort: ->
|
||||||
Index.selectSort.value = Conf['Index Sort']
|
Index.selectSort.value = Index.currentSort
|
||||||
|
|
||||||
getPagesNum: ->
|
getPagesNum: ->
|
||||||
if Index.search
|
if Index.search
|
||||||
@ -635,7 +654,7 @@ Index =
|
|||||||
sort: ->
|
sort: ->
|
||||||
{liveThreadIDs, liveThreadData} = Index
|
{liveThreadIDs, liveThreadData} = Index
|
||||||
return unless liveThreadData
|
return unless liveThreadData
|
||||||
sortedThreadIDs = switch Conf['Index Sort']
|
sortedThreadIDs = switch Index.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)
|
||||||
|
|||||||
@ -53,6 +53,7 @@ Main =
|
|||||||
Conf[db] = boards: {}
|
Conf[db] = boards: {}
|
||||||
Conf['selectedArchives'] = {}
|
Conf['selectedArchives'] = {}
|
||||||
Conf['cooldowns'] = {}
|
Conf['cooldowns'] = {}
|
||||||
|
Conf['Index Sort'] = {}
|
||||||
|
|
||||||
# XXX old key names
|
# XXX old key names
|
||||||
Conf['Except Archives from Encryption'] = false
|
Conf['Except Archives from Encryption'] = false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user