diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index f8819e11cf..0d3ccfcc8d 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -33,6 +33,7 @@ $.fn.keydown = noop; $.fn.keypress = noop; var hotkey = zrequire('hotkey'); +zrequire('common'); set_global('list_util', { }); diff --git a/static/js/common.js b/static/js/common.js index 60fe8a042b..b074f437dd 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -100,6 +100,10 @@ exports.copy_data_attribute_value = function (elem, key) { elem.fadeIn(1000); }; +exports.has_mac_keyboard = function () { + return /Mac/i.test(navigator.userAgent); +}; + return exports; }()); diff --git a/static/js/compose.js b/static/js/compose.js index 8b32fa98d2..c8b334e47f 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -612,7 +612,7 @@ exports.handle_keydown = function (event, textarea) { var isLink = code === 76 && event.shiftKey; // detect command and ctrl key - var isCmdOrCtrl = /Mac/i.test(navigator.userAgent) ? event.metaKey : event.ctrlKey; + var isCmdOrCtrl = common.has_mac_keyboard() ? event.metaKey : event.ctrlKey; if ((isBold || isItalic || isLink) && isCmdOrCtrl) { var range = textarea.range(); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 4401004fe0..5a4e05ef0f 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -128,7 +128,7 @@ exports.get_keydown_hotkey = function (e) { } } - var isCmdOrCtrl = /Mac/i.test(navigator.userAgent) ? e.metaKey : e.ctrlKey; + var isCmdOrCtrl = common.has_mac_keyboard() ? e.metaKey : e.ctrlKey; if (isCmdOrCtrl && !e.shiftKey) { hotkey = keydown_cmd_or_ctrl_mappings[e.which]; if (hotkey) { diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js index 9df13abe5a..3a9bb8b5a0 100644 --- a/static/js/info_overlay.js +++ b/static/js/info_overlay.js @@ -63,7 +63,7 @@ exports.set_up_toggler = function () { $(".informational-overlays .overlay-tabs").append(elem); - if (/Mac/i.test(navigator.userAgent)) { + if (common.has_mac_keyboard()) { adjust_mac_shortcuts(); } diff --git a/static/js/portico/help.js b/static/js/portico/help.js index 31741528f3..ec9adba2f9 100644 --- a/static/js/portico/help.js +++ b/static/js/portico/help.js @@ -74,7 +74,7 @@ function render_code_sections() { highlight_current_article(); - if (/Mac/i.test(navigator.userAgent)) { + if (common.has_mac_keyboard()) { adjust_mac_shortcuts(); } diff --git a/static/js/portico/tabbed-instructions.js b/static/js/portico/tabbed-instructions.js index bfd77a9d1f..a965b57b8a 100644 --- a/static/js/portico/tabbed-instructions.js +++ b/static/js/portico/tabbed-instructions.js @@ -5,7 +5,7 @@ export function detect_user_os() { if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { return "ios"; } - if (/Mac/i.test(navigator.userAgent)) { + if (common.has_mac_keyboard()) { return "mac"; } if (/Win/i.test(navigator.userAgent)) { diff --git a/static/js/ui.js b/static/js/ui.js index 195b436b09..4c69b9105e 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -139,7 +139,7 @@ exports.get_hotkey_deprecation_notice = function (originalHotkey, replacementHot var shown_deprecation_notices = []; exports.maybe_show_deprecation_notice = function (key) { var message; - var isCmdOrCtrl = /Mac/i.test(navigator.userAgent) ? "Cmd" : "Ctrl"; + var isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl"; if (key === 'C') { message = exports.get_hotkey_deprecation_notice('C', 'x'); } else if (key === '*') {