October: Update Deprecated code in October (event.key) Updates and Testing

Created on 6 Jul 2019  路  6Comments  路  Source: octobercms/october

To make things easier I have created this github issue and then will create a bunch of Pr's and connect them to this issue. Probably will take quite long to test each file etc.

Update File List

October CMS Files

event.keyCode (deprecated)

event.which (deprecated)

Third-party (Vendor) Files

event.keyCode (deprecated)

event.which (deprecated)


event.charCode (deprecated)

Already 100% removed from October CMS.

Reason for updating

  1. Vanilla Javascript event.keyCode is deprecated, see here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keycode

  2. jQuery event.keyCode is deprecated, see here: https://github.com/jquery/jquery/issues/2667

  3. Vanilla Javascript event.charCode is deprecated, see here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode

  4. jQuery event.charCode is deprecated, see here: https://github.com/jquery/jquery/issues/2667

  5. Vanilla Javascript event.which is deprecated, see here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which

  6. jQuery event.which is deprecated, see here: https://github.com/jquery/api.jquery.com/issues/821

Therefore we should switch to using: KeyboardEvent.key

Browser Support: https://caniuse.com/#feat=keyboardevent-key

W3c Spec: https://www.w3.org/TR/uievents/#dom-keyboardevent-key

Have tested it and works on most new browsers.

There is an issue with Edge and IE11, see here: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11509049/

Polyfill

Most web browsers now accept event.key, the only problem browsers are old Safari, Edge and IE11. I have already added a Polyfill which fixes those browsers and gives 100% support. The file can be found here: https://github.com/octobercms/october/blob/628551ec53a6d9fec1315dc437f7e83db4abad6a/modules/system/assets/ui/vendor/keyboardevent-key-polyfill/index.js

The Polyfill is also Initialize in that file location so you don't need to do anything, October CMS will take care of backwards compatibility issues.

Third-Party Vendors

When updating third-party vendor files, please also send a pr to their repo. We will have to make a note of these files, to prevent any issues when updating third-party files in the future.

Useful Tools when updating the Code

Please note also that: event.key === 'a' is not the same as event.key === 'A'

Testing and Help

As there are so many files, it will require a lot of time testing and updating - request help! You use October CMS and probably want the CMS to work properly for you, now is the time to help out.

Thanks.

Completed Maintenance

All 6 comments

@ayumihamsaki Is the syntax for event.key the same as event.keyCode? Quite a few of the listed files are from third-party vendors (such as Select2, Bootstrap, SweetAlert, etc.), and I'm not sure we should be changing those when a) we don't know what effects it will have on those libraries and b) if we upgrade them in the future, we'd have to make the same change(s) again if they have not yet done so on their end.

I agree with @bennothommo, @ayumihamsaki could you remove from your list vendor specific files.

@ayumihamsaki please don't make separate PRs for each file, just make them all under one.

How to keep everyone happy here, what I can do is create a single pr to fix all the non-third party vendors files and then fix them at a later date and keep this issue open.

Useful Link: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values

  • Space bar is a bit of a headache, I did some research on it 2 days ago and came to the conclusion you need three fields. This is what I found out:

Future propsoal - (Space character)
Current proposal -
Passed propsal (older browsers e.g. IE11) - Spacebar

Was this page helpful?
0 / 5 - 0 ratings