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

View File

@ -151,9 +151,9 @@ Index =
scroll: ->
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
@ -399,8 +399,8 @@ Index =
Header.scrollToIfNeeded Index.navLinks
getCurrentPage: ->
if Conf['Index Mode'] is 'infinite' and Index.pageNum
return Index.pageNum
if Conf['Index Mode'] is 'infinite' and Index.currentPage
return Index.currentPage
+window.location.pathname.split('/')[2]
userPageNav: (pageNum) ->
@ -449,9 +449,8 @@ Index =
$.add pagesRoot, nodes
Index.togglePagelist()
setPage: (pageNum) ->
pageNum or= Index.getCurrentPage()
Index.pageNum = pageNum
setPage: (pageNum = Index.getCurrentPage()) ->
Index.currentPage = pageNum
maxPageNum = Index.getMaxPageNum()
pagesRoot = $ '.pages', Index.pagelist
# Previous/Next buttons
@ -494,7 +493,7 @@ Index =
return
unless d.readyState is 'loading' or Index.root.parentElement
$.replace $('.board'), Index.root
delete Index.pageNum
Index.currentPage = 0
Index.req?.abort()
Index.notice?.close()
@ -737,18 +736,12 @@ Index =
buildIndex: (infinite) ->
{sortedThreads} = Index
nodes = []
switch Conf['Index Mode']
when 'paged', 'infinite'
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()
nodes = []
threads = []
i = threadsPerPage * pageNum
max = i + threadsPerPage
@ -764,8 +757,7 @@ Index =
nodes = Index.buildCatalogViews()
else
nodes = []
i = 0
i = 0
while thread = sortedThreads[i++]
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
Index.buildReplies thread
@ -786,9 +778,11 @@ Index =
unless Index.searchInput.dataset.searching
Index.searchInput.dataset.searching = 1
Index.pageBeforeSearch = Index.getCurrentPage()
pageNum = 0
Index.setPage pageNum = 0
else
pageNum = Index.getCurrentPage()
unless Conf['Index Mode'] is 'infinite'
pageNum = Index.getCurrentPage()
else
return unless Index.searchInput.dataset.searching
pageNum = Index.pageBeforeSearch
@ -818,7 +812,6 @@ Index =
while thread = sortedThreads[i++]
filtered.push thread if Index.searchMatch thread, keywords
Index.sortedThreads = filtered
searchMatch: (thread, keywords) ->
{info, file} = thread.OP