Fix various issues when switching from single doc to full app

pull/385/merge
Thibaut Courouble 8 years ago
parent 7947f2d9ba
commit 4f62ccbdbf

@ -34,19 +34,24 @@ class app.Router
return return
before: (context, next) -> before: (context, next) ->
previousContext = @context
@context = context @context = context
@trigger 'before', context @trigger 'before', context
next()
return if res = next()
@context = previousContext
return res
else
return
doc: (context, next) -> doc: (context, next) ->
if doc = app.docs.findBySlug(context.params.doc) or app.disabledDocs.findBySlug(context.params.doc) if doc = app.docs.findBySlug(context.params.doc) or app.disabledDocs.findBySlug(context.params.doc)
context.doc = doc context.doc = doc
context.entry = doc.toEntry() context.entry = doc.toEntry()
@triggerRoute 'entry' @triggerRoute 'entry'
return
else else
next() return next()
return
type: (context, next) -> type: (context, next) ->
doc = app.docs.findBySlug(context.params.doc) doc = app.docs.findBySlug(context.params.doc)
@ -55,9 +60,9 @@ class app.Router
context.doc = doc context.doc = doc
context.type = type context.type = type
@triggerRoute 'type' @triggerRoute 'type'
return
else else
next() return next()
return
entry: (context, next) -> entry: (context, next) ->
doc = app.docs.findBySlug(context.params.doc) doc = app.docs.findBySlug(context.params.doc)
@ -66,36 +71,39 @@ class app.Router
context.doc = doc context.doc = doc
context.entry = entry context.entry = entry
@triggerRoute 'entry' @triggerRoute 'entry'
return
else else
next() return next()
return
root: -> root: ->
if app.isSingleDoc() return '/' if app.isSingleDoc()
setTimeout (-> window.location = '/'), 0 @triggerRoute 'root'
else
@triggerRoute 'root'
return return
settings: -> settings: (context) ->
return "/#/#{context.path}" if app.isSingleDoc()
@triggerRoute 'settings' @triggerRoute 'settings'
return return
offline: -> offline: (context)->
return "/#/#{context.path}" if app.isSingleDoc()
@triggerRoute 'offline' @triggerRoute 'offline'
return return
about: (context) -> about: (context) ->
return "/#/#{context.path}" if app.isSingleDoc()
context.page = 'about' context.page = 'about'
@triggerRoute 'page' @triggerRoute 'page'
return return
news: (context) -> news: (context) ->
return "/#/#{context.path}" if app.isSingleDoc()
context.page = 'news' context.page = 'news'
@triggerRoute 'page' @triggerRoute 'page'
return return
help: (context) -> help: (context) ->
return "/#/#{context.path}" if app.isSingleDoc()
context.page = 'help' context.page = 'help'
@triggerRoute 'page' @triggerRoute 'page'
return return

@ -38,11 +38,15 @@ page.stop = ->
page.show = (path, state) -> page.show = (path, state) ->
return if path is currentState?.path return if path is currentState?.path
context = new Context(path, state) context = new Context(path, state)
previousState = currentState
currentState = context.state currentState = context.state
page.dispatch(context) if res = page.dispatch(context)
context.pushState() currentState = previousState
updateCanonicalLink() location.assign(res)
track() else
context.pushState()
updateCanonicalLink()
track()
context context
page.replace = (path, state, skipDispatch, init) -> page.replace = (path, state, skipDispatch, init) ->
@ -58,10 +62,9 @@ page.replace = (path, state, skipDispatch, init) ->
page.dispatch = (context) -> page.dispatch = (context) ->
i = 0 i = 0
next = -> next = ->
fn(context, next) if fn = callbacks[i++] res = fn(context, next) if fn = callbacks[i++]
return return res
next() return next()
return
page.canGoBack = -> page.canGoBack = ->
not Context.isIntialState(currentState) not Context.isIntialState(currentState)
@ -116,10 +119,9 @@ class Route
(context, next) => (context, next) =>
if @match context.pathname, params = [] if @match context.pathname, params = []
context.params = params context.params = params
fn(context, next) return fn(context, next)
else else
next() return next()
return
match: (path, params) -> match: (path, params) ->
return unless matchData = @regexp.exec(path) return unless matchData = @regexp.exec(path)

@ -45,11 +45,8 @@ class app.views.OfflinePage extends app.View
docEl: (doc) -> docEl: (doc) ->
@find("[data-slug='#{doc.slug}']") @find("[data-slug='#{doc.slug}']")
onRoute: (route) -> onRoute: (context) ->
if app.isSingleDoc() @render()
window.location = "/#/#{route.path}"
else
@render()
return return
onClick: (event) => onClick: (event) =>

@ -58,9 +58,6 @@ class app.views.SettingsPage extends app.View
@toggle input.name, input.checked @toggle input.name, input.checked
return return
onRoute: (route) => onRoute: (context) ->
if app.isSingleDoc() @render()
window.location = "/#/#{route.path}"
else
@render()
return return

Loading…
Cancel
Save