Closed sqrtroot closed 8 years ago
What kind of error were you getting on Chrome? I've never heard or experienced this issue before, but I am seeing how we could rewrite that line now.
@georgemandis the plugin didn't work on chrome for me (chrome on pc and chrome on mobile), it just didn't register my key events. This fixed that.
Per the MDN keyCode
should not be used:
Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
Also:
The value of
keypress
event is different between browsers. IE and Google Chrome set theKeyboardEvent.charCode
value.
This whole issue is a lot more interesting than I thought. Per the MDN it looks like all the following shouldn't be used anymore:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which
It appears the properties it would want us to use are either:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
But those don't seem to have a lot of browser support. They require rewriting other parts of the code as well because it'd be returning a string instead of a number ("ArrowUp" vs 38).
Frustratingly, it also appears that Safari/Webkit doesn't support either of these new properties — code
will work on Chrome and Firefox and key
only on Firefox and IE9+.
Future-proofing the script to account for those properties should probably happen at some point, but I'd want to wait until one or the other gains more cross-browser traction.
As for your specific problem, a couple things:
konami.input += e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
Technically we shouldn't be using either per MDN, I guess, but I'm assuming for your code change that keyCode
wasn't working for you. It seems to me it should be more like
konami.input += e.keyCode ? e.keyCode : e.charCode;
I don't think there should be a scenario where we're returning zero.
If my earlier link is working correctly for you then I think it must be something else in the code on the page you were working on that created the problem. In that case I would not merge this pull request, but I would be happy to continue discussing what an update to "future-proof" this might look like.
hmm on the page you did send me it works, on my live page it didn't work strange. I think I'll keep it as a fix for my own page. and close this one. Future proofing might be a good idea IF the api's stabilize
Sounds like there's something else going on with your page that may have been breaking things. If you wanted to link to it I'd be happy to take a look and help. Curious why it would break or why your fix would fix it!
Agree on the future-proofing. I'll open an issue and reference this conversation and maybe someone, somewhere, someday will tend to it... :)
Chrome input didn't work- fixed