Unified · Split
| @@ -242,15 +242,7 @@ · 241 unmodified lines | |||
| 242 | !!(@DOC or @doc) | 242 | !!(@DOC or @doc) |
| 243 | 243 | ||
| 244 | isMobile: -> | 244 | isMobile: -> |
| 245 | try | 245 | @_isMobile ?= app.views.Mobile.detect() |
| 246 | # Need to sniff the user agent because some Android and Windows Phone devices don't take | ||
| 247 | # resolution (dpi) into account when reporting device width/height. | ||
| 248 | @_isMobile ?= (window.matchMedia('(max-device-width: 767px)').matches) or | ||
| 249 | (window.matchMedia('(max-device-height: 767px) and (max-device-width: 1024px)').matches) or | ||
| 250 | (navigator.userAgent.indexOf('Android') isnt -1 and navigator.userAgent.indexOf('Mobile') isnt -1) or | ||
| 251 | (navigator.userAgent.indexOf('IEMobile') isnt -1) | ||
| 252 | catch | ||
| 253 | @_isMobile = false | ||
| 254 | 246 | ||
| 255 | isInvalidLocation: -> | 247 | isInvalidLocation: -> |
| 256 | @config.env is 'production' and location.host.indexOf(app.config.production_host) isnt 0 | 248 | @config.env is 'production' and location.host.indexOf(app.config.production_host) isnt 0 |
| @@ -3,6 +3,9 @@ class app.views.Document extends app.View · 2 unmodified lines | |||
| 3 | 3 | ||
| 4 | @el: document | 4 | @el: document |
| 5 | 5 | ||
| 6 | @events: | ||
| 7 | visibilitychange: 'onVisibilityChange' | ||
| 8 | |||
| 6 | @shortcuts: | 9 | @shortcuts: |
| 7 | help: 'onHelp' | 10 | help: 'onHelp' |
| 8 | escape: 'onEscape' | 11 | escape: 'onEscape' |
| @@ -38,6 +41,14 @@ class app.views.Document extends app.View · 29 unmodified lines | |||
| 38 | setTitle: (title) -> | 41 | setTitle: (title) -> |
| 39 | @el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation' | 42 | @el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation' |
| 40 | 43 | ||
| 44 | onVisibilityChange: => | ||
| 45 | return unless @el.visibilityState is 'visible' | ||
| 46 | @delay -> | ||
| 47 | location.reload() if app.isMobile() isnt app.views.Mobile.detect() | ||
| 48 | return | ||
| 49 | , 300 | ||
| 50 | return | ||
| 51 | |||
| 41 | onHelp: -> | 52 | onHelp: -> |
| 42 | app.router.show '/help#shortcuts' | 53 | app.router.show '/help#shortcuts' |
| 43 | 54 | ||
| @@ -9,6 +9,18 @@ class app.views.Mobile extends app.View · 8 unmodified lines | |||
| 9 | @routes: | 9 | @routes: |
| 10 | after: 'afterRoute' | 10 | after: 'afterRoute' |
| 11 | 11 | ||
| 12 | @detect: -> | ||
| 13 | try | ||
| 14 | (window.matchMedia('(max-width: 480px)').matches) or | ||
| 15 | (window.matchMedia('(max-device-width: 767px)').matches) or | ||
| 16 | (window.matchMedia('(max-device-height: 767px) and (max-device-width: 1024px)').matches) or | ||
| 17 | # Need to sniff the user agent because some Android and Windows Phone devices don't take | ||
| 18 | # resolution (dpi) into account when reporting device width/height. | ||
| 19 | (navigator.userAgent.indexOf('Android') isnt -1 and navigator.userAgent.indexOf('Mobile') isnt -1) or | ||
| 20 | (navigator.userAgent.indexOf('IEMobile') isnt -1) | ||
| 21 | catch | ||
| 22 | false | ||
| 23 | |||
| 12 | constructor: -> | 24 | constructor: -> |
| 13 | @el = document.documentElement | 25 | @el = document.documentElement |
| 14 | super | 26 | super |