From 0540dcf30f2d5c1b3170f6f708987b7fd0369963 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sat, 2 Nov 2013 00:52:12 +0100 Subject: [PATCH] Instantaneous index page navigation. Also fix page navigation keybinds. --- CHANGELOG.md | 13 ++++---- css/style.css | 3 +- html/General/Index-pagelist.html | 4 +-- src/General/Index.coffee | 50 ++++++++++++++++++++++++++----- src/Miscellaneous/Keybinds.coffee | 17 ++++++----- 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 928d719eb..bffeab527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ Index navigation improvements: - You can now refresh the index page you are on with the icon in the header bar or the same keybind for refreshing threads. - - You can now switch between single-page and all-pages navigation via the "Index Navigation" header sub-menu. + - You can now switch between paged and all-threads index modes via the "Index Navigation" header sub-menu. - Threads in the index can now be sorted by: - - bump order - - creation date - - reply count - - file count - - last reply + - Bump order + - Last reply + - Creation date + - Reply count + - File count + - Navigating across index pages is now instantaneous. Added a keybind to open the catalog search field on index pages. diff --git a/css/style.css b/css/style.css index 31f6e7d8b..751f3b772 100644 --- a/css/style.css +++ b/css/style.css @@ -364,8 +364,7 @@ a[href="javascript:;"] { /* Index */ :root.index-loading .board, -:root.index-loading .pagelist, -:root.index-hide-pagelist .pagelist { +:root.index-loading .pagelist { display: none; } diff --git a/html/General/Index-pagelist.html b/html/General/Index-pagelist.html index d8b1d7c99..e6923bb7a 100644 --- a/html/General/Index-pagelist.html +++ b/html/General/Index-pagelist.html @@ -1,11 +1,11 @@
diff --git a/src/General/Index.coffee b/src/General/Index.coffee index c930bb3d0..13eb065ab 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -2,12 +2,12 @@ Index = init: -> return if g.VIEW isnt 'index' - Index.button = $.el 'a', + @button = $.el 'a', className: 'index-refresh-shortcut fa fa-refresh' title: 'Refresh Index' href: 'javascript:;' - $.on Index.button, 'click', Index.update - Header.addShortcut Index.button, 1 + $.on @button, 'click', @update + Header.addShortcut @button, 1 modeEntry = el: $.el 'span', textContent: 'Index mode' @@ -44,11 +44,15 @@ Index = subEntries: [modeEntry, sortEntry] $.addClass doc, 'index-loading' - Index.update() - Index.root = $.el 'div', className: 'board' - Index.pagelist = $.el 'div', + @update() + @root = $.el 'div', className: 'board' + @pagelist = $.el 'div', className: 'pagelist' + hidden: true innerHTML: <%= importHTML('General/Index-pagelist') %> + Index.currentPage = +window.location.pathname.split('/')[2] + $.on window, 'popstate', @cb.popstate + $.on @pagelist, 'click', @cb.pageNav $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> $.replace $('.board'), Index.root $.replace $('.pagelist'), Index.pagelist @@ -61,9 +65,38 @@ Index = sort: -> Index.sort() Index.buildIndex() + popstate: (e) -> + Index.currentPage = +window.location.pathname.split('/')[2] + Index.pageLoad() + pageNav: (e) -> + return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 + switch e.target.nodeName + when 'BUTTON' + a = e.target.parentNode + when 'A' + a = e.target + else + return + e.preventDefault() + Index.pageNav +a.pathname.split('/')[2] + + scrollToIndex: -> + Header.scrollTo Index.root if Index.root.getBoundingClientRect().top < 0 + + pageNav: (pageNum) -> + return if Index.currentPage is pageNum + history.pushState null, '', if pageNum is 0 then './' else pageNum + Index.currentPage = pageNum + Index.pageLoad() + pageLoad: -> + return unless 'currentPage' of Index # unnecessary popstate on page load + return if Conf['Index Mode'] isnt 'paged' + Index.buildIndex() + Index.setPage() + Index.scrollToIndex() togglePagelist: -> - (if Conf['Index Mode'] is 'paged' then $.rmClass else $.addClass) doc, 'index-hide-pagelist' + Index.pagelist.hidden = Conf['Index Mode'] isnt 'paged' buildPagelist: -> pagesRoot = $ '.pages', Index.pagelist if pagesRoot.childElementCount isnt Index.pagesNum @@ -76,6 +109,7 @@ Index = $.rmAll pagesRoot $.add pagesRoot, nodes Index.setPage() + Index.togglePagelist() setPage: -> pageNum = +window.location.pathname.split('/')[2] pagesRoot = $ '.pages', Index.pagelist @@ -134,7 +168,7 @@ Index = notice.el.lastElementChild.textContent = 'Index refreshed!' setTimeout notice.close, $.SECOND - Header.scrollTo Index.root if Index.root.getBoundingClientRect().top < 0 + Index.scrollToIndex() parse: (pages) -> Index.parseThreadList pages Index.buildAll() diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index c5fb5d59a..7ad88b273 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -74,17 +74,18 @@ Keybinds = Keybinds.img threadRoot, true # Board Navigation when Conf['Front page'] - window.location = "/#{g.BOARD}/0#delform" + if g.VIEW is 'index' + Index.pageNav 0 + else + window.location = "/#{g.BOARD}/" when Conf['Open front page'] - $.open "/#{g.BOARD}/#delform" + $.open "/#{g.BOARD}/" when Conf['Next page'] - return if Conf['Index Mode'] isnt 'paged' - if form = $ '.next form' - window.location = form.action + return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged' + $('.next a', Index.pagelist).click() when Conf['Previous page'] - return if Conf['Index Mode'] isnt 'paged' - if form = $ '.prev form' - window.location = form.action + return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged' + $('.prev a', Index.pagelist).click() when Conf['Search form'] $.id('search-btn').click() # Thread Navigation