forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b330661
commit c58eb41
Showing
9 changed files
with
92 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import hotkeys from "hotkeys-js" | ||
|
||
const ADD_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M256 112v288M400 256H112"/></svg>` | ||
|
||
window.addEventListener("load", () => { | ||
document.querySelectorAll("[data-keyboard-shortcut]").forEach(function(element) { | ||
hotkeys(translateKeyboardShortcutForOS(element.dataset.keyboardShortcut), () => { | ||
element.click() | ||
// Returning false stops the event and prevents default browser events | ||
return false | ||
}) | ||
}) | ||
}) | ||
|
||
/** | ||
* Translates a given keyboard shortcut, e.g. CMD+K, into an OS friendly version, e.g. CTRL+K | ||
* @param {string} keyboardShortcut The shortcut for translation | ||
*/ | ||
function translateKeyboardShortcutForOS(keyboardShortcut) { | ||
const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0 | ||
return keyboardShortcut.replace("CMD", isMac ? "CMD" : "CTRL") | ||
} | ||
|
||
/** | ||
* Translates a given keyboard shortcut, e.g. CMD+K, into a UI friendly version, e.g. ⌘+K | ||
* @param {string} keyboardShortcut The shortcut for translation | ||
*/ | ||
function translateKeyboardShortcutForUI(keyboardShortcut) { | ||
const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0 | ||
return keyboardShortcut.replace("CMD", isMac ? "⌘" : "CTRL") | ||
} | ||
|
||
/** | ||
* Generates a UI representation of the given keyboard shortcut | ||
* @param {string} keyboardShortcut The shortcut for generation | ||
*/ | ||
export function generateKeyboardShortcutUI(keyboardShortcut) { | ||
return translateKeyboardShortcutForUI(keyboardShortcut) | ||
.split("+") | ||
.map(shortcut => `<span class="shortcut">${shortcut}</span>`) | ||
.join(ADD_SVG) | ||
} | ||
|
||
export default { generateKeyboardShortcutUI } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters