From 0ea4509d3ac201da4b36dea91a543dfb0ddcece9 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 12 Mar 2016 11:05:44 -0800 Subject: [PATCH] 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. --- src/General/Header.coffee | 7 +++---- src/General/Index.coffee | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/General/Header.coffee b/src/General/Header.coffee index af8165608..d86734897 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -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 diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 34a81fe9e..cbc2e8f49 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -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