Add Refreshed Navigation setting.

Close #1323, #1332.
This commit is contained in:
Mayhem 2013-12-03 11:36:43 +01:00
parent f17f9fd441
commit ceff7c5d5f
4 changed files with 34 additions and 13 deletions

View File

@ -1,5 +1,6 @@
- More index navigation improvements: - More index navigation improvements:
- New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages. - New setting: `Anchor Hidden Threads`, enabled by default. Hidden threads will be moved at the end of the index to fill the first pages.
- New setting: `Refreshed Navigation`, disabled by default. When enabled, navigating through pages will refresh the index.
### 3.14.3 - *2013-12-09* ### 3.14.3 - *2013-12-09*

View File

@ -144,6 +144,7 @@ Config =
'Index Sort': 'bump' 'Index Sort': 'bump'
'Show Replies': true 'Show Replies': true
'Anchor Hidden Threads': true 'Anchor Hidden Threads': true
'Refreshed Navigation': false
Header: Header:
'Header auto-hide': false 'Header auto-hide': false
'Header auto-hide on scroll': false 'Header auto-hide on scroll': false

View File

@ -37,10 +37,17 @@ Index =
$.on input, 'change', @cb.sort $.on input, 'change', @cb.sort
repliesEntry = repliesEntry =
el: $.el 'label', innerHTML: '<input type=checkbox name="Show Replies"> Show replies' el: $.el 'label',
innerHTML: '<input type=checkbox name="Show Replies"> Show replies'
anchorEntry = anchorEntry =
el: $.el 'label', innerHTML: '<input type=checkbox name="Anchor Hidden Threads" title="Move hidden threads at the end of the index."> Anchor hidden threads' el: $.el 'label',
for label in [repliesEntry, anchorEntry] innerHTML: '<input type=checkbox name="Anchor Hidden Threads"> Anchor hidden threads'
title: 'Move hidden threads at the end of the index.'
refNavEntry =
el: $.el 'label',
innerHTML: '<input type=checkbox name="Refreshed Navigation"> Refreshed navigation'
title: 'Refresh index when navigating through pages.'
for label in [repliesEntry, anchorEntry, refNavEntry]
input = label.el.firstChild input = label.el.firstChild
{name} = input {name} = input
input.checked = Conf[name] input.checked = Conf[name]
@ -56,7 +63,7 @@ Index =
el: $.el 'span', el: $.el 'span',
textContent: 'Index Navigation' textContent: 'Index Navigation'
order: 90 order: 90
subEntries: [modeEntry, sortEntry, repliesEntry, anchorEntry] subEntries: [modeEntry, sortEntry, repliesEntry, anchorEntry, refNavEntry]
$.addClass doc, 'index-loading' $.addClass doc, 'index-loading'
@update() @update()
@ -118,13 +125,18 @@ Index =
return return
return if a.textContent is 'Catalog' return if a.textContent is 'Catalog'
e.preventDefault() e.preventDefault()
Index.pageNav +a.pathname.split('/')[2] Index.userPageNav +a.pathname.split('/')[2]
scrollToIndex: -> scrollToIndex: ->
Header.scrollToIfNeeded Index.root Header.scrollToIfNeeded Index.root
getCurrentPage: -> getCurrentPage: ->
+window.location.pathname.split('/')[2] +window.location.pathname.split('/')[2]
userPageNav: (pageNum) ->
if Conf['Refreshed Navigation'] and Conf['Index Mode'] is 'paged'
Index.update pageNum
else
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 0 then './' else pageNum
@ -181,7 +193,7 @@ Index =
$.before a, strong $.before a, strong
$.add strong, a $.add strong, a
update: -> update: (pageNum) ->
return unless navigator.onLine return unless navigator.onLine
Index.req?.abort() Index.req?.abort()
Index.notice?.close() Index.notice?.close()
@ -196,13 +208,14 @@ Index =
return unless Index.req and !Index.notice return unless Index.req and !Index.notice
Index.notice = new Notice 'info', 'Refreshing index...' Index.notice = new Notice 'info', 'Refreshing index...'
), 5 * $.SECOND - (Date.now() - now) ), 5 * $.SECOND - (Date.now() - now)
onload = (e) -> Index.load e, pageNum
Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json",
onabort: Index.load onabort: onload
onloadend: Index.load onloadend: onload
, ,
whenModified: true whenModified: true
$.addClass Index.button, 'fa-spin' $.addClass Index.button, 'fa-spin'
load: (e) -> load: (e, pageNum) ->
$.rmClass Index.button, 'fa-spin' $.rmClass Index.button, 'fa-spin'
{req, notice} = Index {req, notice} = Index
delete Index.req delete Index.req
@ -214,7 +227,10 @@ Index =
return return
try try
Index.parse JSON.parse req.response if req.status is 200 if req.status is 200
Index.parse JSON.parse(req.response), pageNum
else if req.status is 304 and pageNum?
Index.pageNav pageNum
catch err catch err
c.error 'Index failure:', err.stack c.error 'Index failure:', err.stack
# network error or non-JSON content for example. # network error or non-JSON content for example.
@ -235,12 +251,15 @@ Index =
timeEl.dataset.utc = e.timeStamp <% if (type === 'userscript') { %>/ 1000<% } %> timeEl.dataset.utc = e.timeStamp <% if (type === 'userscript') { %>/ 1000<% } %>
RelativeDates.update timeEl RelativeDates.update timeEl
Index.scrollToIndex() Index.scrollToIndex()
parse: (pages) -> parse: (pages, pageNum) ->
Index.parseThreadList pages Index.parseThreadList pages
Index.buildThreads() Index.buildThreads()
Index.sort() Index.sort()
Index.buildIndex()
Index.buildPagelist() Index.buildPagelist()
if pageNum?
Index.pageNav pageNum
return
Index.buildIndex()
Index.setPage() Index.setPage()
parseThreadList: (pages) -> parseThreadList: (pages) ->
Index.pagesNum = pages.length Index.pagesNum = pages.length

View File

@ -75,7 +75,7 @@ Keybinds =
# Board Navigation # Board Navigation
when Conf['Front page'] when Conf['Front page']
if g.VIEW is 'index' if g.VIEW is 'index'
Index.pageNav 0 Index.userPageNav 0
else else
window.location = "/#{g.BOARD}/" window.location = "/#{g.BOARD}/"
when Conf['Open front page'] when Conf['Open front page']