issue #22500: make hack as reasonable as possible
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Fri, 24 Jan 2014 20:16:14 +0000 (15:16 -0500)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Fri, 24 Jan 2014 20:16:14 +0000 (15:16 -0500)
lib/enyo-x/source/app.js
lib/tools/source/foundation.js

index 67357d1..4eb74bf 100644 (file)
@@ -44,17 +44,23 @@ white:true*/
     */
     handleKeyDown: function (inSender, inEvent) {
       var that = this,
-        keyCode = inEvent.keyCode;
+        keyCode = inEvent.keyCode,
+        exoticTransforms = {},
+        numberShiftCharacters = ")!@#$%^&*(";
 
-      // XXX start hacks
-      if (keyCode === 189) {
-        // Dashes aren't coming through as dashes from my keyboard
-        keyCode = '-'.charCodeAt(0);
-      } else if (keyCode === 56 && inEvent.shiftKey) {
-        // there's gotta be a way to know that shift-8 is *
-        keyCode = '*'.charCodeAt(0);
+      // exotic transforms. sorta hackish, but the inEvent codes coming
+      // through are not always the ones we want
+
+      // http://stackoverflow.com/questions/1898129/javascript-subtract-keycode
+      exoticTransforms[XT.ASCII.VULGAR_HALF] = XT.ASCII.N_DASH;
+      if (_.contains(Object.keys(exoticTransforms), "" + keyCode)) {
+        // account for inexplicably wrongly mapped keys
+        keyCode = exoticTransforms[keyCode];
+      } else if (inEvent.shiftKey && keyCode >= XT.ASCII.ZERO && keyCode <= XT.ASCII.NINE) {
+        // shift-number should be transformed into the appropriate character
+        // XXX jingoistic implementation
+        keyCode = numberShiftCharacters.charCodeAt(keyCode - XT.ASCII.ZERO);
       }
-      // XXX end hacks
 
       // remember the last 10 key presses
       this._keyBufferArray.push(keyCode);
index 291149c..b586f32 100644 (file)
@@ -15,6 +15,14 @@ XT = typeof XT !== 'undefined' ? XT : {};
 
 _.extend(XT, /** @lends XT.Foundation# */{
 
+  ASCII: {
+    CARRIAGE_RETURN: 13,
+    N_DASH: 45,
+    ZERO: 48,
+    NINE: 57,
+    VULGAR_HALF: 189
+  },
+
   // This will be updated from the server when we start our session
   debugging: false,