Files
iD/js/id/ui/cmd.js
John Firebaugh 66afcd9923 Platform-specific keybindings
Specifying keybindings that use a command key (⌘ on Mac,
Ctrl on Win/Linux) using the appropriate Mac binding, e.g.
'⌘Z'. Use iD.ui.cmd to translate it to an appropriate key
string for other platforms, e.g. 'Ctrl+Z'.
2013-02-11 11:24:05 -08:00

23 lines
524 B
JavaScript

// Translate a MacOS key command into the appropriate Windows/Linux equivalent.
// For example, ⌘Z -> Ctrl+Z
iD.ui.cmd = function(code) {
if (iD.detect().os === 'mac')
return code;
var modifiers = {
'⌘': 'Ctrl',
'⇧': 'Shift',
'⌥': 'Alt'
}, keys = [];
for (var i = 0; i < code.length; i++) {
if (code[i] in modifiers) {
keys.push(modifiers[code[i]]);
} else {
keys.push(code[i]);
}
}
return keys.join('+');
};