mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Key handlers: allow the user to prevent the default behaviour of key events.
This commit is contained in:
parent
1efb69e46f
commit
e52ed9ae36
1 changed files with 14 additions and 2 deletions
|
@ -42,12 +42,24 @@ var Key = new function() {
|
||||||
// Call the onKeyDown or onKeyUp handler if present:
|
// Call the onKeyDown or onKeyUp handler if present:
|
||||||
// TODO: don't call the key handler if the key is a modifier?
|
// TODO: don't call the key handler if the key is a modifier?
|
||||||
if (paper.tool[toolHandler]) {
|
if (paper.tool[toolHandler]) {
|
||||||
paper.tool[toolHandler]({
|
var preventDefault = paper.tool[toolHandler]({
|
||||||
type: keyDown ? 'key-down' : 'key-up',
|
type: keyDown ? 'key-down' : 'key-up',
|
||||||
keyCode: code,
|
keyCode: code,
|
||||||
character: key,
|
character: key,
|
||||||
modifiers: modifiers
|
modifiers: modifiers,
|
||||||
|
// 'preventDefault: event.preventDefault' throws
|
||||||
|
// an error in Safari when called, so we have to wrap
|
||||||
|
// it into a function.
|
||||||
|
// TODO: port to Scriptographer.
|
||||||
|
preventDefault: function() {
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
// TODO: port to Scriptographer:
|
||||||
|
// When the handler function returns false, prevent the
|
||||||
|
// default behaviour of the key event:
|
||||||
|
if (preventDefault === false)
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, {});
|
}, {});
|
||||||
|
|
Loading…
Reference in a new issue