mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Fix various issues when switching from single doc to full app
This commit is contained in:
parent
7947f2d9ba
commit
4f62ccbdbf
4 changed files with 39 additions and 35 deletions
|
@ -34,19 +34,24 @@ class app.Router
|
|||
return
|
||||
|
||||
before: (context, next) ->
|
||||
previousContext = @context
|
||||
@context = context
|
||||
@trigger 'before', context
|
||||
next()
|
||||
return
|
||||
|
||||
if res = next()
|
||||
@context = previousContext
|
||||
return res
|
||||
else
|
||||
return
|
||||
|
||||
doc: (context, next) ->
|
||||
if doc = app.docs.findBySlug(context.params.doc) or app.disabledDocs.findBySlug(context.params.doc)
|
||||
context.doc = doc
|
||||
context.entry = doc.toEntry()
|
||||
@triggerRoute 'entry'
|
||||
return
|
||||
else
|
||||
next()
|
||||
return
|
||||
return next()
|
||||
|
||||
type: (context, next) ->
|
||||
doc = app.docs.findBySlug(context.params.doc)
|
||||
|
@ -55,9 +60,9 @@ class app.Router
|
|||
context.doc = doc
|
||||
context.type = type
|
||||
@triggerRoute 'type'
|
||||
return
|
||||
else
|
||||
next()
|
||||
return
|
||||
return next()
|
||||
|
||||
entry: (context, next) ->
|
||||
doc = app.docs.findBySlug(context.params.doc)
|
||||
|
@ -66,36 +71,39 @@ class app.Router
|
|||
context.doc = doc
|
||||
context.entry = entry
|
||||
@triggerRoute 'entry'
|
||||
return
|
||||
else
|
||||
next()
|
||||
return
|
||||
return next()
|
||||
|
||||
root: ->
|
||||
if app.isSingleDoc()
|
||||
setTimeout (-> window.location = '/'), 0
|
||||
else
|
||||
@triggerRoute 'root'
|
||||
return '/' if app.isSingleDoc()
|
||||
@triggerRoute 'root'
|
||||
return
|
||||
|
||||
settings: ->
|
||||
settings: (context) ->
|
||||
return "/#/#{context.path}" if app.isSingleDoc()
|
||||
@triggerRoute 'settings'
|
||||
return
|
||||
|
||||
offline: ->
|
||||
offline: (context)->
|
||||
return "/#/#{context.path}" if app.isSingleDoc()
|
||||
@triggerRoute 'offline'
|
||||
return
|
||||
|
||||
about: (context) ->
|
||||
return "/#/#{context.path}" if app.isSingleDoc()
|
||||
context.page = 'about'
|
||||
@triggerRoute 'page'
|
||||
return
|
||||
|
||||
news: (context) ->
|
||||
return "/#/#{context.path}" if app.isSingleDoc()
|
||||
context.page = 'news'
|
||||
@triggerRoute 'page'
|
||||
return
|
||||
|
||||
help: (context) ->
|
||||
return "/#/#{context.path}" if app.isSingleDoc()
|
||||
context.page = 'help'
|
||||
@triggerRoute 'page'
|
||||
return
|
||||
|
|
|
@ -38,11 +38,15 @@ page.stop = ->
|
|||
page.show = (path, state) ->
|
||||
return if path is currentState?.path
|
||||
context = new Context(path, state)
|
||||
previousState = currentState
|
||||
currentState = context.state
|
||||
page.dispatch(context)
|
||||
context.pushState()
|
||||
updateCanonicalLink()
|
||||
track()
|
||||
if res = page.dispatch(context)
|
||||
currentState = previousState
|
||||
location.assign(res)
|
||||
else
|
||||
context.pushState()
|
||||
updateCanonicalLink()
|
||||
track()
|
||||
context
|
||||
|
||||
page.replace = (path, state, skipDispatch, init) ->
|
||||
|
@ -58,10 +62,9 @@ page.replace = (path, state, skipDispatch, init) ->
|
|||
page.dispatch = (context) ->
|
||||
i = 0
|
||||
next = ->
|
||||
fn(context, next) if fn = callbacks[i++]
|
||||
return
|
||||
next()
|
||||
return
|
||||
res = fn(context, next) if fn = callbacks[i++]
|
||||
return res
|
||||
return next()
|
||||
|
||||
page.canGoBack = ->
|
||||
not Context.isIntialState(currentState)
|
||||
|
@ -116,10 +119,9 @@ class Route
|
|||
(context, next) =>
|
||||
if @match context.pathname, params = []
|
||||
context.params = params
|
||||
fn(context, next)
|
||||
return fn(context, next)
|
||||
else
|
||||
next()
|
||||
return
|
||||
return next()
|
||||
|
||||
match: (path, params) ->
|
||||
return unless matchData = @regexp.exec(path)
|
||||
|
|
|
@ -45,11 +45,8 @@ class app.views.OfflinePage extends app.View
|
|||
docEl: (doc) ->
|
||||
@find("[data-slug='#{doc.slug}']")
|
||||
|
||||
onRoute: (route) ->
|
||||
if app.isSingleDoc()
|
||||
window.location = "/#/#{route.path}"
|
||||
else
|
||||
@render()
|
||||
onRoute: (context) ->
|
||||
@render()
|
||||
return
|
||||
|
||||
onClick: (event) =>
|
||||
|
|
|
@ -58,9 +58,6 @@ class app.views.SettingsPage extends app.View
|
|||
@toggle input.name, input.checked
|
||||
return
|
||||
|
||||
onRoute: (route) =>
|
||||
if app.isSingleDoc()
|
||||
window.location = "/#/#{route.path}"
|
||||
else
|
||||
@render()
|
||||
onRoute: (context) ->
|
||||
@render()
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue