From 4ffc60501939b4e571f30b365db16f95b4f1c9df Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 10 Aug 2014 08:30:37 -0400 Subject: [PATCH] Refactor Mac/Windows detection --- assets/javascripts/app/shortcuts.coffee | 2 +- assets/javascripts/lib/util.coffee | 6 ++++++ assets/javascripts/templates/pages/help_tmpl.coffee | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/app/shortcuts.coffee b/assets/javascripts/app/shortcuts.coffee index a944af43..567ba01f 100644 --- a/assets/javascripts/app/shortcuts.coffee +++ b/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: -> diff --git a/assets/javascripts/lib/util.coffee b/assets/javascripts/lib/util.coffee index 4e6ee8df..39e4682f 100644 --- a/assets/javascripts/lib/util.coffee +++ b/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 diff --git a/assets/javascripts/templates/pages/help_tmpl.coffee b/assets/javascripts/templates/pages/help_tmpl.coffee index 53e7131e..3b76d7fe 100644 --- a/assets/javascripts/templates/pages/help_tmpl.coffee +++ b/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 = """