From c6b74361390d29a0e0a07200962354cec3ec22e4 Mon Sep 17 00:00:00 2001 From: Fabrice Daugan Date: Thu, 27 Mar 2014 20:51:22 +0100 Subject: [PATCH 1/3] Fix evt.keyCode usage on IE6,7 On IE7- keyCode property is does not correspond to the key code. The fixed issue is relevant on IE7. The 't' key, keyCode on IE7 is equal to 116, so is mapped to F5 key. So, using {999} patern allows digit and 't' key since isSpecialKey(key) return true. --- src/formatter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter.js b/src/formatter.js index 581d5ca..6ac9507 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -182,7 +182,7 @@ Formatter.prototype._keyPress = function (evt) { if (evt.which) { k = evt.which; } else { - k = evt.keyCode; + k = (window.event) ? evt.which : evt.keyCode; isSpecial = utils.isSpecialKey(k); } // Process the keyCode and prevent default From cebf8803d40f6e870918954bc6823b31ef1a02c3 Mon Sep 17 00:00:00 2001 From: Fabrice Daugan Date: Fri, 28 Mar 2014 14:48:57 +0100 Subject: [PATCH 2/3] Fix evt.keyCode usage on IE6,7 I found the issue for keyPress/keyDown. http://www.west-wind.com/WestwindWebToolkit/samples/Ajax/html5andCss3/keycodechecker.aspx For keypress event does not map the keycode as keydown event. Why are there 2 key event managements? Any way, I've tested this PR on IE7, FF, Chrome and IE11. --- src/formatter.js | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/formatter.js b/src/formatter.js index 6ac9507..3a4b70a 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -70,9 +70,6 @@ function Formatter(el, opts) { utils.addListener(self.el, 'keydown', function (evt) { self._keyDown(evt); }); - utils.addListener(self.el, 'keypress', function (evt) { - self._keyPress(evt); - }); utils.addListener(self.el, 'paste', function (evt) { self._paste(evt); }); @@ -167,26 +164,10 @@ Formatter.prototype._keyDown = function (evt) { this._processKey(null, k); return utils.preventDefault(evt); } -}; - -// -// @private -// Handler called on all keyPress strokes. Only processes -// character keys (as long as no modifier key is in use). -// -Formatter.prototype._keyPress = function (evt) { - // The first thing we need is the character code - var k, isSpecial; - // Mozilla will trigger on special keys and assign the the value 0 - // We want to use that 0 rather than the keyCode it assigns. - if (evt.which) { - k = evt.which; - } else { - k = (window.event) ? evt.which : evt.keyCode; - isSpecial = utils.isSpecialKey(k); - } - // Process the keyCode and prevent default - if (!utils.isDelKey(k) && !isSpecial && !utils.isModifier(evt)) { + + // Process the keyCode and prevent default + var isSpecial = utils.isSpecialKey(k); + if (!isSpecial && !utils.isModifier(evt)) { this._processKey(String.fromCharCode(k), false); return utils.preventDefault(evt); } From 34201909f174772a57255fac0a4ea87603f0996c Mon Sep 17 00:00:00 2001 From: Fabrice Daugan Date: Wed, 2 Apr 2014 13:36:09 +0200 Subject: [PATCH 3/3] Update formatter.js --- src/formatter.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/formatter.js b/src/formatter.js index 3a4b70a..581d5ca 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -70,6 +70,9 @@ function Formatter(el, opts) { utils.addListener(self.el, 'keydown', function (evt) { self._keyDown(evt); }); + utils.addListener(self.el, 'keypress', function (evt) { + self._keyPress(evt); + }); utils.addListener(self.el, 'paste', function (evt) { self._paste(evt); }); @@ -164,10 +167,26 @@ Formatter.prototype._keyDown = function (evt) { this._processKey(null, k); return utils.preventDefault(evt); } - - // Process the keyCode and prevent default - var isSpecial = utils.isSpecialKey(k); - if (!isSpecial && !utils.isModifier(evt)) { +}; + +// +// @private +// Handler called on all keyPress strokes. Only processes +// character keys (as long as no modifier key is in use). +// +Formatter.prototype._keyPress = function (evt) { + // The first thing we need is the character code + var k, isSpecial; + // Mozilla will trigger on special keys and assign the the value 0 + // We want to use that 0 rather than the keyCode it assigns. + if (evt.which) { + k = evt.which; + } else { + k = evt.keyCode; + isSpecial = utils.isSpecialKey(k); + } + // Process the keyCode and prevent default + if (!utils.isDelKey(k) && !isSpecial && !utils.isModifier(evt)) { this._processKey(String.fromCharCode(k), false); return utils.preventDefault(evt); }