Always use generated pathname and hash; consolidate some code.
This commit is contained in:
parent
1540e0f3ed
commit
0c78647b92
@ -236,16 +236,8 @@ Index =
|
|||||||
popstate: (e) ->
|
popstate: (e) ->
|
||||||
if e?.state
|
if e?.state
|
||||||
{search, mode} = e.state
|
{search, mode} = e.state
|
||||||
if Index.search isnt search
|
|
||||||
Index.changed.search = true
|
|
||||||
Index.search = search
|
|
||||||
if Conf['Index Mode'] isnt mode
|
|
||||||
Index.changed.mode = true
|
|
||||||
Index.saveMode mode
|
|
||||||
page = Index.getCurrentPage()
|
page = Index.getCurrentPage()
|
||||||
if Index.currentPage isnt page
|
Index.setState {search, mode, page}
|
||||||
Index.changed.page = true
|
|
||||||
Index.currentPage = page
|
|
||||||
Index.pageLoad false
|
Index.pageLoad false
|
||||||
else
|
else
|
||||||
# page load or hash change
|
# page load or hash change
|
||||||
@ -274,10 +266,7 @@ Index =
|
|||||||
Header.scrollToIfNeeded Index.navLinks
|
Header.scrollToIfNeeded Index.navLinks
|
||||||
|
|
||||||
getCurrentPage: ->
|
getCurrentPage: ->
|
||||||
if Conf['Index Mode'] in ['all pages', 'catalog']
|
+window.location.pathname.split('/')[2] or 1
|
||||||
1
|
|
||||||
else
|
|
||||||
+window.location.pathname.split('/')[2] or 1
|
|
||||||
|
|
||||||
userPageNav: (page) ->
|
userPageNav: (page) ->
|
||||||
Index.pushState {page}
|
Index.pushState {page}
|
||||||
@ -288,10 +277,10 @@ Index =
|
|||||||
|
|
||||||
processHash: ->
|
processHash: ->
|
||||||
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304
|
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304
|
||||||
command = location.href.match(/#(.*)/)?[1]
|
hash = location.href.match(/#.*/)?[0] or ''
|
||||||
|
command = hash[1..]
|
||||||
state =
|
state =
|
||||||
replace: true
|
replace: true
|
||||||
hash: ''
|
|
||||||
if command in ['paged', 'infinite', 'all-pages', 'catalog']
|
if command in ['paged', 'infinite', 'all-pages', 'catalog']
|
||||||
state.mode = command.replace /-/g, ' '
|
state.mode = command.replace /-/g, ' '
|
||||||
else if command is 'index'
|
else if command is 'index'
|
||||||
@ -300,45 +289,43 @@ Index =
|
|||||||
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
|
else
|
||||||
delete state.hash
|
state.hash = hash
|
||||||
Index.pushState state
|
Index.pushState state
|
||||||
state.hash is ''
|
!state.hash?
|
||||||
|
|
||||||
pushState: ({search, mode, page, hash, replace}) ->
|
pushState: (state) ->
|
||||||
|
{search, hash, replace} = state
|
||||||
pageBeforeSearch = history.state?.oldpage
|
pageBeforeSearch = history.state?.oldpage
|
||||||
if search?
|
if search? and search isnt Index.search
|
||||||
Index.changed.search = true
|
state.page = if search then 1 else (pageBeforeSearch or 1)
|
||||||
page = if search then 1 else (pageBeforeSearch or 1)
|
|
||||||
if !search
|
if !search
|
||||||
pageBeforeSearch = undefined
|
pageBeforeSearch = undefined
|
||||||
else if !Index.search
|
else if !Index.search
|
||||||
pageBeforeSearch = Index.currentPage
|
pageBeforeSearch = Index.currentPage
|
||||||
Index.search = search
|
Index.setState state
|
||||||
if mode?
|
pathname = if Index.currentPage is 1 then "/#{g.BOARD}/" else "/#{g.BOARD}/#{Index.currentPage}"
|
||||||
Index.changed.mode = true unless mode is Conf['Index Mode']
|
hash or= ''
|
||||||
Index.saveMode mode
|
|
||||||
page = 1 if mode in ['all pages', 'catalog']
|
|
||||||
hash ?= ''
|
|
||||||
if page?
|
|
||||||
Index.changed.page = true unless page is Index.currentPage
|
|
||||||
Index.currentPage = page
|
|
||||||
pathname = if page is 1 then "/#{g.BOARD}/" else "/#{g.BOARD}/#{page}"
|
|
||||||
hash ?= ''
|
|
||||||
pathname ?= location.pathname
|
|
||||||
hash ?= location.hash
|
|
||||||
history[if replace then 'replaceState' else 'pushState']
|
history[if replace then 'replaceState' else 'pushState']
|
||||||
mode: Conf['Index Mode']
|
mode: Conf['Index Mode']
|
||||||
search: Index.search
|
search: Index.search
|
||||||
oldpage: pageBeforeSearch
|
oldpage: pageBeforeSearch
|
||||||
, '', pathname + hash
|
, '', pathname + hash
|
||||||
|
|
||||||
saveMode: (mode) ->
|
setState: ({search, mode, page}) ->
|
||||||
unless Conf['Index Mode'] is mode
|
if search? and search isnt Index.search
|
||||||
|
Index.changed.search = true
|
||||||
|
Index.search = search
|
||||||
|
if mode? and mode isnt Conf['Index Mode']
|
||||||
|
Index.changed.mode = true
|
||||||
Conf['Index Mode'] = mode
|
Conf['Index Mode'] = mode
|
||||||
$.set 'Index Mode', mode
|
$.set 'Index Mode', mode
|
||||||
unless mode is 'catalog' or Conf['Previous Index Mode'] is mode
|
unless mode is 'catalog' or Conf['Previous Index Mode'] is mode
|
||||||
Conf['Previous Index Mode'] = mode
|
Conf['Previous Index Mode'] = mode
|
||||||
$.set 'Previous Index Mode', mode
|
$.set 'Previous Index Mode', mode
|
||||||
|
page = 1 if Conf['Index Mode'] in ['all pages', 'catalog']
|
||||||
|
if page? and page isnt Index.currentPage
|
||||||
|
Index.changed.page = true
|
||||||
|
Index.currentPage = page
|
||||||
|
|
||||||
pageLoad: (scroll=true) ->
|
pageLoad: (scroll=true) ->
|
||||||
{threads, search, mode, page} = Index.changed
|
{threads, search, mode, page} = Index.changed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user