Use while loops for consistency and also get rid of Array::filter

This commit is contained in:
Zixaphir 2014-03-11 14:14:24 -07:00
parent dec9775f80
commit 5cbe5753e8
3 changed files with 150 additions and 97 deletions

View File

@ -2832,10 +2832,14 @@
return $.event('change', null, Index.selectMode); return $.event('change', null, Index.selectMode);
}, },
cycleSortType: function() { cycleSortType: function() {
var i, type, types, _i, _len; var i, option, type, types, _i, _len;
types = __slice.call(Index.selectSort.options).filter(function(option) { types = [];
return !option.disabled; i = 0;
}); while (option = Index.selectSort.options[i++]) {
if (!option.disabled) {
types.push(option);
}
}
for (i = _i = 0, _len = types.length; _i < _len; i = ++_i) { for (i = _i = 0, _len = types.length; _i < _len; i = ++_i) {
type = types[i]; type = types[i];
if (type.selected) { if (type.selected) {
@ -2846,13 +2850,15 @@
return $.event('change', null, Index.selectSort); return $.event('change', null, Index.selectSort);
}, },
catalogSwitch: function() { catalogSwitch: function() {
var hash; return $.get('JSON Navigation', true, function(items) {
if (!Conf['JSON Navigation']) { var hash;
return; if (!items['JSON Navigation']) {
} return;
$.set('Index Mode', 'catalog'); }
hash = window.location.hash; $.set('Index Mode', 'catalog');
return window.location = './' + hash; hash = window.location.hash;
return window.location = './' + hash;
});
}, },
searchTest: function() { searchTest: function() {
var hash, match; var hash, match;
@ -2942,20 +2948,18 @@
return Index.buildIndex(); return Index.buildIndex();
}, },
target: function() { target: function() {
var thread, threadID, thumb, _ref; return g.BOARD.threads.forEach(function(thread) {
_ref = g.BOARD.threads; var thumb;
for (threadID in _ref) {
thread = _ref[threadID];
if (!thread.catalogView) { if (!thread.catalogView) {
continue; return;
} }
thumb = thread.catalogView.nodes.thumb; thumb = thread.catalogView.nodes.thumb;
if (Conf['Open threads in a new tab']) { if (Conf['Open threads in a new tab']) {
thumb.target = '_blank'; return thumb.target = '_blank';
} else { } else {
thumb.removeAttribute('target'); return thumb.removeAttribute('target');
} }
} });
}, },
replies: function() { replies: function() {
Index.buildThreads(); Index.buildThreads();
@ -3359,7 +3363,7 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
buildCatalogViews: function() { buildCatalogViews: function() {
var catalogThreads, nodes, thread, _i, _j, _len, _len1, _ref, _ref1; var catalogThreads, i, nodes, thread, _i, _len, _ref;
catalogThreads = []; catalogThreads = [];
_ref = Index.sortedThreads; _ref = Index.sortedThreads;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -3370,9 +3374,8 @@
} }
Main.callbackNodes(CatalogThread, catalogThreads); Main.callbackNodes(CatalogThread, catalogThreads);
nodes = []; nodes = [];
_ref1 = Index.sortedThreads; i = 0;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { while (thread = Index.sortedThreads[i++]) {
thread = _ref1[_j];
nodes.push(thread.catalogView.nodes.root); nodes.push(thread.catalogView.nodes.root);
} }
return nodes; return nodes;
@ -3393,7 +3396,7 @@
} }
}, },
sort: function() { sort: function() {
var sortedThreadIDs, sortedThreads, threadID, _i, _len; var i, sortedThreadIDs, sortedThreads, thread, threadID;
sortedThreads = []; sortedThreads = [];
sortedThreadIDs = []; sortedThreadIDs = [];
({ ({
@ -3401,7 +3404,7 @@
return sortedThreadIDs = Index.liveThreadIDs; return sortedThreadIDs = Index.liveThreadIDs;
}, },
'lastreply': function() { 'lastreply': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
var _ref, _ref1; var _ref, _ref1;
if ('last_replies' in a) { if ('last_replies' in a) {
@ -3412,8 +3415,8 @@
} }
return b.no - a.no; return b.no - a.no;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
}, },
@ -3423,33 +3426,37 @@
}); });
}, },
'replycount': function() { 'replycount': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
}, },
'filecount': function() { 'filecount': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
} }
})[Conf['Index Sort']](); })[Conf['Index Sort']]();
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { i = 0;
threadID = sortedThreadIDs[_i]; while (threadID = sortedThreadIDs[i++]) {
sortedThreads.push(g.BOARD.threads[threadID]); sortedThreads.push(g.BOARD.threads[threadID]);
} }
Index.sortedThreads = sortedThreads.filter(function(thread) { Index.sortedThreads = [];
return thread.isHidden === Index.showHiddenThreads; i = 0;
}); while (thread = sortedThreads[i++]) {
if (thread.isHidden === Index.showHiddenThreads) {
Index.sortedThreads.push(thread);
}
}
if (Index.isSearching) { if (Index.isSearching) {
Index.sortedThreads = Index.querySearch(Index.searchInput.value) || Index.sortedThreads; Index.sortedThreads = Index.querySearch(Index.searchInput.value) || Index.sortedThreads;
} }
@ -3553,9 +3560,16 @@
return Index.search(keywords); return Index.search(keywords);
}, },
search: function(keywords) { search: function(keywords) {
return Index.sortedThreads.filter(function(thread) { var filtered, i, sortedThreads, thread;
return Index.searchMatch(thread, keywords); filtered = [];
}); i = 0;
sortedThreads = Index.sortedThreads;
while (thread = sortedThreads[i++]) {
if (Index.searchMatch(thread, keywords)) {
filtered.push(thread);
}
}
return Index.sortedThreads = filtered;
}, },
searchMatch: function(thread, keywords) { searchMatch: function(thread, keywords) {
var file, info, key, keyword, text, _i, _j, _len, _len1, _ref, _ref1; var file, info, key, keyword, text, _i, _j, _len, _len1, _ref, _ref1;

View File

@ -2891,10 +2891,14 @@
return $.event('change', null, Index.selectMode); return $.event('change', null, Index.selectMode);
}, },
cycleSortType: function() { cycleSortType: function() {
var i, type, types, _i, _len; var i, option, type, types, _i, _len;
types = __slice.call(Index.selectSort.options).filter(function(option) { types = [];
return !option.disabled; i = 0;
}); while (option = Index.selectSort.options[i++]) {
if (!option.disabled) {
types.push(option);
}
}
for (i = _i = 0, _len = types.length; _i < _len; i = ++_i) { for (i = _i = 0, _len = types.length; _i < _len; i = ++_i) {
type = types[i]; type = types[i];
if (type.selected) { if (type.selected) {
@ -2905,13 +2909,15 @@
return $.event('change', null, Index.selectSort); return $.event('change', null, Index.selectSort);
}, },
catalogSwitch: function() { catalogSwitch: function() {
var hash; return $.get('JSON Navigation', true, function(items) {
if (!Conf['JSON Navigation']) { var hash;
return; if (!items['JSON Navigation']) {
} return;
$.set('Index Mode', 'catalog'); }
hash = window.location.hash; $.set('Index Mode', 'catalog');
return window.location = './' + hash; hash = window.location.hash;
return window.location = './' + hash;
});
}, },
searchTest: function() { searchTest: function() {
var hash, match; var hash, match;
@ -3001,20 +3007,18 @@
return Index.buildIndex(); return Index.buildIndex();
}, },
target: function() { target: function() {
var thread, threadID, thumb, _ref; return g.BOARD.threads.forEach(function(thread) {
_ref = g.BOARD.threads; var thumb;
for (threadID in _ref) {
thread = _ref[threadID];
if (!thread.catalogView) { if (!thread.catalogView) {
continue; return;
} }
thumb = thread.catalogView.nodes.thumb; thumb = thread.catalogView.nodes.thumb;
if (Conf['Open threads in a new tab']) { if (Conf['Open threads in a new tab']) {
thumb.target = '_blank'; return thumb.target = '_blank';
} else { } else {
thumb.removeAttribute('target'); return thumb.removeAttribute('target');
} }
} });
}, },
replies: function() { replies: function() {
Index.buildThreads(); Index.buildThreads();
@ -3418,7 +3422,7 @@
return Main.callbackNodes(Post, posts); return Main.callbackNodes(Post, posts);
}, },
buildCatalogViews: function() { buildCatalogViews: function() {
var catalogThreads, nodes, thread, _i, _j, _len, _len1, _ref, _ref1; var catalogThreads, i, nodes, thread, _i, _len, _ref;
catalogThreads = []; catalogThreads = [];
_ref = Index.sortedThreads; _ref = Index.sortedThreads;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -3429,9 +3433,8 @@
} }
Main.callbackNodes(CatalogThread, catalogThreads); Main.callbackNodes(CatalogThread, catalogThreads);
nodes = []; nodes = [];
_ref1 = Index.sortedThreads; i = 0;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { while (thread = Index.sortedThreads[i++]) {
thread = _ref1[_j];
nodes.push(thread.catalogView.nodes.root); nodes.push(thread.catalogView.nodes.root);
} }
return nodes; return nodes;
@ -3452,7 +3455,7 @@
} }
}, },
sort: function() { sort: function() {
var sortedThreadIDs, sortedThreads, threadID, _i, _len; var i, sortedThreadIDs, sortedThreads, thread, threadID;
sortedThreads = []; sortedThreads = [];
sortedThreadIDs = []; sortedThreadIDs = [];
({ ({
@ -3460,7 +3463,7 @@
return sortedThreadIDs = Index.liveThreadIDs; return sortedThreadIDs = Index.liveThreadIDs;
}, },
'lastreply': function() { 'lastreply': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
var _ref, _ref1; var _ref, _ref1;
if ('last_replies' in a) { if ('last_replies' in a) {
@ -3471,8 +3474,8 @@
} }
return b.no - a.no; return b.no - a.no;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
}, },
@ -3482,33 +3485,37 @@
}); });
}, },
'replycount': function() { 'replycount': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.replies - a.replies; return b.replies - a.replies;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
}, },
'filecount': function() { 'filecount': function() {
var data, liveData, _i, _len; var data, i, liveData;
liveData = __slice.call(Index.liveThreadData).sort(function(a, b) { liveData = __slice.call(Index.liveThreadData).sort(function(a, b) {
return b.images - a.images; return b.images - a.images;
}); });
for (_i = 0, _len = liveData.length; _i < _len; _i++) { i = 0;
data = liveData[_i]; while (data = liveData[i++]) {
sortedThreadIDs.push(data.no); sortedThreadIDs.push(data.no);
} }
} }
})[Conf['Index Sort']](); })[Conf['Index Sort']]();
for (_i = 0, _len = sortedThreadIDs.length; _i < _len; _i++) { i = 0;
threadID = sortedThreadIDs[_i]; while (threadID = sortedThreadIDs[i++]) {
sortedThreads.push(g.BOARD.threads[threadID]); sortedThreads.push(g.BOARD.threads[threadID]);
} }
Index.sortedThreads = sortedThreads.filter(function(thread) { Index.sortedThreads = [];
return thread.isHidden === Index.showHiddenThreads; i = 0;
}); while (thread = sortedThreads[i++]) {
if (thread.isHidden === Index.showHiddenThreads) {
Index.sortedThreads.push(thread);
}
}
if (Index.isSearching) { if (Index.isSearching) {
Index.sortedThreads = Index.querySearch(Index.searchInput.value) || Index.sortedThreads; Index.sortedThreads = Index.querySearch(Index.searchInput.value) || Index.sortedThreads;
} }
@ -3612,9 +3619,16 @@
return Index.search(keywords); return Index.search(keywords);
}, },
search: function(keywords) { search: function(keywords) {
return Index.sortedThreads.filter(function(thread) { var filtered, i, sortedThreads, thread;
return Index.searchMatch(thread, keywords); filtered = [];
}); i = 0;
sortedThreads = Index.sortedThreads;
while (thread = sortedThreads[i++]) {
if (Index.searchMatch(thread, keywords)) {
filtered.push(thread);
}
}
return Index.sortedThreads = filtered;
}, },
searchMatch: function(thread, keywords) { searchMatch: function(thread, keywords) {
var file, info, key, keyword, text, _i, _j, _len, _len1, _ref, _ref1; var file, info, key, keyword, text, _i, _j, _len, _len1, _ref, _ref1;

View File

@ -252,17 +252,21 @@ Index =
$.event 'change', null, Index.selectMode $.event 'change', null, Index.selectMode
cycleSortType: -> cycleSortType: ->
types = [Index.selectSort.options...].filter (option) -> !option.disabled types = []
i = 0
while option = Index.selectSort.options[i++]
types.push option if !option.disabled
for type, i in types for type, i in types
break if type.selected break if type.selected
types[(i + 1) % types.length].selected = true types[(i + 1) % types.length].selected = true
$.event 'change', null, Index.selectSort $.event 'change', null, Index.selectSort
catalogSwitch: -> catalogSwitch: ->
return if !Conf['JSON Navigation'] $.get 'JSON Navigation', true, (items) ->
$.set 'Index Mode', 'catalog' return if !items['JSON Navigation']
{hash} = window.location $.set 'Index Mode', 'catalog'
window.location = './' + hash {hash} = window.location
window.location = './' + hash
searchTest: -> searchTest: ->
return unless hash = window.location.hash return unless hash = window.location.hash
@ -331,13 +335,13 @@ Index =
Index.buildIndex() Index.buildIndex()
target: -> target: ->
for threadID, thread of g.BOARD.threads when thread.catalogView g.BOARD.threads.forEach (thread) ->
return if !thread.catalogView
{thumb} = thread.catalogView.nodes {thumb} = thread.catalogView.nodes
if Conf['Open threads in a new tab'] if Conf['Open threads in a new tab']
thumb.target = '_blank' thumb.target = '_blank'
else else
thumb.removeAttribute 'target' thumb.removeAttribute 'target'
return
replies: -> replies: ->
Index.buildThreads() Index.buildThreads()
@ -652,7 +656,9 @@ Index =
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
Main.callbackNodes CatalogThread, catalogThreads Main.callbackNodes CatalogThread, catalogThreads
nodes = [] nodes = []
nodes.push thread.catalogView.nodes.root for thread in Index.sortedThreads i = 0
while thread = Index.sortedThreads[i++]
nodes.push thread.catalogView.nodes.root
return nodes return nodes
sizeCatalogViews: (nodes) -> sizeCatalogViews: (nodes) ->
@ -679,21 +685,35 @@ Index =
[..., a] = a.last_replies if 'last_replies' of a [..., a] = a.last_replies if 'last_replies' of a
[..., b] = b.last_replies if 'last_replies' of b [..., b] = b.last_replies if 'last_replies' of b
b.no - a.no b.no - a.no
sortedThreadIDs.push data.no for data in liveData i = 0
while data = liveData[i++]
sortedThreadIDs.push data.no
return return
'birth': -> 'birth': ->
sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a
'replycount': -> 'replycount': ->
liveData = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies) liveData = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies)
sortedThreadIDs.push data.no for data in liveData i = 0
while data = liveData[i++]
sortedThreadIDs.push data.no
return return
'filecount': -> 'filecount': ->
liveData = [Index.liveThreadData...].sort((a, b) -> b.images - a.images) liveData = [Index.liveThreadData...].sort((a, b) -> b.images - a.images)
sortedThreadIDs.push data.no for data in liveData i = 0
while data = liveData[i++]
sortedThreadIDs.push data.no
return return
}[Conf['Index Sort']]() }[Conf['Index Sort']]()
sortedThreads.push g.BOARD.threads[threadID] for threadID in sortedThreadIDs
Index.sortedThreads = sortedThreads.filter (thread) -> thread.isHidden is Index.showHiddenThreads i = 0
while threadID = sortedThreadIDs[i++]
sortedThreads.push g.BOARD.threads[threadID]
Index.sortedThreads = []
i = 0
while thread = sortedThreads[i++]
Index.sortedThreads.push thread if thread.isHidden is Index.showHiddenThreads
if Index.isSearching if Index.isSearching
Index.sortedThreads = Index.querySearch(Index.searchInput.value) or Index.sortedThreads Index.sortedThreads = Index.querySearch(Index.searchInput.value) or Index.sortedThreads
# Sticky threads # Sticky threads
@ -773,8 +793,13 @@ Index =
Index.search keywords Index.search keywords
search: (keywords) -> search: (keywords) ->
Index.sortedThreads.filter (thread) -> filtered = []
Index.searchMatch thread, keywords i = 0
{sortedThreads} = Index
while thread = sortedThreads[i++]
filtered.push thread if Index.searchMatch thread, keywords
Index.sortedThreads = filtered
searchMatch: (thread, keywords) -> searchMatch: (thread, keywords) ->
{info, file} = thread.OP {info, file} = thread.OP