From ccbdb2abe322537d5bf2dd4c4f25ba542c92c4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 27 Apr 2011 12:41:52 +0100 Subject: [PATCH] Make preventDefault() work on IE too. --- src/ui/Key.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ui/Key.js b/src/ui/Key.js index 22c9cdc8..aa0db58a 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -42,7 +42,8 @@ var Key = new function() { // Call the onKeyDown or onKeyUp handler if present: // TODO: don't call the key handler if the key is a modifier? if (paper.tool[toolHandler]) { - var preventDefault = paper.tool[toolHandler]({ + // TODO: Introduce a class for this? + var keyEvent = { type: keyDown ? 'key-down' : 'key-up', keyCode: code, character: key, @@ -52,14 +53,19 @@ var Key = new function() { // it into a function. // TODO: Port to Scriptographer: preventDefault: function() { - event.preventDefault() + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } } - }); + } + var res = paper.tool[toolHandler](keyEvent); // TODO: Port to Scriptographer: // When the handler function returns false, prevent the // default behaviour of the key event: - if (preventDefault === false) - event.preventDefault(); + if (res === false) + keyEvent.preventDefault(); } }; }, {});