Better handling of scrolling to hash in JSON index.

This commit is contained in:
ccd0 2016-03-12 16:32:16 -08:00
parent 8a15dfdbce
commit e8cce848e7
2 changed files with 24 additions and 14 deletions

View File

@ -423,15 +423,16 @@ Header =
$('[name=boardnav]', settings).focus() $('[name=boardnav]', settings).focus()
hashScroll: (e) -> hashScroll: (e) ->
# Don't scroll when navigating to an already visited state. if e
return if e.state # Don't scroll when navigating to an already visited state.
history.replaceState {}, '' unless history.state return if e.state
history.replaceState {}, '' unless history.state
hash = location.hash.match /[^#/]*$/ if (hash = location.hash[1..]) and (el = $.id hash)
if (el = $.id hash) and el.offsetParent # not hidden
$.queueTask -> Header.scrollTo el $.queueTask -> Header.scrollTo el
scrollTo: (root, down, needed) -> scrollTo: (root, down, needed) ->
return unless root.offsetParent # hidden or fixed
if down if down
x = Header.getBottomOf root x = Header.getBottomOf root
if Conf['Fixed Header'] and Conf['Header auto-hide on scroll'] and Conf['Bottom header'] if Conf['Fixed Header'] and Conf['Header auto-hide on scroll'] and Conf['Bottom header']

View File

@ -246,8 +246,11 @@ Index =
Index.pageLoad false Index.pageLoad false
else else
# page load or hash change # page load or hash change
if Index.processHash() nCommands = Index.processHash()
Index[if Conf['Refreshed Navigation'] then 'update' else 'pageLoad']() if Conf['Refreshed Navigation'] and nCommands
Index.update()
else
Index.pageLoad()
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
@ -302,7 +305,8 @@ Index =
state = state =
replace: true replace: true
commands = hash[1..].split '/' commands = hash[1..].split '/'
for command, i in commands leftover = []
for command in commands
if (mode = Index.hashCommands.mode[command]) if (mode = Index.hashCommands.mode[command])
state.mode = mode state.mode = mode
else if command is 'index' else if command is 'index'
@ -312,10 +316,12 @@ Index =
state.sort = sort state.sort = sort
else if /^s=/.test command else if /^s=/.test command
state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim()
else if i is commands.length - 1 else
state.hash = if command then "##{command}" else '' leftover.push command
hash = leftover.join '/'
state.hash = "##{hash}" if hash
Index.pushState state Index.pushState state
hash isnt state.hash commands.length - leftover.length
pushState: (state) -> pushState: (state) ->
{search, hash, replace} = state {search, hash, replace} = state
@ -336,7 +342,7 @@ Index =
oldpage: pageBeforeSearch oldpage: pageBeforeSearch
, '', "#{location.protocol}//#{location.host}#{pathname}#{hash}" , '', "#{location.protocol}//#{location.host}#{pathname}#{hash}"
setState: ({search, mode, sort, page}) -> setState: ({search, mode, sort, page, hash}) ->
if search? and search isnt Index.search if search? and search isnt Index.search
Index.changed.search = true Index.changed.search = true
Index.search = search Index.search = search
@ -355,10 +361,12 @@ Index =
if page? and page isnt Index.currentPage if page? and page isnt Index.currentPage
Index.changed.page = true Index.changed.page = true
Index.currentPage = page Index.currentPage = page
if hash?
Index.changed.hash = true
pageLoad: (scroll=true) -> pageLoad: (scroll=true) ->
return unless Index.liveThreadData return unless Index.liveThreadData
{threads, search, mode, sort, page} = Index.changed {threads, search, mode, sort, page, hash} = Index.changed
Index.sort() if threads or search or sort Index.sort() if threads or search or sort
Index.buildPagelist() if threads or search Index.buildPagelist() if threads or search
Index.setupSearch() if search Index.setupSearch() if search
@ -366,7 +374,8 @@ Index =
Index.setupSort() if sort Index.setupSort() if sort
Index.buildIndex() if threads or search or mode or page or sort Index.buildIndex() if threads or search or mode or page or sort
Index.setPage() if threads or search or mode or page Index.setPage() if threads or search or mode or page
Index.scrollToIndex() if scroll Index.scrollToIndex() if scroll and not hash
Header.hashScroll() if hash
Index.changed = {} Index.changed = {}
setupMode: -> setupMode: ->