Skip to content

Commit

Permalink
Merge pull request #263 from jongund/menu-button to remove keypress c…
Browse files Browse the repository at this point in the history
…harCode dependency

Addressess issue #249 for menu button examples.
  • Loading branch information
jongund authored and mcking65 committed Jan 30, 2017
1 parent a50306d commit 50a45b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
23 changes: 8 additions & 15 deletions examples/menu-button/menu-button-1/js/MenuItemAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ MenuItem.prototype.init = function () {
}

this.domNode.addEventListener('keydown', this.handleKeydown.bind(this));
this.domNode.addEventListener('keypress', this.handleKeypress.bind(this));
this.domNode.addEventListener('click', this.handleClick.bind(this));
this.domNode.addEventListener('focus', this.handleFocus.bind(this));
this.domNode.addEventListener('blur', this.handleBlur.bind(this));
Expand All @@ -67,9 +66,12 @@ MenuItem.prototype.init = function () {
MenuItem.prototype.handleKeydown = function (event) {
var tgt = event.currentTarget,
flag = false,
clickEvent;
char = event.key,
clickEvent;

// console.log("[MenuItem][handleKeydown]: " + event.keyCode + " " + this.menu)
function isPrintableCharacter (str) {
return str.length === 1 && str.match(/\S/);
}

switch (event.keyCode) {
case this.keyCode.SPACE:
Expand Down Expand Up @@ -140,6 +142,9 @@ MenuItem.prototype.handleKeydown = function (event) {
break;

default:
if (isPrintableCharacter(char)) {
this.menu.setFocusByFirstCharacter(this, char);
}
break;
}

Expand All @@ -149,18 +154,6 @@ MenuItem.prototype.handleKeydown = function (event) {
}
};

MenuItem.prototype.handleKeypress = function (event) {
var char = String.fromCharCode(event.charCode);

function isPrintableCharacter (str) {
return str.length === 1 && str.match(/\S/);
}

if (isPrintableCharacter(char)) {
this.menu.setFocusByFirstCharacter(this, char);
}
};

MenuItem.prototype.handleClick = function (event) {
this.menu.setFocusToController();
this.menu.close(true);
Expand Down
23 changes: 8 additions & 15 deletions examples/menu-button/menu-button-2/js/MenuItemLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ MenuItemLinks.prototype.init = function () {
}

this.domNode.addEventListener('keydown', this.handleKeydown.bind(this));
this.domNode.addEventListener('keypress', this.handleKeypress.bind(this));
this.domNode.addEventListener('click', this.handleClick.bind(this));
this.domNode.addEventListener('focus', this.handleFocus.bind(this));
this.domNode.addEventListener('blur', this.handleBlur.bind(this));
Expand All @@ -67,9 +66,12 @@ MenuItemLinks.prototype.init = function () {
MenuItemLinks.prototype.handleKeydown = function (event) {
var tgt = event.currentTarget,
flag = false,
clickEvent;
char = event.key,
clickEvent;

// Console.log("[MenuItemLinks][handleKeydown]: " + event.keyCode + " " + this.menu)
function isPrintableCharacter (str) {
return str.length === 1 && str.match(/\S/);
}

switch (event.keyCode) {
case this.keyCode.SPACE:
Expand Down Expand Up @@ -140,6 +142,9 @@ MenuItemLinks.prototype.handleKeydown = function (event) {
break;

default:
if (isPrintableCharacter(char)) {
this.menu.setFocusByFirstCharacter(this, char);
}
break;
}

Expand All @@ -149,18 +154,6 @@ MenuItemLinks.prototype.handleKeydown = function (event) {
}
};

MenuItemLinks.prototype.handleKeypress = function (event) {
var char = String.fromCharCode(event.charCode);

function isPrintableCharacter (str) {
return str.length === 1 && str.match(/\S/);
}

if (isPrintableCharacter(char)) {
this.menu.setFocusByFirstCharacter(this, char);
}
};

MenuItemLinks.prototype.handleClick = function (event) {
this.menu.setFocusToController();
this.menu.close(true);
Expand Down

0 comments on commit 50a45b3

Please sign in to comment.