浏览代码

Wrap app.isMobile in try/catch

Thibaut 11 年之前
父节点
当前提交
e21ac0589c
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8 5
      assets/javascripts/app/app.coffee

+ 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