Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useCapture capability #400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions mousetrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@
* @param {Function} callback
* @returns void
*/
function _addEvent(object, type, callback) {
function _addEvent(object, type, callback, useCapture) {
if (object.addEventListener) {
object.addEventListener(type, callback, false);
object.addEventListener(type, callback, useCapture);
return;
}

Expand Down Expand Up @@ -432,10 +432,11 @@
return _belongsTo(element.parentNode, ancestor);
}

function Mousetrap(targetElement) {
function Mousetrap(targetElement, useCapture) {
var self = this;

targetElement = targetElement || document;
useCapture = !!useCapture;

if (!(self instanceof Mousetrap)) {
return new Mousetrap(targetElement);
Expand Down Expand Up @@ -886,9 +887,9 @@
};

// start!
_addEvent(targetElement, 'keypress', _handleKeyEvent);
_addEvent(targetElement, 'keydown', _handleKeyEvent);
_addEvent(targetElement, 'keyup', _handleKeyEvent);
_addEvent(targetElement, 'keypress', _handleKeyEvent, useCapture);
_addEvent(targetElement, 'keydown', _handleKeyEvent, useCapture);
_addEvent(targetElement, 'keyup', _handleKeyEvent, useCapture);
}

/**
Expand Down