-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.url.coffee
58 lines (47 loc) · 1.57 KB
/
app.url.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
###
HTML5 API History Wrapper
@namespace Atoms
@class Url
@author Javier Jimenez Villar <[email protected]> || @soyjavi
###
"use strict"
Atoms.App.Url = do (a = Atoms) ->
_article = undefined
_aside = undefined
_options = Atoms.Url.options
# Private
_onChangeRoute = (properties) ->
article = a.App.Article[properties.article.toClassName()]
if article
unless article.el then article.render()
_article.aside _aside if _article?.el.hasClass "aside"
setTimeout ->
unless _options.forward then _stepHistory 0
_activeSection article, properties.section
if _article isnt article
if _options.forward
_stepHistory 1
article.state("in")
_article.state("back-in").addClass(article.attributes.style) if _article
else
_article.state("out")
article.state("back-out").removeClass(_article.attributes.style)
_article = article
, 10
_activeAside = (id = _aside) ->
_article?.aside _aside = id
_activeSection = (article, section) ->
_addStepHistory()
article.section section
_addStepHistory = ->
state = window.history.state or steps: 0
state.steps++
window.history.replaceState state, document.title
_stepHistory = (value) ->
window.history.replaceState steps: value, document.title
Atoms.$ ->
url = Atoms.Url.path().split("/")
if url.length is 3 then _onChangeRoute article: url[1], section: url[2]
Atoms.Url.listen "/:article/:section", _onChangeRoute
aside : _activeAside
current : -> _article