Fix minor bugs with keybinds/pageload + index.

This commit is contained in:
Mayhem 2013-11-02 14:32:54 +01:00
parent 7fd72676cb
commit a0d3694b61
2 changed files with 12 additions and 11 deletions

View File

@ -50,7 +50,7 @@ Index =
className: 'pagelist' className: 'pagelist'
hidden: true hidden: true
innerHTML: <%= importHTML('General/Index-pagelist') %> innerHTML: <%= importHTML('General/Index-pagelist') %>
Index.currentPage = +window.location.pathname.split('/')[2] Index.currentPage = Index.getCurrentPage()
$.on window, 'popstate', @cb.popstate $.on window, 'popstate', @cb.popstate
$.on @pagelist, 'click', @cb.pageNav $.on @pagelist, 'click', @cb.pageNav
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
@ -66,8 +66,8 @@ Index =
Index.sort() Index.sort()
Index.buildIndex() Index.buildIndex()
popstate: (e) -> popstate: (e) ->
Index.currentPage = +window.location.pathname.split('/')[2] pageNum = Index.getCurrentPage()
Index.pageLoad() Index.pageLoad pageNum if Index.currentPage isnt pageNum
pageNav: (e) -> pageNav: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
switch e.target.nodeName switch e.target.nodeName
@ -83,13 +83,14 @@ Index =
scrollToIndex: -> scrollToIndex: ->
Header.scrollTo Index.root if Index.root.getBoundingClientRect().top < 0 Header.scrollTo Index.root if Index.root.getBoundingClientRect().top < 0
getCurrentPage: ->
+window.location.pathname.split('/')[2]
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 0 then './' else pageNum
Index.pageLoad pageNum
pageLoad: (pageNum) ->
Index.currentPage = pageNum Index.currentPage = pageNum
Index.pageLoad()
pageLoad: ->
return unless 'currentPage' of Index # unnecessary popstate on page load
return if Conf['Index Mode'] isnt 'paged' return if Conf['Index Mode'] isnt 'paged'
Index.buildIndex() Index.buildIndex()
Index.setPage() Index.setPage()
@ -111,7 +112,7 @@ Index =
Index.setPage() Index.setPage()
Index.togglePagelist() Index.togglePagelist()
setPage: -> setPage: ->
pageNum = +window.location.pathname.split('/')[2] pageNum = Index.getCurrentPage()
pagesRoot = $ '.pages', Index.pagelist pagesRoot = $ '.pages', Index.pagelist
# Previous/Next buttons # Previous/Next buttons
prev = pagesRoot.previousSibling.firstChild prev = pagesRoot.previousSibling.firstChild
@ -246,9 +247,9 @@ Index =
return return
buildIndex: -> buildIndex: ->
if Conf['Index Mode'] is 'paged' if Conf['Index Mode'] is 'paged'
pageNum = +window.location.pathname.split('/')[2] pageNum = Index.getCurrentPage()
nodesPerPage = Index.threadsNumPerPage * 2 nodesPerPage = Index.threadsNumPerPage * 2
nodes = Index.sortedNodes.slice nodesPerPage * pageNum, nodesPerPage * (pageNum + 1) nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
else else
nodes = Index.sortedNodes nodes = Index.sortedNodes
$.event 'IndexRefresh' $.event 'IndexRefresh'

View File

@ -82,10 +82,10 @@ Keybinds =
$.open "/#{g.BOARD}/" $.open "/#{g.BOARD}/"
when Conf['Next page'] when Conf['Next page']
return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged' return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged'
$('.next a', Index.pagelist).click() $('.next button', Index.pagelist).click()
when Conf['Previous page'] when Conf['Previous page']
return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged' return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged'
$('.prev a', Index.pagelist).click() $('.prev button', Index.pagelist).click()
when Conf['Search form'] when Conf['Search form']
$.id('search-btn').click() $.id('search-btn').click()
# Thread Navigation # Thread Navigation