update page numbering in Index.coffee

This commit is contained in:
ccd0 2014-04-12 12:02:28 -07:00
parent 8a5cd7a610
commit b6e5d206f1

View File

@ -117,7 +117,7 @@ Index =
Index.pageNum = Index.getCurrentPage() unless Index.pageNum? # Avoid having to pushState to keep track of the current page Index.pageNum = Index.getCurrentPage() unless Index.pageNum? # Avoid having to pushState to keep track of the current page
pageNum = Index.pageNum++ pageNum = Index.pageNum++
return Index.endNotice() if pageNum >= Index.pagesNum return Index.endNotice() if pageNum > Index.pagesNum
nodes = Index.buildSinglePage pageNum nodes = Index.buildSinglePage pageNum
Index.buildReplies nodes if Conf['Show Replies'] Index.buildReplies nodes if Conf['Show Replies']
@ -161,7 +161,7 @@ Index =
Header.scrollToIfNeeded Index.root Header.scrollToIfNeeded Index.root
getCurrentPage: -> getCurrentPage: ->
+window.location.pathname.split('/')[2] +window.location.pathname.split('/')[2] or 1
userPageNav: (pageNum) -> userPageNav: (pageNum) ->
if Conf['Refreshed Navigation'] and Conf['Index Mode'] isnt 'all pages' if Conf['Refreshed Navigation'] and Conf['Index Mode'] isnt 'all pages'
Index.update pageNum Index.update pageNum
@ -169,7 +169,7 @@ Index =
Index.pageNav pageNum Index.pageNav pageNum
pageNav: (pageNum) -> pageNav: (pageNum) ->
return if Index.currentPage is pageNum return if Index.currentPage is pageNum
history.pushState null, '', if pageNum is 0 then './' else pageNum history.pushState null, '', if pageNum is 1 then './' else pageNum
Index.pageLoad pageNum Index.pageLoad pageNum
pageLoad: (pageNum) -> pageLoad: (pageNum) ->
Index.currentPage = pageNum Index.currentPage = pageNum
@ -184,15 +184,15 @@ Index =
else else
Index.pagesNum Index.pagesNum
getMaxPageNum: -> getMaxPageNum: ->
Math.max 0, Index.getPagesNum() - 1 Math.max 1, Index.getPagesNum()
togglePagelist: -> togglePagelist: ->
Index.pagelist.hidden = Conf['Index Mode'] isnt 'paged' Index.pagelist.hidden = Conf['Index Mode'] isnt 'paged'
buildPagelist: -> buildPagelist: ->
pagesRoot = $ '.pages', Index.pagelist pagesRoot = $ '.pages', Index.pagelist
maxPageNum = Index.getMaxPageNum() maxPageNum = Index.getMaxPageNum()
if pagesRoot.childElementCount isnt maxPageNum + 1 if pagesRoot.childElementCount isnt maxPageNum
nodes = [] nodes = []
for i in [0..maxPageNum] by 1 for i in [1..maxPageNum] by 1
a = $.el 'a', a = $.el 'a',
textContent: i textContent: i
href: if i then i else './' href: if i then i else './'
@ -207,11 +207,11 @@ Index =
# Previous/Next buttons # Previous/Next buttons
prev = pagesRoot.previousSibling.firstChild prev = pagesRoot.previousSibling.firstChild
next = pagesRoot.nextSibling.firstChild next = pagesRoot.nextSibling.firstChild
href = Math.max pageNum - 1, 0 href = Math.max pageNum - 1, 1
prev.href = if href is 0 then './' else href prev.href = if href is 1 then './' else href
prev.firstChild.disabled = href is pageNum prev.firstChild.disabled = href is pageNum
href = Math.min pageNum + 1, maxPageNum href = Math.min pageNum + 1, maxPageNum
next.href = if href is 0 then './' else href next.href = if href is 1 then './' else href
next.firstChild.disabled = href is pageNum next.firstChild.disabled = href is pageNum
# <strong> current page # <strong> current page
if strong = $ 'strong', pagesRoot if strong = $ 'strong', pagesRoot
@ -442,7 +442,7 @@ Index =
buildSinglePage: (pageNum) -> buildSinglePage: (pageNum) ->
nodes = [] nodes = []
nodesPerPage = Index.threadsNumPerPage nodesPerPage = Index.threadsNumPerPage
offset = nodesPerPage * pageNum offset = nodesPerPage * (pageNum - 1)
end = offset + nodesPerPage end = offset + nodesPerPage
target = Index.sortedNodes.order()[offset] target = Index.sortedNodes.order()[offset]
Index.sortedNodes Index.sortedNodes
@ -471,7 +471,7 @@ 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 pageNum = 1
else else
pageNum = Index.getCurrentPage() pageNum = Index.getCurrentPage()
else else