forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.coffee
More file actions
85 lines (69 loc) · 2.27 KB
/
Copy pathdocument.coffee
File metadata and controls
85 lines (69 loc) · 2.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class app.views.Document extends app.View
@el: document
@events:
visibilitychange: 'onVisibilityChange'
@shortcuts:
help: 'onHelp'
preferences: 'onPreferences'
escape: 'onEscape'
superLeft: 'onBack'
superRight: 'onForward'
@routes:
after: 'afterRoute'
init: ->
@addSubview @menu = new app.views.Menu,
@addSubview @sidebar = new app.views.Sidebar
@addSubview @resizer = new app.views.Resizer if app.views.Resizer.isSupported()
@addSubview @content = new app.views.Content
@addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile()
@settings = new app.views.Settings unless app.isSingleDoc()
$.on document.body, 'click', @onClick
@activate()
return
setTitle: (title) ->
@el.title = if title then "#{title} — DevDocs" else 'DevDocs API Documentation'
afterRoute: (route) =>
if route is 'settings'
@settings?.activate()
else
@settings?.deactivate()
return
onVisibilityChange: =>
return unless @el.visibilityState is 'visible'
@delay ->
location.reload() if app.isMobile() isnt app.views.Mobile.detect()
return
, 300
return
onHelp: ->
app.router.show '/help#shortcuts'
return
onPreferences: ->
app.router.show '/settings'
return
onEscape: ->
path = if !app.isSingleDoc() or location.pathname is app.doc.fullPath()
'/'
else
app.doc.fullPath()
app.router.show(path)
return
onBack: ->
history.back()
return
onForward: ->
history.forward()
return
onClick: (event) ->
target = $.eventTarget(event)
return unless target.hasAttribute('data-behavior')
$.stopEvent(event)
switch target.getAttribute('data-behavior')
when 'back' then history.back()
when 'reload' then window.location.reload()
when 'reboot' then app.reboot()
when 'hard-reload' then app.reload()
when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?')
when 'accept-analytics' then Cookies.set('analyticsConsent', '1', expires: 1e8) && app.reboot()
when 'decline-analytics' then Cookies.set('analyticsConsent', '0', expires: 1e8) && app.reboot()
return