Skip to content

Commit

Permalink
Switching keycodes.js and app.js to ES6 modules (#279)
Browse files Browse the repository at this point in the history
This avoids polluting the global namespace and makes explicit which functions we want to export.
  • Loading branch information
mtlynch authored Oct 7, 2020
1 parent 255f657 commit c2aed0c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

import { isAltGraphPressed, findKeyCode } from "./keycodes.js";

const socket = io();
let connectedToServer = false;

Expand Down
4 changes: 2 additions & 2 deletions app/static/js/keycodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const commonKeyCodes = {
};

// Given a character and a browser language, finds the matching keycode
function findKeyCode(character, browserLanguage) {
export function findKeyCode(character, browserLanguage) {
if (browserLanguage === "en-GB") {
return findKeyCodeEnGb(character);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ function findKeyCodeEnGb(character) {
// But in my tests, I see all modifiers as false when Alt Graph is pushed.
// The only difference in the onKeyDown event I see is that the key property
// changes when Alt Graph is pushed, so we detect it that way.
function isAltGraphPressed(browserLanguage, keyCode, key) {
export function isAltGraphPressed(browserLanguage, keyCode, key) {
// Only French AZERTY is supported now.
// This is not robust, as a user's browser language doesn't necessarily match
// their keyboard layout.
Expand Down
3 changes: 1 addition & 2 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ <h3 id="error-type">Error Type</h3>
{% include "components/paste-overlay.html" %}
<shutdown-wait id="shutdown-wait"></shutdown-wait>
<script src="/third-party/socket.io/2.3.0/socket.io.js"></script>
<script src="/js/keycodes.js"></script>
<script src="/js/paste.js"></script>
<script src="/js/app.js"></script>
<script type="module" src="/js/app.js"></script>
</body>
</html>

0 comments on commit c2aed0c

Please sign in to comment.