Skip to content

Commit

Permalink
Prevent Firefox from interfering with quick find
Browse files Browse the repository at this point in the history
Execute preventDefault() for keys that qwerty-hancock handles, so that Firefox doesn't think that key should trigger the quick find bar - which prevents all further playing via keys.
  • Loading branch information
EugenDueck committed May 10, 2016
1 parent 646e860 commit d266de2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/qwerty-hancock.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@
* Handle a keyboard key being pressed.
* @param {object} key The keyboard event of the currently pressed key.
* @param {callback} callback The user's noteDown function.
* @return {boolean} true if it was a key (combo) used by qwerty-hancock
*/
var keyboardDown = function (key, callback) {
var key_pressed;

if (key.keyCode in keysDown) {
return;
return false;
}

keysDown[key.keyCode] = true;
Expand All @@ -413,13 +414,16 @@
// Call user's noteDown function.
callback(key_pressed, getFrequencyOfNote(key_pressed));
lightenUp(document.getElementById(key_pressed));
return true;
}
return false;
};

/**
* Handle a keyboard key being released.
* @param {element} key The DOM element of the key that was released.
* @param {callback} callback The user's noteDown function.
* @return {boolean} true if it was a key (combo) used by qwerty-hancock
*/
var keyboardUp = function (key, callback) {
var key_pressed;
Expand All @@ -431,7 +435,9 @@
// Call user's noteDown function.
callback(key_pressed, getFrequencyOfNote(key_pressed));
darkenDown(document.getElementById(key_pressed));
return true;
}
return false;
};

/**
Expand All @@ -454,15 +460,19 @@
if (isModifierKey(key)) {
return;
}
keyboardDown(key, that.keyDown);
if (keyboardDown(key, that.keyDown)) {
key.preventDefault();
}
});

// Key is released on keyboard.
globalWindow.addEventListener('keyup', function (key) {
if (isModifierKey(key)) {
return;
}
keyboardUp(key, that.keyUp);
if (keyboardUp(key, that.keyUp)) {
key.preventDefault();
}
});

// Mouse is clicked down on keyboard element.
Expand Down

0 comments on commit d266de2

Please sign in to comment.