Navigate.coffee refactoring
from commit a0c24fd06dc14e55908ea1531a8e967713131a7c Fix some stupid threadupdater issues, more navigate from catalog js
This commit is contained in:
parent
ee4ad9b86e
commit
1e682f9306
@ -3,7 +3,7 @@ Navigate =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' or !Conf['JSON Navigation']
|
return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' or !Conf['JSON Navigation']
|
||||||
|
|
||||||
$.ready ->
|
$.ready ->
|
||||||
# blink/webkit throw a popstate on page load. Not what we want.
|
# blink/webkit throw a popstate on page load. Not what we want.
|
||||||
$.on window, 'popstate', Navigate.popstate
|
$.on window, 'popstate', Navigate.popstate
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ Navigate =
|
|||||||
g.threads.forEach (thread) -> thread.collect()
|
g.threads.forEach (thread) -> thread.collect()
|
||||||
QuoteBacklink.containers = {}
|
QuoteBacklink.containers = {}
|
||||||
|
|
||||||
$.rmAll $('.board')
|
$.rmAll $ '.board'
|
||||||
|
|
||||||
features: [
|
features: [
|
||||||
['Thread Excerpt', ThreadExcerpt]
|
['Thread Excerpt', ThreadExcerpt]
|
||||||
@ -150,10 +150,10 @@ Navigate =
|
|||||||
style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b"
|
style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b"
|
||||||
return ["#{type}_style", (if style then style[1] else base)]
|
return ["#{type}_style", (if style then style[1] else base)]
|
||||||
|
|
||||||
style = findStyle (if sfw
|
style = if sfw
|
||||||
['ws', 'Yotsuba B New']
|
findStyle 'ws', 'Yotsuba B New'
|
||||||
else
|
else
|
||||||
['nws', 'Yotsuba New'])...
|
findStyle 'nws', 'Yotsuba New'
|
||||||
|
|
||||||
$.globalEval "var style_group = '#{style[0]}'"
|
$.globalEval "var style_group = '#{style[0]}'"
|
||||||
|
|
||||||
@ -166,20 +166,19 @@ Navigate =
|
|||||||
$('.boardTitle').textContent = d.title = "/#{board}/ - #{title}"
|
$('.boardTitle').textContent = d.title = "/#{board}/ - #{title}"
|
||||||
|
|
||||||
navigate: (e) ->
|
navigate: (e) ->
|
||||||
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org' or
|
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
||||||
(e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0))) # Not simply a left click
|
return if e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0)) # Not simply a left click
|
||||||
|
|
||||||
$.addClass Index.button, 'fa-spin'
|
$.addClass Index.button, 'fa-spin'
|
||||||
|
|
||||||
path = @pathname.split '/'
|
[_, boardID, view, threadID] = @pathname.split '/'
|
||||||
path.shift() if path[0] is ''
|
|
||||||
[boardID, view, threadID] = path
|
|
||||||
|
|
||||||
return if view is 'catalog' or 'f' in [boardID, g.BOARD.ID]
|
return if view is 'catalog' or 'f' in [boardID, g.BOARD.ID]
|
||||||
e.preventDefault() if e
|
e.preventDefault() if e
|
||||||
Navigate.title = -> return
|
Navigate.title = -> return
|
||||||
|
|
||||||
delete Index.pageNum
|
delete Index.pageNum
|
||||||
|
$.rmAll Header.hover
|
||||||
|
|
||||||
path = @pathname
|
path = @pathname
|
||||||
path += @hash if @hash
|
path += @hash if @hash
|
||||||
@ -195,6 +194,7 @@ Navigate =
|
|||||||
|
|
||||||
if view is g.VIEW and boardID is g.BOARD.ID
|
if view is g.VIEW and boardID is g.BOARD.ID
|
||||||
Navigate.updateContext view
|
Navigate.updateContext view
|
||||||
|
|
||||||
else # We've navigated somewhere we weren't before!
|
else # We've navigated somewhere we weren't before!
|
||||||
Navigate.disconnect()
|
Navigate.disconnect()
|
||||||
Navigate.updateContext view
|
Navigate.updateContext view
|
||||||
@ -208,20 +208,19 @@ Navigate =
|
|||||||
Navigate.title = -> Navigate.updateBoard boardID
|
Navigate.title = -> Navigate.updateBoard boardID
|
||||||
|
|
||||||
if view is 'index'
|
if view is 'index'
|
||||||
Index.update pageNum
|
return Index.update pageNum
|
||||||
|
|
||||||
# Moving from index to thread or thread to thread
|
# Moving from index to thread or thread to thread
|
||||||
else
|
Navigate.updateSFW Favicon.SFW
|
||||||
Navigate.updateSFW Favicon.SFW
|
{load} = Navigate
|
||||||
{load} = Navigate
|
Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/thread/#{threadID}.json",
|
||||||
Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/thread/#{threadID}.json",
|
onabort: load
|
||||||
onabort: load
|
onloadend: load
|
||||||
onloadend: load
|
|
||||||
|
|
||||||
setTimeout (->
|
setTimeout (->
|
||||||
if Navigate.req and !Navigate.notice
|
if Navigate.req and !Navigate.notice
|
||||||
Navigate.notice = new Notice 'info', 'Loading thread...'
|
Navigate.notice = new Notice 'info', 'Loading thread...'
|
||||||
), 3 * $.SECOND
|
), 3 * $.SECOND
|
||||||
|
|
||||||
load: (e) ->
|
load: (e) ->
|
||||||
$.rmClass Index.button, 'fa-spin'
|
$.rmClass Index.button, 'fa-spin'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user