Use EventKey module instead of event.charCode
authorMatthias Schmidt <gravatronics@live.com>
Wed, 28 Dec 2016 21:59:06 +0000 (22:59 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 28 Dec 2016 21:59:09 +0000 (22:59 +0100)
This also fixes Firefox not having `event.charCode = 13` for enter
events.

wcfsetup/install/files/js/WoltLabSuite/Core/Event/Key.js
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Search.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js

index 4912826a041f4da46b1fbcc4bf66207b40245a87..259277fed42f2d509d4408855621fd5ed2fae6b4 100644 (file)
@@ -62,6 +62,16 @@ define([], function() {
                        return _isKey(event, 'ArrowUp', 38);
                },
                
+               /**
+                * Returns true if pressed key equals 'Comma'.
+                * 
+                * @param       {Event}         event           event object
+                * @return      {boolean}
+                */
+               Comma: function(event) {
+                       return _isKey(event, ',', 44);
+               },
+               
                /**
                 * Returns true if pressed key equals 'Enter'.
                 * 
index e1a2635dfb2827d9fbb7d284447faf8651a4c9f9..916929cc25f032a1ae71f47fc10a2658c1b4c80e 100644 (file)
@@ -10,12 +10,12 @@ define(
        [
                'Ajax',                         'Core',                       'Dictionary',          'Dom/ChangeListener',
                'Dom/Traverse',                 'Language',                   'Ui/Dialog',           'Ui/Notification',
-               'WoltLabSuite/Core/Language/Chooser', 'WoltLabSuite/Core/Language/Input'
+               'WoltLabSuite/Core/Language/Chooser', 'WoltLabSuite/Core/Language/Input', 'EventKey'
        ],
        function(
                Ajax,                            Core,                         Dictionary,            DomChangeListener,
                DomTraverse,                     Language,                     UiDialog,              UiNotification,
-               LanguageChooser,                 LanguageInput
+               LanguageChooser,                 LanguageInput,                EventKey
        )
 {
        "use strict";
@@ -87,8 +87,7 @@ define(
                 * @param       {object}        event           event object
                 */
                _keyPress: function(event) {
-                       // 13 = [ENTER]
-                       if (event.charCode === 13) {
+                       if (EventKey.Enter(event)) {
                                event.preventDefault();
                                
                                this._saveData();
index d7282e693a85f0523ef3724663833c11fdf3b371..5ab80cc0ad29c18296dccf60de7ec1d18dfa5033 100644 (file)
@@ -6,7 +6,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLabSuite/Core/Media/Manager/Search
  */
-define(['Ajax', 'Core', 'Dom/Traverse', 'Dom/Util', 'Language', 'Ui/SimpleDropdown'], function(Ajax, Core, DomTraverse, DomUtil, Language, UiSimpleDropdown) {
+define(['Ajax', 'Core', 'Dom/Traverse', 'Dom/Util', 'EventKey', 'Language', 'Ui/SimpleDropdown'], function(Ajax, Core, DomTraverse, DomUtil, EventKey, Language, UiSimpleDropdown) {
        "use strict";
        
        /**
@@ -65,8 +65,7 @@ define(['Ajax', 'Core', 'Dom/Traverse', 'Dom/Util', 'Language', 'Ui/SimpleDropdo
                 * @param       {Event}         event           event object
                 */
                _keyPress: function(event) {
-                       // 13 = [ENTER]
-                       if (event.charCode === 13) {
+                       if (EventKey.Enter(event)) {
                                event.preventDefault();
                                
                                var innerInfo = DomTraverse.childByClass(this._input.parentNode.parentNode, 'innerInfo');
index c6f6078a43d8781d301d126c7a3889b5d55bcd32..50fb25c7a89a7298aeab83dcbe20a90897aa4954 100644 (file)
@@ -6,7 +6,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLabSuite/Core/Ui/ItemList
  */
-define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'WoltLabSuite/Core/Ui/Suggestion'], function(Core, Dictionary, Language, DomTraverse, UiSuggestion) {
+define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'WoltLabSuite/Core/Ui/Suggestion'], function(Core, Dictionary, Language, DomTraverse, EventKey, UiSuggestion) {
        "use strict";
        
        var _activeId = '';
@@ -329,8 +329,7 @@ define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'WoltLabSuite/Core/Ui/
                 * @param       {object}        event           event object
                 */
                _keyPress: function(event) {
-                       // 13 = [ENTER], 44 = [,]
-                       if (event.charCode == 13 || event.charCode == 44) {
+                       if (EventKey.Enter(event) || EventKey.Comma(event)) {
                                event.preventDefault();
                                
                                if (_data.get(event.currentTarget.id).options.restricted) {