Sort that shit, yo

This commit is contained in:
Zixaphir 2014-04-06 21:58:12 -07:00
parent 46f29fd094
commit 23cc92d7cc
3 changed files with 41 additions and 56 deletions

View File

@ -2715,8 +2715,8 @@
if (Index.req || Conf['Index Mode'] !== 'infinite' || (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') { if (Index.req || Conf['Index Mode'] !== 'infinite' || (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') {
return; return;
} }
Index.pageNum = (Index.pageNum || Index.getCurrentPage()) + 1; Index.currentPage = (Index.currentPage || Index.getCurrentPage()) + 1;
if (Index.pageNum >= Index.pagesNum) { if (Index.currentPage >= Index.pagesNum) {
return Index.endNotice(); return Index.endNotice();
} }
return Index.buildIndex(true); return Index.buildIndex(true);
@ -3055,8 +3055,8 @@
return Header.scrollToIfNeeded(Index.navLinks); return Header.scrollToIfNeeded(Index.navLinks);
}, },
getCurrentPage: function() { getCurrentPage: function() {
if (Conf['Index Mode'] === 'infinite' && Index.pageNum) { if (Conf['Index Mode'] === 'infinite' && Index.currentPage) {
return Index.pageNum; return Index.currentPage;
} }
return +window.location.pathname.split('/')[2]; return +window.location.pathname.split('/')[2];
}, },
@ -3118,8 +3118,10 @@
}, },
setPage: function(pageNum) { setPage: function(pageNum) {
var a, href, maxPageNum, next, pagesRoot, prev, strong; var a, href, maxPageNum, next, pagesRoot, prev, strong;
pageNum || (pageNum = Index.getCurrentPage()); if (pageNum == null) {
Index.pageNum = pageNum; pageNum = Index.getCurrentPage();
}
Index.currentPage = pageNum;
maxPageNum = Index.getMaxPageNum(); maxPageNum = Index.getMaxPageNum();
pagesRoot = $('.pages', Index.pagelist); pagesRoot = $('.pages', Index.pagelist);
prev = pagesRoot.previousSibling.firstChild; prev = pagesRoot.previousSibling.firstChild;
@ -3180,7 +3182,7 @@
if (!(d.readyState === 'loading' || Index.root.parentElement)) { if (!(d.readyState === 'loading' || Index.root.parentElement)) {
$.replace($('.board'), Index.root); $.replace($('.board'), Index.root);
} }
delete Index.pageNum; Index.currentPage = 0;
if ((_ref = Index.req) != null) { if ((_ref = Index.req) != null) {
_ref.abort(); _ref.abort();
} }
@ -3498,19 +3500,12 @@
buildIndex: function(infinite) { buildIndex: function(infinite) {
var i, max, nodes, pageNum, sortedThreads, thread, threads, threadsPerPage; var i, max, nodes, pageNum, sortedThreads, thread, threads, threadsPerPage;
sortedThreads = Index.sortedThreads; sortedThreads = Index.sortedThreads;
nodes = [];
switch (Conf['Index Mode']) { switch (Conf['Index Mode']) {
case 'paged': case 'paged':
case 'infinite': case 'infinite':
pageNum = Index.getCurrentPage(); pageNum = Index.getCurrentPage();
if (Index.isSearching) {
Index.setPage(pageNum = 0);
}
if (pageNum > Index.getMaxPageNum()) {
Index.pageNav(Index.getMaxPageNum());
return;
}
threadsPerPage = Index.getThreadsNumPerPage(); threadsPerPage = Index.getThreadsNumPerPage();
nodes = [];
threads = []; threads = [];
i = threadsPerPage * pageNum; i = threadsPerPage * pageNum;
max = i + threadsPerPage; max = i + threadsPerPage;
@ -3526,7 +3521,6 @@
nodes = Index.buildCatalogViews(); nodes = Index.buildCatalogViews();
break; break;
default: default:
nodes = [];
i = 0; i = 0;
while (thread = sortedThreads[i++]) { while (thread = sortedThreads[i++]) {
nodes.push(thread.OP.nodes.root.parentNode, $.el('hr')); nodes.push(thread.OP.nodes.root.parentNode, $.el('hr'));
@ -3551,9 +3545,11 @@
if (!Index.searchInput.dataset.searching) { if (!Index.searchInput.dataset.searching) {
Index.searchInput.dataset.searching = 1; Index.searchInput.dataset.searching = 1;
Index.pageBeforeSearch = Index.getCurrentPage(); Index.pageBeforeSearch = Index.getCurrentPage();
pageNum = 0; Index.setPage(pageNum = 0);
} else { } else {
pageNum = Index.getCurrentPage(); if (Conf['Index Mode'] !== 'infinite') {
pageNum = Index.getCurrentPage();
}
} }
} else { } else {
if (!Index.searchInput.dataset.searching) { if (!Index.searchInput.dataset.searching) {

View File

@ -2776,8 +2776,8 @@
if (Index.req || Conf['Index Mode'] !== 'infinite' || (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') { if (Index.req || Conf['Index Mode'] !== 'infinite' || (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') {
return; return;
} }
Index.pageNum = (Index.pageNum || Index.getCurrentPage()) + 1; Index.currentPage = (Index.currentPage || Index.getCurrentPage()) + 1;
if (Index.pageNum >= Index.pagesNum) { if (Index.currentPage >= Index.pagesNum) {
return Index.endNotice(); return Index.endNotice();
} }
return Index.buildIndex(true); return Index.buildIndex(true);
@ -3116,8 +3116,8 @@
return Header.scrollToIfNeeded(Index.navLinks); return Header.scrollToIfNeeded(Index.navLinks);
}, },
getCurrentPage: function() { getCurrentPage: function() {
if (Conf['Index Mode'] === 'infinite' && Index.pageNum) { if (Conf['Index Mode'] === 'infinite' && Index.currentPage) {
return Index.pageNum; return Index.currentPage;
} }
return +window.location.pathname.split('/')[2]; return +window.location.pathname.split('/')[2];
}, },
@ -3179,8 +3179,10 @@
}, },
setPage: function(pageNum) { setPage: function(pageNum) {
var a, href, maxPageNum, next, pagesRoot, prev, strong; var a, href, maxPageNum, next, pagesRoot, prev, strong;
pageNum || (pageNum = Index.getCurrentPage()); if (pageNum == null) {
Index.pageNum = pageNum; pageNum = Index.getCurrentPage();
}
Index.currentPage = pageNum;
maxPageNum = Index.getMaxPageNum(); maxPageNum = Index.getMaxPageNum();
pagesRoot = $('.pages', Index.pagelist); pagesRoot = $('.pages', Index.pagelist);
prev = pagesRoot.previousSibling.firstChild; prev = pagesRoot.previousSibling.firstChild;
@ -3241,7 +3243,7 @@
if (!(d.readyState === 'loading' || Index.root.parentElement)) { if (!(d.readyState === 'loading' || Index.root.parentElement)) {
$.replace($('.board'), Index.root); $.replace($('.board'), Index.root);
} }
delete Index.pageNum; Index.currentPage = 0;
if ((_ref = Index.req) != null) { if ((_ref = Index.req) != null) {
_ref.abort(); _ref.abort();
} }
@ -3559,19 +3561,12 @@
buildIndex: function(infinite) { buildIndex: function(infinite) {
var i, max, nodes, pageNum, sortedThreads, thread, threads, threadsPerPage; var i, max, nodes, pageNum, sortedThreads, thread, threads, threadsPerPage;
sortedThreads = Index.sortedThreads; sortedThreads = Index.sortedThreads;
nodes = [];
switch (Conf['Index Mode']) { switch (Conf['Index Mode']) {
case 'paged': case 'paged':
case 'infinite': case 'infinite':
pageNum = Index.getCurrentPage(); pageNum = Index.getCurrentPage();
if (Index.isSearching) {
Index.setPage(pageNum = 0);
}
if (pageNum > Index.getMaxPageNum()) {
Index.pageNav(Index.getMaxPageNum());
return;
}
threadsPerPage = Index.getThreadsNumPerPage(); threadsPerPage = Index.getThreadsNumPerPage();
nodes = [];
threads = []; threads = [];
i = threadsPerPage * pageNum; i = threadsPerPage * pageNum;
max = i + threadsPerPage; max = i + threadsPerPage;
@ -3587,7 +3582,6 @@
nodes = Index.buildCatalogViews(); nodes = Index.buildCatalogViews();
break; break;
default: default:
nodes = [];
i = 0; i = 0;
while (thread = sortedThreads[i++]) { while (thread = sortedThreads[i++]) {
nodes.push(thread.OP.nodes.root.parentNode, $.el('hr')); nodes.push(thread.OP.nodes.root.parentNode, $.el('hr'));
@ -3612,9 +3606,11 @@
if (!Index.searchInput.dataset.searching) { if (!Index.searchInput.dataset.searching) {
Index.searchInput.dataset.searching = 1; Index.searchInput.dataset.searching = 1;
Index.pageBeforeSearch = Index.getCurrentPage(); Index.pageBeforeSearch = Index.getCurrentPage();
pageNum = 0; Index.setPage(pageNum = 0);
} else { } else {
pageNum = Index.getCurrentPage(); if (Conf['Index Mode'] !== 'infinite') {
pageNum = Index.getCurrentPage();
}
} }
} else { } else {
if (!Index.searchInput.dataset.searching) { if (!Index.searchInput.dataset.searching) {

View File

@ -151,9 +151,9 @@ Index =
scroll: -> scroll: ->
return if Index.req or Conf['Index Mode'] isnt 'infinite' or (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) or g.VIEW is 'thread' return if Index.req or Conf['Index Mode'] isnt 'infinite' or (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) or g.VIEW is 'thread'
Index.pageNum = (Index.pageNum or Index.getCurrentPage()) + 1 # Avoid having to pushState to keep track of the current page Index.currentPage = (Index.currentPage or Index.getCurrentPage()) + 1 # Avoid having to pushState to keep track of the current page
return Index.endNotice() if Index.pageNum >= Index.pagesNum return Index.endNotice() if Index.currentPage >= Index.pagesNum
Index.buildIndex true Index.buildIndex true
@ -399,8 +399,8 @@ Index =
Header.scrollToIfNeeded Index.navLinks Header.scrollToIfNeeded Index.navLinks
getCurrentPage: -> getCurrentPage: ->
if Conf['Index Mode'] is 'infinite' and Index.pageNum if Conf['Index Mode'] is 'infinite' and Index.currentPage
return Index.pageNum return Index.currentPage
+window.location.pathname.split('/')[2] +window.location.pathname.split('/')[2]
userPageNav: (pageNum) -> userPageNav: (pageNum) ->
@ -449,9 +449,8 @@ Index =
$.add pagesRoot, nodes $.add pagesRoot, nodes
Index.togglePagelist() Index.togglePagelist()
setPage: (pageNum) -> setPage: (pageNum = Index.getCurrentPage()) ->
pageNum or= Index.getCurrentPage() Index.currentPage = pageNum
Index.pageNum = pageNum
maxPageNum = Index.getMaxPageNum() maxPageNum = Index.getMaxPageNum()
pagesRoot = $ '.pages', Index.pagelist pagesRoot = $ '.pages', Index.pagelist
# Previous/Next buttons # Previous/Next buttons
@ -494,7 +493,7 @@ Index =
return return
unless d.readyState is 'loading' or Index.root.parentElement unless d.readyState is 'loading' or Index.root.parentElement
$.replace $('.board'), Index.root $.replace $('.board'), Index.root
delete Index.pageNum Index.currentPage = 0
Index.req?.abort() Index.req?.abort()
Index.notice?.close() Index.notice?.close()
@ -737,18 +736,12 @@ Index =
buildIndex: (infinite) -> buildIndex: (infinite) ->
{sortedThreads} = Index {sortedThreads} = Index
nodes = []
switch Conf['Index Mode'] switch Conf['Index Mode']
when 'paged', 'infinite' when 'paged', 'infinite'
pageNum = Index.getCurrentPage() pageNum = Index.getCurrentPage()
if Index.isSearching
Index.setPage pageNum = 0
if pageNum > Index.getMaxPageNum()
# Go to the last available page if we were past the limit.
Index.pageNav Index.getMaxPageNum()
return
threadsPerPage = Index.getThreadsNumPerPage() threadsPerPage = Index.getThreadsNumPerPage()
nodes = []
threads = [] threads = []
i = threadsPerPage * pageNum i = threadsPerPage * pageNum
max = i + threadsPerPage max = i + threadsPerPage
@ -764,8 +757,7 @@ Index =
nodes = Index.buildCatalogViews() nodes = Index.buildCatalogViews()
else else
nodes = [] i = 0
i = 0
while thread = sortedThreads[i++] while thread = sortedThreads[i++]
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr' nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
Index.buildReplies thread Index.buildReplies thread
@ -786,9 +778,11 @@ Index =
unless Index.searchInput.dataset.searching unless Index.searchInput.dataset.searching
Index.searchInput.dataset.searching = 1 Index.searchInput.dataset.searching = 1
Index.pageBeforeSearch = Index.getCurrentPage() Index.pageBeforeSearch = Index.getCurrentPage()
pageNum = 0 Index.setPage pageNum = 0
else else
pageNum = Index.getCurrentPage() unless Conf['Index Mode'] is 'infinite'
pageNum = Index.getCurrentPage()
else else
return unless Index.searchInput.dataset.searching return unless Index.searchInput.dataset.searching
pageNum = Index.pageBeforeSearch pageNum = Index.pageBeforeSearch
@ -819,7 +813,6 @@ Index =
filtered.push thread if Index.searchMatch thread, keywords filtered.push thread if Index.searchMatch thread, keywords
Index.sortedThreads = filtered Index.sortedThreads = filtered
searchMatch: (thread, keywords) -> searchMatch: (thread, keywords) ->
{info, file} = thread.OP {info, file} = thread.OP
text = [] text = []