1
0
Эх сурвалжийг харах

Wrap app.isMobile in try/catch

Thibaut 11 жил өмнө
parent
commit
e21ac0589c

+ 8 - 5
assets/javascripts/app/app.coffee

@@ -191,11 +191,14 @@
     !!(@DOC or @doc)
 
   isMobile: ->
-    # Need to sniff the user agent because some Android and Windows Phone devices don't take
-    # resolution (dpi) into account when reporting device width/height.
-    @_isMobile ?= (matchMedia('(max-device-width: 767px), (max-device-height: 767px)').matches) or
-                  (navigator.userAgent.indexOf('Android') isnt -1 and navigator.userAgent.indexOf('Mobile') isnt -1) or
-                  (navigator.userAgent.indexOf('IEMobile') isnt -1)
+    try
+      # Need to sniff the user agent because some Android and Windows Phone devices don't take
+      # resolution (dpi) into account when reporting device width/height.
+      @_isMobile ?= (window.matchMedia('(max-device-width: 767px), (max-device-height: 767px)').matches) or
+                    (navigator.userAgent.indexOf('Android') isnt -1 and navigator.userAgent.indexOf('Mobile') isnt -1) or
+                    (navigator.userAgent.indexOf('IEMobile') isnt -1)
+    catch
+      @_isMobile = false
 
   isInvalidLocation: ->
     @config.env is 'production' and location.host.indexOf(app.config.production_host) isnt 0