Parcourir la source

Refactor `indications.js`

rigwild il y a 4 ans
Parent
commit
4c8bac1b6c
1 fichiers modifiés avec 20 ajouts et 24 suppressions
  1. 20 24
      static/js/indications.js

+ 20 - 24
static/js/indications.js

@@ -1,29 +1,25 @@
-// implement `key` events
-document.onkeydown = checkKey;
-
 // Utils informations
-var KEYCODE_Q           = '81'
-var KEYCODE_ENTER       = '13'
-
-urlParams = new URLSearchParams(window.location.search);
+const KEYCODE_Q     = 81
+const KEYCODE_ENTER = 13
 
-var scene = urlParams.get('scene')
-var expe  = urlParams.get('expe')
+urlParams = new URLSearchParams(window.location.search)
 
-function checkKey(e) {
+const scene = urlParams.get('scene')
+const expe  = urlParams.get('expe')
 
-   e = e || window.event;
+const checkKey = e => {
+     if (e.keyCode === KEYCODE_Q) {
+          // `q` to quit expe
+          console.log('`q` key is pressed')
+          window.location = ''
+     }
+     else if (e.keyCode === KEYCODE_ENTER) {
+          // right arrow
+          const params = `?scene=${scene}&expe=${expe}&iteration=0`
+          console.log(expeUrl + params)
+          window.location = expeUrl + params
+     }
+}
 
-   if (e.keyCode == KEYCODE_Q) {
-        // `q` for quit expe
-        console.log('`q` key is pressed')
-        window.location = ''
-   }
-   else if (e.keyCode == KEYCODE_ENTER) {
-
-        // right arrow
-        var params = "?scene=" + scene + "&expe=" + expe + "&iteration=0"
-        console.log(expeUrl + params)
-        window.location = expeUrl + params
-   }
-}
+// implement `key` events
+document.addEventListener('keydown', checkKey)