Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[BUG #4983] Add getKeyIdentifier() method to keyboard events

  • Loading branch information...
commit 0f5acf178983658f020e27cb2eb16004af2ef607 1 parent ca45fd6
Daniel Wagner danielwagner authored
1  component/standalone/website/config.json
@@ -44,6 +44,7 @@
44 44 "qx.module.Event",
45 45 "qx.module.event.Native",
46 46 "qx.module.event.Mouse",
  47 + "qx.module.event.Keyboard",
47 48 "qx.module.Template",
48 49 "qx.module.Polyfill",
49 50 "q"
37 component/standalone/website/test/tests.js
@@ -1222,6 +1222,43 @@ testrunner.define({
1222 1222 });
1223 1223
1224 1224 testrunner.define({
  1225 + classname : "event.Keyboard",
  1226 +
  1227 + setUp : testrunner.globalSetup,
  1228 + tearDown : testrunner.globalTeardown,
  1229 +
  1230 + testEventNormalization : function()
  1231 + {
  1232 + var eventTypes = qx.module.event.Keyboard.TYPES;
  1233 + this.assertArray(eventTypes);
  1234 + this.assert(eventTypes.length > 0);
  1235 + var registry = qx.module.Event.getRegistry();
  1236 + for (var i=0,l=eventTypes.length; i<l; i++) {
  1237 + this.assertKeyInMap(eventTypes[i], registry);
  1238 + }
  1239 + },
  1240 +
  1241 + testEventMethods : function()
  1242 + {
  1243 + var test = q.create("<div id='foo'></div>");
  1244 + test.appendTo(this.sandbox[0]);
  1245 +
  1246 + var obj = {};
  1247 +
  1248 + q("#sandbox #foo").on("keydown", function(ev) {
  1249 + this.keyIdentifier = ev.getKeyIdentifier();
  1250 + }, obj);
  1251 +
  1252 + q("#sandbox #foo").emit("keydown", {
  1253 + keyCode: 27
  1254 + });
  1255 +
  1256 + this.assertEquals("Escape", obj.keyIdentifier);
  1257 + }
  1258 +});
  1259 +
  1260 +
  1261 +testrunner.define({
1225 1262 classname : "Templates",
1226 1263
1227 1264 setUp : testrunner.globalSetup,
31 framework/source/class/qx/module/event/Keyboard.js
... ... @@ -0,0 +1,31 @@
  1 +qx.Bootstrap.define("qx.module.event.Keyboard", {
  2 + statics :
  3 + {
  4 + TYPES : ["keydown", "keypress", "keyup"],
  5 +
  6 + BIND_METHODS : ["getKeyIdentifier"],
  7 +
  8 + getKeyIdentifier : function()
  9 + {
  10 + return qx.event.util.Keyboard.keyCodeToIdentifier(this.keyCode);
  11 + },
  12 +
  13 + normalize : function(event, element) {
  14 + if (!event) {
  15 + return event;
  16 + }
  17 + var bindMethods = qx.module.event.Keyboard.BIND_METHODS;
  18 + for (var i=0, l=bindMethods.length; i<l; i++) {
  19 + if (typeof event[bindMethods[i]] != "function") {
  20 + event[bindMethods[i]] = qx.module.event.Keyboard[bindMethods[i]].bind(event);
  21 + }
  22 + }
  23 +
  24 + return event;
  25 + }
  26 + },
  27 +
  28 + defer : function(statics) {
  29 + q.registerEventNormalization(qx.module.event.Keyboard.TYPES, statics.normalize);
  30 + }
  31 +});

0 comments on commit 0f5acf1

Please sign in to comment.
Something went wrong with that request. Please try again.