import { getPlatform } from './utils/user-agent-platform.js'; import $ from 'jquery'; /** * Adds OS-specific class to component * @param {string} osClass - OS-specific class to add * @param {Object} options - Component options * @param {jQuery} options.$component - jQuery element reference */ function addOSClass(osClass, { $component }) { $component.addClass(osClass); } /** * Updates keybinding display based on detected platform * @param {Object} options - Component options * @param {jQuery} options.$component - jQuery element reference * @param {string} options.platform - Detected platform */ function updateKeyBindings({ $component, platform }) { const osx = $component.data('osx'); const linux = $component.data('linux'); const win = $component.data('win'); let keybind; if (platform === 'other') { if (win !== linux) { keybind = `${osx} for macOS, ` + `${linux} for Linux, ` + `and ${win} for Windows`; } else { keybind = `${linux} for Linux and Windows and ` + `${osx} for macOS`; } } else { keybind = `${$component.data(platform)}`; } $component.html(keybind); } /** * Initialize and render platform-specific keybindings * @param {Object} options - Component options * @param {HTMLElement} options.component - DOM element * @returns {void} */ export default function KeyBinding({ component }) { // Initialize keybindings const platform = getPlatform(); const $component = $(component); addOSClass(platform, { $component }); updateKeyBindings({ $component, platform }); }