History

Improve mobile detection + handle iOS side view

Thibaut Courouble committed 10 years ago

Commit 29efcef1 parent 0e8aeed3 files · +24 −9Browse files

Unified · Split

3 files
  1. assets/javascripts/app/app.coffee +1 −9
  2. assets/javascripts/views/layout/document.coffee +11 −0
  3. assets/javascripts/views/layout/mobile.coffee +12 −0
assets/javascripts/app/app.coffee+1−9
@@ -242,15 +242,7 @@ · 241 unmodified lines
242242 !!(@DOC or @doc)
243243
244244 isMobile: ->
245− try
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
245+ @_isMobile ?= app.views.Mobile.detect()
254246
255247 isInvalidLocation: ->
256248 @config.env is 'production' and location.host.indexOf(app.config.production_host) isnt 0
assets/javascripts/views/layout/document.coffee+11−0
@@ -3,6 +3,9 @@ class app.views.Document extends app.View · 2 unmodified lines
33
44 @el: document
55
6+ @events:
7+ visibilitychange: 'onVisibilityChange'
8+
69 @shortcuts:
710 help: 'onHelp'
811 escape: 'onEscape'
@@ -38,6 +41,14 @@ class app.views.Document extends app.View · 29 unmodified lines
3841 setTitle: (title) ->
3942 @el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation'
4043
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+
4152 onHelp: ->
4253 app.router.show '/help#shortcuts'
4354
assets/javascripts/views/layout/mobile.coffee+12−0
@@ -9,6 +9,18 @@ class app.views.Mobile extends app.View · 8 unmodified lines
99 @routes:
1010 after: 'afterRoute'
1111
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+
1224 constructor: ->
1325 @el = document.documentElement
1426 super

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t