1
0

document.coffee 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class app.views.Document extends app.View
  2. @el: document
  3. @shortcuts:
  4. help: 'onHelp'
  5. escape: 'onEscape'
  6. superLeft: 'onBack'
  7. superRight: 'onForward'
  8. init: ->
  9. @addSubview @nav = new app.views.Nav,
  10. @addSubview @sidebar = new app.views.Sidebar
  11. @addSubview @resizer = new app.views.Resizer if app.views.Resizer.isSupported()
  12. @addSubview @content = new app.views.Content
  13. @addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile()
  14. @setTitle()
  15. @activate()
  16. return
  17. toggleLight: ->
  18. css = $('link[rel="stylesheet"][data-alt]')
  19. alt = css.getAttribute('data-alt')
  20. css.setAttribute('data-alt', css.getAttribute('href'))
  21. css.setAttribute('href', alt)
  22. app.settings.setDark(alt.indexOf('dark') > 0)
  23. app.appCache?.updateInBackground()
  24. return
  25. setTitle: (title) ->
  26. @el.title = if title then "DevDocs/#{title}" else 'DevDocs'
  27. onHelp: ->
  28. app.router.show '/help#shortcuts'
  29. onEscape: ->
  30. path = if !app.isSingleDoc() or location.pathname is app.doc.fullPath()
  31. '/'
  32. else
  33. app.doc.fullPath()
  34. app.router.show(path)
  35. onBack: ->
  36. history.back()
  37. onForward: ->
  38. history.forward()