]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Use existing keycode constants in dropdown. (#21697)
authorPierre-Denis Vanduynslager <pierre.denis.vanduynslager@gmail.com>
Sun, 15 Jan 2017 02:42:24 +0000 (21:42 -0500)
committerBardi Harborow <bardi@bardiharborow.com>
Sun, 15 Jan 2017 02:42:24 +0000 (13:42 +1100)
js/src/dropdown.js

index 36305df46864dcb046fe6455cab13aea9e1f2ff3..1660d425755cd937fc669a81d669c30b01aec0cf 100644 (file)
@@ -24,9 +24,11 @@ const Dropdown = (($) => {
   const DATA_API_KEY             = '.data-api'
   const JQUERY_NO_CONFLICT       = $.fn[NAME]
   const ESCAPE_KEYCODE           = 27 // KeyboardEvent.which value for Escape (Esc) key
+  const SPACE_KEYCODE            = 32 // KeyboardEvent.which value for space key
   const ARROW_UP_KEYCODE         = 38 // KeyboardEvent.which value for up arrow key
   const ARROW_DOWN_KEYCODE       = 40 // KeyboardEvent.which value for down arrow key
   const RIGHT_MOUSE_BUTTON_WHICH = 3 // MouseEvent.which value for the right button (assuming a right-handed mouse)
+  const REGEXP_KEYDOWN = new RegExp(`${ARROW_UP_KEYCODE}|${ARROW_DOWN_KEYCODE}|${ESCAPE_KEYCODE}|${SPACE_KEYCODE}`)
 
   const Event = {
     HIDE             : `hide${EVENT_KEY}`,
@@ -213,7 +215,7 @@ const Dropdown = (($) => {
     }
 
     static _dataApiKeydownHandler(event) {
-      if (!/(38|40|27|32)/.test(event.which) ||
+      if (!REGEXP_KEYDOWN.test(event.which) ||
          /input|textarea/i.test(event.target.tagName)) {
         return
       }