diff --git a/src/General/Config.coffee b/src/General/Config.coffee index b2b173952..c937ba950 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -739,7 +739,6 @@ Config = Index: 'Index Mode': 'paged' 'Previous Index Mode': 'paged' - 'Index Sort': 'bump' 'Index Size': 'small' 'Show Replies': true 'Pin Watched Threads': false diff --git a/src/General/Index.coffee b/src/General/Index.coffee index cbdc05544..dcabd6f2a 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -12,8 +12,12 @@ Index = @search = history.state?.searched or '' if history.state?.mode Conf['Index Mode'] = history.state?.mode - if history.state?.sort - Conf['Index Sort'] = history.state?.sort + @currentSort = 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() @processHash() @@ -32,9 +36,11 @@ Index = # Header "Index Navigation" submenu 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' anchorEntry = el: UI.checkbox 'Anchor Hidden Threads', 'Anchor hidden threads' 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.' anchorEntry.el.title = 'Move hidden threads to the end of the index.' refNavEntry.el.title = 'Refresh index when navigating through pages.' @@ -47,12 +53,13 @@ Index = $.on input, 'change', @cb.replies when 'Pin Watched Threads', 'Anchor Hidden Threads' $.on input, 'change', @cb.resort + $.on sortEntry.el.firstChild, 'change', @cb.perBoardSort Header.menu.addEntry el: $.el 'span', textContent: 'Index Navigation' order: 100 - subEntries: [repliesEntry, pinEntry, anchorEntry, refNavEntry] + subEntries: [repliesEntry, sortEntry, pinEntry, anchorEntry, refNavEntry] # Navigation links at top of index @navLinks = $.el 'div', className: 'navLinks json-index' @@ -79,8 +86,9 @@ Index = $.on @selectSort, 'change', @cb.sort $.on @selectSize, 'change', $.cb.value $.on @selectSize, 'change', @cb.size - for select in [@selectMode, @selectSort, @selectSize] + for select in [@selectMode, @selectSize] select.value = Conf[select.name] + @selectSort.value = Index.currentSort # Thread container @root = $.el 'div', className: 'board json-index' @@ -223,6 +231,10 @@ Index = Index.sort() Index.buildIndex() + perBoardSort: -> + Conf['Index Sort'] = if @checked then {} else '' + Index.saveSort() + size: (e) -> if Conf['Index Mode'] isnt 'catalog' $.rmClass Index.root, 'catalog-small' @@ -340,7 +352,7 @@ Index = hash or= '' history[if replace then 'replaceState' else 'pushState'] mode: Conf['Index Mode'] - sort: Conf['Index Sort'] + sort: Index.currentSort searched: Index.search oldpage: pageBeforeSearch , '', "#{location.protocol}//#{location.host}#{pathname}#{hash}" @@ -356,10 +368,10 @@ Index = unless mode is 'catalog' or Conf['Previous Index Mode'] is mode Conf['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 - Conf['Index Sort'] = sort - $.set 'Index Sort', sort + Index.currentSort = sort + Index.saveSort() page = 1 if Conf['Index Mode'] in ['all pages', 'catalog'] if page? and page isnt Index.currentPage Index.changed.page = true @@ -367,6 +379,13 @@ Index = if hash? 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) -> return unless Index.liveThreadData {threads, search, mode, sort, page, hash} = Index.changed @@ -390,7 +409,7 @@ Index = $('#hidden-toggle a', Index.navLinks).textContent = 'Show' setupSort: -> - Index.selectSort.value = Conf['Index Sort'] + Index.selectSort.value = Index.currentSort getPagesNum: -> if Index.search @@ -635,7 +654,7 @@ Index = sort: -> {liveThreadIDs, liveThreadData} = Index return unless liveThreadData - sortedThreadIDs = switch Conf['Index Sort'] + sortedThreadIDs = switch Index.currentSort when 'lastreply' [liveThreadData...].sort((a, b) -> a = num[num.length - 1] if (num = a.last_replies) diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 0a2c8d8ee..8245bf35a 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -53,6 +53,7 @@ Main = Conf[db] = boards: {} Conf['selectedArchives'] = {} Conf['cooldowns'] = {} + Conf['Index Sort'] = {} # XXX old key names Conf['Except Archives from Encryption'] = false