You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/layout/document.coffee

57 lines
1.5 KiB

11 years ago
class app.views.Document extends app.View
MAX_WIDTH_CLASS = '_max-width'
11 years ago
@el: document
@shortcuts:
help: 'onHelp'
escape: 'onEscape'
superLeft: 'onBack'
superRight: 'onForward'
init: ->
@addSubview @nav = new app.views.Nav,
@addSubview @sidebar = new app.views.Sidebar
@addSubview @resizer = new app.views.Resizer if app.views.Resizer.isSupported()
11 years ago
@addSubview @content = new app.views.Content
@addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile()
11 years ago
@activate()
return
toggleLight: ->
css = $('link[rel="stylesheet"][data-alt]')
alt = css.getAttribute('data-alt')
css.setAttribute('data-alt', css.getAttribute('href'))
css.setAttribute('href', alt)
app.settings.setDark(alt.indexOf('dark') > 0)
app.appCache?.updateInBackground()
return
toggleLayout: ->
wantsMaxWidth = !app.el.classList.contains(MAX_WIDTH_CLASS)
app.el.classList[if wantsMaxWidth then 'add' else 'remove'](MAX_WIDTH_CLASS)
app.settings.setLayout(if wantsMaxWidth then MAX_WIDTH_CLASS else false)
app.appCache?.updateInBackground()
return
11 years ago
setTitle: (title) ->
10 years ago
@el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation'
11 years ago
onHelp: ->
app.router.show '/help#shortcuts'
onEscape: ->
path = if !app.isSingleDoc() or location.pathname is app.doc.fullPath()
'/'
else
app.doc.fullPath()
app.router.show(path)
11 years ago
onBack: ->
history.back()
onForward: ->
history.forward()