From 8961a2ee28b3c33e47302fda66dcd6b1a4dde101 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Fri, 7 Mar 2014 01:24:36 -0500 Subject: [PATCH] Simplify characterCode lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce String.fromCharCode that can’t be optimized by the minifier. --- .../javascripts/discourse/lib/autocomplete.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js b/app/assets/javascripts/discourse/lib/autocomplete.js index b89d9a6ef21..a1a68e919a2 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js +++ b/app/assets/javascripts/discourse/lib/autocomplete.js @@ -31,19 +31,16 @@ shiftMap[32] = " "; function mapKeyPressToActualCharacter(isShiftKey, characterCode) { if ( characterCode === 27 || characterCode === 8 || characterCode === 9 || characterCode === 20 || characterCode === 16 || characterCode === 17 || characterCode === 91 || characterCode === 13 || characterCode === 92 || characterCode === 18 ) { return false; } - if (isShiftKey) { - if ( characterCode >= 65 && characterCode <= 90 ) { - return String.fromCharCode(characterCode); - } else { - return shiftMap[characterCode]; - } - } else { - if ( characterCode >= 65 && characterCode <= 90 ) { - return String.fromCharCode(characterCode).toLowerCase(); - } else { - return String.fromCharCode(characterCode); - } + // Lookup non-letter keypress while holding shift + if (isShiftKey && ( characterCode < 65 || characterCode > 90 )) { + return shiftMap[characterCode]; } + + var stringValue = String.fromCharCode(characterCode); + if ( !isShiftKey ) { + stringValue = stringValue.toLowerCase(); + } + return stringValue; } $.fn.autocomplete = function(options) {