From 6772fcd8514cf307d686521929ef08d91494765e Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 28 Dec 2016 22:59:06 +0100 Subject: [PATCH] Use EventKey module instead of event.charCode This also fixes Firefox not having `event.charCode = 13` for enter events. --- .../install/files/js/WoltLabSuite/Core/Event/Key.js | 10 ++++++++++ .../install/files/js/WoltLabSuite/Core/Media/Editor.js | 7 +++---- .../files/js/WoltLabSuite/Core/Media/Manager/Search.js | 5 ++--- .../install/files/js/WoltLabSuite/Core/Ui/ItemList.js | 5 ++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Key.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Key.js index 4912826a04..259277fed4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Key.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Key.js @@ -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'. * diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js index e1a2635dfb..916929cc25 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js @@ -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(); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Search.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Search.js index d7282e693a..5ab80cc0ad 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Search.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Search.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @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'); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js index c6f6078a43..50fb25c7a8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @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) { -- 2.20.1