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,43 +2718,34 @@
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; if ('last_replies' in a) {
break; a = a.last_replies[a.last_replies.length - 1];
case 'lastreply': }
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) { if ('last_replies' in b) {
if ('last_replies' in a) { b = b.last_replies[b.last_replies.length - 1];
a = a.last_replies[a.last_replies.length - 1]; }
} return b.no - a.no;
if ('last_replies' in b) { }).map(function(data) {
b = b.last_replies[b.last_replies.length - 1]; return data.no;
} }),
return b.no - a.no; bump: Index.liveThreadIDs,
}).map(function(data) { birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) {
return data.no; return b - a;
}); }),
break; replycount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'birth': return b.replies - a.replies;
sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) { }).map(function(data) {
return b - a; return data.no;
}); }),
break; filecount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'replycount': return b.images - a.images;
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) { }).map(function(data) {
return b.replies - a.replies; return data.no;
}).map(function(data) { })
return data.no; }[Conf['Index Sort']];
});
break;
case 'filecount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images;
}).map(function(data) {
return data.no;
});
}
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;
return thread.isSticky; items = [
}); {
if (Conf['Filter']) { fn: function(thread) {
Index.sortOnTop(function(thread) { return thread.isSticky;
return thread.isOnTop; },
}); cnd: true
} }, {
if (Conf['Anchor Hidden Threads']) { fn: function(thread) {
return Index.sortOnTop(function(thread) { return thread.isOnTop;
return !thread.isHidden; },
}); cnd: Conf['Filter']
}, {
fn: function(thread) {
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,43 +2728,34 @@
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; if ('last_replies' in a) {
break; a = a.last_replies[a.last_replies.length - 1];
case 'lastreply': }
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) { if ('last_replies' in b) {
if ('last_replies' in a) { b = b.last_replies[b.last_replies.length - 1];
a = a.last_replies[a.last_replies.length - 1]; }
} return b.no - a.no;
if ('last_replies' in b) { }).map(function(data) {
b = b.last_replies[b.last_replies.length - 1]; return data.no;
} }),
return b.no - a.no; bump: Index.liveThreadIDs,
}).map(function(data) { birth: __slice.call(Index.liveThreadIDs).sort(function(a, b) {
return data.no; return b - a;
}); }),
break; replycount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'birth': return b.replies - a.replies;
sortedThreadIDs = __slice.call(Index.liveThreadIDs).sort(function(a, b) { }).map(function(data) {
return b - a; return data.no;
}); }),
break; filecount: __slice.call(Index.liveThreadData).sort(function(a, b) {
case 'replycount': return b.images - a.images;
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) { }).map(function(data) {
return b.replies - a.replies; return data.no;
}).map(function(data) { })
return data.no; }[Conf['Index Sort']];
});
break;
case 'filecount':
sortedThreadIDs = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images;
}).map(function(data) {
return data.no;
});
}
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;
return thread.isSticky; items = [
}); {
if (Conf['Filter']) { fn: function(thread) {
Index.sortOnTop(function(thread) { return thread.isSticky;
return thread.isOnTop; },
}); cnd: true
} }, {
if (Conf['Anchor Hidden Threads']) { fn: function(thread) {
return Index.sortOnTop(function(thread) { return thread.isOnTop;
return !thread.isHidden; },
}); cnd: Conf['Filter']
}, {
fn: function(thread) {
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