Add sorting options by bump order and creation date.

This commit is contained in:
Mayhem 2013-10-31 19:10:24 +01:00
parent 0038f1f011
commit 092d9317e0
4 changed files with 53 additions and 24 deletions

View File

@ -1,6 +1,10 @@
Index navigation improvements:
- You can now refresh the index page you are on with the icon in the header bar or the same keybind for refreshing threads.
- You can now switch between single-page and all-pages navigation via the "Index Navigation" header sub-menu.
- Threads in the index can now be sorted by:
- bump order
- creation date
Added a keybind to open the catalog search field on index pages.
### 3.11.5 - *2013-10-03*

View File

@ -104,7 +104,7 @@ $.rm = do ->
(el) -> el.parentNode?.removeChild el
$.rmAll = (root) ->
# jsperf.com/emptify-element
while node = root.firstChild
for node in [root.childNodes...]
# HTMLSelectElement.remove !== Element.remove
root.removeChild node
return

View File

@ -139,8 +139,10 @@ Config =
#//archive.foolz.us/%board/search/image/%MD5/;text:View same on foolz /%board/
#//archive.installgentoo.net/%board/image/%MD5;text:View same on installgentoo /%board/
"""
'Index Mode': 'paged'
'Custom CSS': false
Index:
'Index Mode': 'paged'
'Index Sort': 'bump'
Header:
'Header auto-hide': false
'Bottom header': false

View File

@ -9,34 +9,44 @@ Index =
$.on button, 'click', Index.update
Header.addShortcut button, 1
subEntries = []
subEntry =
el: $.el 'span', textContent: 'Index Mode'
modeEntry =
el: $.el 'span', textContent: 'Index mode'
subEntries: [
{ el: $.el 'label', innerHTML: '<input type=radio name="Index Mode" value="paged"> Paged' }
{ el: $.el 'label', innerHTML: '<input type=radio name="Index Mode" value="all pages"> All threads' }
]
for label in subEntry.subEntries
for label in modeEntry.subEntries
input = label.el.firstChild
input.checked = Conf['Index Mode'] is input.value
$.on input, 'change', $.cb.value
$.on input, 'change', @update
subEntries.push subEntry
sortEntry =
el: $.el 'span', textContent: 'Sort by'
subEntries: [
{ el: $.el 'label', innerHTML: '<input type=radio name="Index Sort" value="bump"> Bump order' }
{ el: $.el 'label', innerHTML: '<input type=radio name="Index Sort" value="birth"> Creation date' }
]
for label in sortEntry.subEntries
input = label.el.firstChild
input.checked = Conf['Index Sort'] is input.value
$.on input, 'change', $.cb.value
$.on input, 'change', @resort
$.event 'AddMenuEntry',
type: 'header'
el: $.el 'span',
textContent: 'Index Navigation'
order: 90
subEntries: subEntries
subEntries: [modeEntry, sortEntry]
$.on d, '4chanXInitFinished', @initReady
initReady: ->
$.off d, '4chanXInitFinished', Index.initReady
Index.root = $ '.board'
Index.setIndex $$ '.board > .thread, .board > hr', Index.root
Index.liveThreads = $$('.board > .thread', Index.root).map Get.threadFromRoot
Index.resort()
return if Conf['Index Mode'] is 'paged'
Index.update()
@ -84,17 +94,17 @@ Index =
for page in pages
dataThr.push page.threads...
nodes = []
threads = []
liveThreads = []
posts = []
nodes = []
threads = []
posts = []
Index.liveThreads = []
for data in dataThr
threadRoot = Build.thread g.BOARD, data
nodes.push threadRoot, $.el 'hr'
unless thread = g.threads["#{g.BOARD}.#{data.no}"]
thread = new Thread data.no, g.BOARD
threads.push thread
liveThreads.push thread
Index.liveThreads.push thread
for postRoot in $$ '.thread > .postContainer', threadRoot
continue if thread.posts[postRoot.id.match /\d+/]
try
@ -108,7 +118,7 @@ Index =
error: err
Main.handleErrors errors if errors
Index.collectDeadThreads liveThreads
Index.collectDeadThreads()
# Add the threads and <hr>s in a container to make sure all features work.
$.nodes nodes
Main.callbackNodes Thread, threads
@ -120,19 +130,32 @@ Index =
$.rmAll Index.root
$.add Index.root, Index.sort nodes
$('.pagelist').hidden = Conf['Index Mode'] isnt 'paged'
sort: (nodes) ->
sort: (unsortedNodes) ->
nodes = []
switch Conf['Index Sort']
when 'bump'
for thread in Index.liveThreads
i = unsortedNodes.indexOf thread.OP.nodes.root.parentNode
nodes.push unsortedNodes[i], unsortedNodes[i + 1]
when 'birth'
dates = []
for threadRoot, i in unsortedNodes by 2
dates.push Get.threadFromRoot(threadRoot).OP.info.date
unsortedDates = [dates...]
for date in dates.sort((a, b) -> b - a)
i = unsortedDates.indexOf(date) * 2
nodes.push unsortedNodes[i], unsortedNodes[i + 1]
return nodes unless Conf['Filter']
# Put the highlighted thread & <hr> on top of the index
# while keeping the original order they appear in.
i = offset = 0
while threadRoot = nodes[i]
if Get.threadFromRoot(threadRoot).isOnTop
nodes.splice offset, 0, nodes.splice(i, 2)...
offset += 2
i += 2
offset = 0
for threadRoot, i in nodes by 2 when Get.threadFromRoot(threadRoot).isOnTop
nodes.splice offset++ * 2, 0, nodes.splice(i, 2)...
nodes
resort: ->
Index.setIndex $$ '.board > .thread, .board > hr', Index.root
collectDeadThreads: (liveThreads) ->
for threadID, thread of g.threads when thread not in liveThreads
for threadID, thread of g.threads when thread not in Index.liveThreads
thread.collect()
return