document.coffee 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. class app.views.Document extends app.View
  2. @el: document
  3. @events:
  4. visibilitychange: 'onVisibilityChange'
  5. @shortcuts:
  6. help: 'onHelp'
  7. preferences: 'onPreferences'
  8. escape: 'onEscape'
  9. superLeft: 'onBack'
  10. superRight: 'onForward'
  11. @routes:
  12. after: 'afterRoute'
  13. init: ->
  14. @addSubview @menu = new app.views.Menu,
  15. @addSubview @sidebar = new app.views.Sidebar
  16. @addSubview @resizer = new app.views.Resizer if app.views.Resizer.isSupported()
  17. @addSubview @content = new app.views.Content
  18. @addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile()
  19. @settings = new app.views.Settings unless app.isSingleDoc()
  20. $.on document.body, 'click', @onClick
  21. @activate()
  22. return
  23. setTitle: (title) ->
  24. @el.title = if title then "#{title} — DevDocs" else 'DevDocs API Documentation'
  25. afterRoute: (route) =>
  26. if route is 'settings'
  27. @settings?.activate()
  28. else
  29. @settings?.deactivate()
  30. return
  31. onVisibilityChange: =>
  32. return unless @el.visibilityState is 'visible'
  33. @delay ->
  34. location.reload() if app.isMobile() isnt app.views.Mobile.detect()
  35. return
  36. , 300
  37. return
  38. onHelp: ->
  39. app.router.show '/help#shortcuts'
  40. return
  41. onPreferences: ->
  42. app.router.show '/settings'
  43. return
  44. onEscape: ->
  45. path = if !app.isSingleDoc() or location.pathname is app.doc.fullPath()
  46. '/'
  47. else
  48. app.doc.fullPath()
  49. app.router.show(path)
  50. return
  51. onBack: ->
  52. history.back()
  53. return
  54. onForward: ->
  55. history.forward()
  56. return
  57. onClick: (event) ->
  58. target = $.eventTarget(event)
  59. return unless target.hasAttribute('data-behavior')
  60. $.stopEvent(event)
  61. switch target.getAttribute('data-behavior')
  62. when 'back' then history.back()
  63. when 'reload' then window.location.reload()
  64. when 'reboot' then app.reboot()
  65. when 'hard-reload' then app.reload()
  66. when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?')
  67. when 'accept-analytics' then Cookies.set('analyticsConsent', '1') && app.reboot()
  68. when 'decline-analytics' then Cookies.set('analyticsConsent', '0') && app.reboot()
  69. return