Showing the changes to assets/javascripts (4 of 4 files). Show all
Unified · Split
| @@ -34,19 +34,24 @@ class app.Router · 33 unmodified lines | ||
| 34 | 34 | return |
| 35 | 35 | |
| 36 | 36 | before: (context, next) -> |
| 37 | + previousContext = @context | |
| 37 | 38 | @context = context |
| 38 | 39 | @trigger 'before', context |
| 39 | − next() | |
| 40 | − return | |
| 40 | + | |
| 41 | + if res = next() | |
| 42 | + @context = previousContext | |
| 43 | + return res | |
| 44 | + else | |
| 45 | + return | |
| 41 | 46 | |
| 42 | 47 | doc: (context, next) -> |
| 43 | 48 | if doc = app.docs.findBySlug(context.params.doc) or app.disabledDocs.findBySlug(context.params.doc) |
| 44 | 49 | context.doc = doc |
| 45 | 50 | context.entry = doc.toEntry() |
| 46 | 51 | @triggerRoute 'entry' |
| 52 | + return | |
| 47 | 53 | else |
| 48 | − next() | |
| 49 | − return | |
| 54 | + return next() | |
| 50 | 55 | |
| 51 | 56 | type: (context, next) -> |
| 52 | 57 | doc = app.docs.findBySlug(context.params.doc) |
| @@ -55,9 +60,9 @@ class app.Router · 2 unmodified lines | ||
| 55 | 60 | context.doc = doc |
| 56 | 61 | context.type = type |
| 57 | 62 | @triggerRoute 'type' |
| 63 | + return | |
| 58 | 64 | else |
| 59 | − next() | |
| 60 | − return | |
| 65 | + return next() | |
| 61 | 66 | |
| 62 | 67 | entry: (context, next) -> |
| 63 | 68 | doc = app.docs.findBySlug(context.params.doc) |
| @@ -66,36 +71,39 @@ class app.Router · 2 unmodified lines | ||
| 66 | 71 | context.doc = doc |
| 67 | 72 | context.entry = entry |
| 68 | 73 | @triggerRoute 'entry' |
| 74 | + return | |
| 69 | 75 | else |
| 70 | − next() | |
| 71 | − return | |
| 76 | + return next() | |
| 72 | 77 | |
| 73 | 78 | root: -> |
| 74 | − if app.isSingleDoc() | |
| 75 | − setTimeout (-> window.location = '/'), 0 | |
| 76 | − else | |
| 77 | − @triggerRoute 'root' | |
| 79 | + return '/' if app.isSingleDoc() | |
| 80 | + @triggerRoute 'root' | |
| 78 | 81 | return |
| 79 | 82 | |
| 80 | − settings: -> | |
| 83 | + settings: (context) -> | |
| 84 | + return "/#/#{context.path}" if app.isSingleDoc() | |
| 81 | 85 | @triggerRoute 'settings' |
| 82 | 86 | return |
| 83 | 87 | |
| 84 | − offline: -> | |
| 88 | + offline: (context)-> | |
| 89 | + return "/#/#{context.path}" if app.isSingleDoc() | |
| 85 | 90 | @triggerRoute 'offline' |
| 86 | 91 | return |
| 87 | 92 | |
| 88 | 93 | about: (context) -> |
| 94 | + return "/#/#{context.path}" if app.isSingleDoc() | |
| 89 | 95 | context.page = 'about' |
| 90 | 96 | @triggerRoute 'page' |
| 91 | 97 | return |
| 92 | 98 | |
| 93 | 99 | news: (context) -> |
| 100 | + return "/#/#{context.path}" if app.isSingleDoc() | |
| 94 | 101 | context.page = 'news' |
| 95 | 102 | @triggerRoute 'page' |
| 96 | 103 | return |
| 97 | 104 | |
| 98 | 105 | help: (context) -> |
| 106 | + return "/#/#{context.path}" if app.isSingleDoc() | |
| 99 | 107 | context.page = 'help' |
| 100 | 108 | @triggerRoute 'page' |
| 101 | 109 | return |
| @@ -38,11 +38,15 @@ page.stop = -> · 37 unmodified lines | ||
| 38 | 38 | page.show = (path, state) -> |
| 39 | 39 | return if path is currentState?.path |
| 40 | 40 | context = new Context(path, state) |
| 41 | + previousState = currentState | |
| 41 | 42 | currentState = context.state |
| 42 | − page.dispatch(context) | |
| 43 | − context.pushState() | |
| 44 | − updateCanonicalLink() | |
| 45 | − track() | |
| 43 | + if res = page.dispatch(context) | |
| 44 | + currentState = previousState | |
| 45 | + location.assign(res) | |
| 46 | + else | |
| 47 | + context.pushState() | |
| 48 | + updateCanonicalLink() | |
| 49 | + track() | |
| 46 | 50 | context |
| 47 | 51 | |
| 48 | 52 | page.replace = (path, state, skipDispatch, init) -> |
| @@ -58,10 +62,9 @@ page.replace = (path, state, skipDispatch, init) -> · 9 unmodified lines | ||
| 58 | 62 | page.dispatch = (context) -> |
| 59 | 63 | i = 0 |
| 60 | 64 | next = -> |
| 61 | − fn(context, next) if fn = callbacks[i++] | |
| 62 | − return | |
| 63 | − next() | |
| 64 | − return | |
| 65 | + res = fn(context, next) if fn = callbacks[i++] | |
| 66 | + return res | |
| 67 | + return next() | |
| 65 | 68 | |
| 66 | 69 | page.canGoBack = -> |
| 67 | 70 | not Context.isIntialState(currentState) |
| @@ -116,10 +119,9 @@ class Route · 48 unmodified lines | ||
| 116 | 119 | (context, next) => |
| 117 | 120 | if @match context.pathname, params = [] |
| 118 | 121 | context.params = params |
| 119 | − fn(context, next) | |
| 122 | + return fn(context, next) | |
| 120 | 123 | else |
| 121 | − next() | |
| 122 | − return | |
| 124 | + return next() | |
| 123 | 125 | |
| 124 | 126 | match: (path, params) -> |
| 125 | 127 | return unless matchData = @regexp.exec(path) |
| @@ -45,11 +45,8 @@ class app.views.OfflinePage extends app.View · 44 unmodified lines | ||
| 45 | 45 | docEl: (doc) -> |
| 46 | 46 | @find("[data-slug='#{doc.slug}']") |
| 47 | 47 | |
| 48 | − onRoute: (route) -> | |
| 49 | − if app.isSingleDoc() | |
| 50 | − window.location = "/#/#{route.path}" | |
| 51 | − else | |
| 52 | − @render() | |
| 48 | + onRoute: (context) -> | |
| 49 | + @render() | |
| 53 | 50 | return |
| 54 | 51 | |
| 55 | 52 | onClick: (event) => |
| @@ -58,9 +58,6 @@ class app.views.SettingsPage extends app.View · 57 unmodified lines | ||
| 58 | 58 | @toggle input.name, input.checked |
| 59 | 59 | return |
| 60 | 60 | |
| 61 | − onRoute: (route) => | |
| 62 | − if app.isSingleDoc() | |
| 63 | − window.location = "/#/#{route.path}" | |
| 64 | − else | |
| 65 | − @render() | |
| 61 | + onRoute: (context) -> | |
| 62 | + @render() | |
| 66 | 63 | return |