JSON Index: Support multiple commands in hash by separating with slashes.

Also generalize Header.hashScroll to support scrolling to last item in list
as well as scrolling to non-post elements.
This commit is contained in:
ccd0 2016-03-12 11:05:44 -08:00
parent 60a4513717
commit 0ea4509d3a
2 changed files with 15 additions and 15 deletions

View File

@ -427,10 +427,9 @@ Header =
return if e.state
history.replaceState {}, '' unless history.state
hash = @location.hash[1..]
return unless /^\d*p\d+$/.test(hash) and (post = $.id hash)
return if !post.getBoundingClientRect().height
$.queueTask -> Header.scrollTo post
hash = location.hash.match /[^#/]*$/
if (el = $.id hash) and el.offsetParent # not hidden
$.queueTask -> Header.scrollTo el
scrollTo: (root, down, needed) ->
if down

View File

@ -284,20 +284,21 @@ Index =
processHash: ->
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304
hash = location.href.match(/#.*/)?[0] or ''
command = hash[1..]
state =
replace: true
if command in ['paged', 'infinite', 'all-pages', 'catalog']
state.mode = command.replace /-/g, ' '
else if command is 'index'
state.mode = Conf['Previous Index Mode']
state.page = 1
else if /^s=/.test command
state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim()
else
state.hash = hash
commands = hash[1..].split '/'
for command, i in commands
if command in ['paged', 'infinite', 'all-pages', 'catalog']
state.mode = command.replace /-/g, ' '
else if command is 'index'
state.mode = Conf['Previous Index Mode']
state.page = 1
else if /^s=/.test command
state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim()
else if i is commands.length - 1
state.hash = if command then "##{command}" else ''
Index.pushState state
!state.hash?
hash isnt state.hash
pushState: (state) ->
{search, hash, replace} = state