Skip to content

Commit

Permalink
work around missing Array#indexOf on IE. fixes madrobby#14.
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Sep 1, 2011
1 parent 29fc18c commit a1c1654
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions keymaster.js
Expand Up @@ -27,6 +27,13 @@

for(k=1;k<20;k++) _MODIFIERS['f'+k] = 111+k;

// IE doesn't support Array#indexOf, so have a simple replacement
function index(array, item){
var i = array.length;
while(i--) if(array[i]===item) return i;
return -1;
}

// handle keydown event
function dispatch(event){
var key, tagName, handler, k, i, modifiersMatch;
Expand Down Expand Up @@ -57,8 +64,8 @@
// check if modifiers match if any
modifiersMatch = handler.mods.length > 0;
for(k in _mods)
if((!_mods[k] && handler.mods.indexOf(+k) > -1) ||
(_mods[k] && handler.mods.indexOf(+k) == -1)) modifiersMatch = false;
if((!_mods[k] && index(handler.mods, +k) > -1) ||
(_mods[k] && index(handler.mods, +k) == -1)) modifiersMatch = false;
// call the handler and stop the event if neccessary
if((handler.mods.length == 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91]) || modifiersMatch){
if(handler.method(event, handler)===false){
Expand Down
2 changes: 1 addition & 1 deletion keymaster.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1c1654

Please sign in to comment.