Browse Source

Refactor Mac/Windows detection

Thibaut 11 years ago
parent
commit
4ffc605019

+ 1 - 1
assets/javascripts/app/shortcuts.coffee

@@ -2,7 +2,7 @@ class app.Shortcuts
   $.extend @prototype, Events
 
   constructor: ->
-    @isWindows = navigator.platform?.indexOf('Win') >= 0
+    @isWindows = $.isWindows()
     @start()
 
   start: ->

+ 6 - 0
assets/javascripts/lib/util.coffee

@@ -277,6 +277,12 @@ $.popup = (value) ->
 $.isTouchScreen = ->
   typeof ontouchstart isnt 'undefined'
 
+$.isWindows = ->
+  navigator.platform?.indexOf('Win') >= 0
+
+$.isMac = ->
+  navigator.userAgent?.indexOf('Mac') >= 0
+
 HIGHLIGHT_DEFAULTS =
   className: 'highlight'
   delay: 1000

+ 2 - 2
assets/javascripts/templates/pages/help_tmpl.coffee

@@ -1,5 +1,5 @@
-ctrlKey = if navigator.userAgent?.indexOf('Mac') >= 0 then 'cmd' else 'ctrl'
-navKey = if navigator.platform?.indexOf('Win') >= 0 then 'alt' else ctrlKey
+ctrlKey = if $.isMac() then 'cmd' else 'ctrl'
+navKey = if $.isWindows() then 'alt' else ctrlKey
 
 app.templates.helpPage = """
   <div class="_toc">