Consolidate things a little

This commit is contained in:
Zixaphir 2014-01-16 08:28:40 -07:00
parent d34284a8d0
commit ef99677f14
3 changed files with 130 additions and 114 deletions

View File

@ -2718,13 +2718,9 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
sort: function() { sort: function() {
var i, sortedThreadIDs, threadID, _i, _len; var cnd, fn, i, item, items, sortOnTop, sortedThreadIDs, threadID, _i, _len;
switch (Conf['Index Sort']) { sortedThreadIDs = {
case 'bump': lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) {
sortedThreadIDs = Index.liveThreadIDs;
break;
case 'lastreply':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
if ('last_replies' in a) { if ('last_replies' in a) {
a = a.last_replies[a.last_replies.length - 1]; a = a.last_replies[a.last_replies.length - 1];
} }
@ -2734,27 +2730,22 @@
return b.no - a.no; return b.no - a.no;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); }),
break; bump: Index.liveThreadIDs,
case 'birth': birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) {
sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) {
return b - a; return b - a;
}); }),
break; replycount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'replycount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); }),
break; filecount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'filecount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); })
} }[Conf['Index Sort']];
Index.sortedNodes = []; Index.sortedNodes = [];
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) {
threadID = sortedThreadIDs[_i]; threadID = sortedThreadIDs[_i];
@ -2764,18 +2755,31 @@
if (Index.isSearching) { if (Index.isSearching) {
Index.sortedNodes = Index.querySearch(Index.searchInput.value) || Index.sortedNodes; Index.sortedNodes = Index.querySearch(Index.searchInput.value) || Index.sortedNodes;
} }
Index.sortOnTop(function(thread) { sortOnTop = Index.sortOnTop;
items = [
{
fn: function(thread) {
return thread.isSticky; return thread.isSticky;
}); },
if (Conf['Filter']) { cnd: true
Index.sortOnTop(function(thread) { }, {
fn: function(thread) {
return thread.isOnTop; return thread.isOnTop;
}); },
} cnd: Conf['Filter']
if (Conf['Anchor Hidden Threads']) { }, {
return Index.sortOnTop(function(thread) { fn: function(thread) {
return !thread.isHidden; return !thread.isHidden;
}); },
cnd: Conf['Anchor Hidden Threads']
}
];
i = 0;
while (item = items[i++]) {
fn = item.fn, cnd = item.cnd;
if (fn) {
sortOnTop(fn);
}
} }
}, },
sortOnTop: function(match) { sortOnTop: function(match) {

View File

@ -2728,13 +2728,9 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
sort: function() { sort: function() {
var i, sortedThreadIDs, threadID, _i, _len; var cnd, fn, i, item, items, sortOnTop, sortedThreadIDs, threadID, _i, _len;
switch (Conf['Index Sort']) { sortedThreadIDs = {
case 'bump': lastreply: __slice.call(Index.liveThreadData).sort(function(a, b) {
sortedThreadIDs = Index.liveThreadIDs;
break;
case 'lastreply':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
if ('last_replies' in a) { if ('last_replies' in a) {
a = a.last_replies[a.last_replies.length - 1]; a = a.last_replies[a.last_replies.length - 1];
} }
@ -2744,27 +2740,22 @@
return b.no - a.no; return b.no - a.no;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); }),
break; bump: Index.liveThreadIDs,
case 'birth': birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) {
sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) {
return b - a; return b - a;
}); }),
break; replycount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'replycount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); }),
break; filecount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'filecount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}).map(function(data) { }).map(function(data) {
return data.no; return data.no;
}); })
} }[Conf['Index Sort']];
Index.sortedNodes = []; Index.sortedNodes = [];
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) {
threadID = sortedThreadIDs[_i]; threadID = sortedThreadIDs[_i];
@ -2774,18 +2765,31 @@
if (Index.isSearching) { if (Index.isSearching) {
Index.sortedNodes = Index.querySearch(Index.searchInput.value) || Index.sortedNodes; Index.sortedNodes = Index.querySearch(Index.searchInput.value) || Index.sortedNodes;
} }
Index.sortOnTop(function(thread) { sortOnTop = Index.sortOnTop;
items = [
{
fn: function(thread) {
return thread.isSticky; return thread.isSticky;
}); },
if (Conf['Filter']) { cnd: true
Index.sortOnTop(function(thread) { }, {
fn: function(thread) {
return thread.isOnTop; return thread.isOnTop;
}); },
} cnd: Conf['Filter']
if (Conf['Anchor Hidden Threads']) { }, {
return Index.sortOnTop(function(thread) { fn: function(thread) {
return !thread.isHidden; return !thread.isHidden;
}); },
cnd: Conf['Anchor Hidden Threads']
}
];
i = 0;
while (item = items[i++]) {
fn = item.fn, cnd = item.cnd;
if (fn) {
sortOnTop(fn);
}
} }
}, },
sortOnTop: function(match) { sortOnTop: function(match) {

View File

@ -374,21 +374,18 @@ Index =
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
sort: -> sort: ->
switch Conf['Index Sort'] sortedThreadIDs = {
when 'bump' lastreply:
sortedThreadIDs = Index.liveThreadIDs [Index.liveThreadData...].sort((a, b) ->
when 'lastreply'
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) ->
a = a.last_replies[a.last_replies.length - 1] if 'last_replies' of a a = a.last_replies[a.last_replies.length - 1] if 'last_replies' of a
b = b.last_replies[b.last_replies.length - 1] if 'last_replies' of b b = b.last_replies[b.last_replies.length - 1] if 'last_replies' of b
b.no - a.no b.no - a.no
).map (data) -> data.no ).map (data) -> data.no
when 'birth' bump: Index.liveThreadIDs
sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a birth: [Index.liveThreadIDs...].sort (a, b) -> b - a
when 'replycount' replycount: [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no filecount: [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no
when 'filecount' }[Conf['Index Sort']]
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no
Index.sortedNodes = [] Index.sortedNodes = []
for threadID in sortedThreadIDs for threadID in sortedThreadIDs
i = Index.liveThreadIDs.indexOf(threadID) * 2 i = Index.liveThreadIDs.indexOf(threadID) * 2
@ -396,11 +393,22 @@ Index =
if Index.isSearching if Index.isSearching
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
# Sticky threads # Sticky threads
Index.sortOnTop (thread) -> thread.isSticky {sortOnTop} = Index
# Highlighted threads items = [
Index.sortOnTop((thread) -> thread.isOnTop) if Conf['Filter'] fn: (thread) -> thread.isSticky
# Non-hidden threads cnd: true
Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads'] , # Highlighted threads
fn: (thread) -> thread.isOnTop
cnd: Conf['Filter']
, # Non-hidden threads
fn: (thread) -> !thread.isHidden
cnd: Conf['Anchor Hidden Threads']
]
i = 0
while item = items[i++]
{fn, cnd} = item
sortOnTop fn if fn
return
sortOnTop: (match) -> sortOnTop: (match) ->
offset = 0 offset = 0