From c80e13a48a50caecc3e0c7b2904655e8bdc95d9c Mon Sep 17 00:00:00 2001 From: Pierre-Denis Vanduynslager Date: Sat, 14 Jan 2017 21:42:24 -0500 Subject: Use existing keycode constants in dropdown. (#21697) --- js/src/dropdown.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/src') diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 36305df46..1660d4257 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -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 } -- cgit v1.2.3 From 8fbd4aaa383e3506d2da3c2335eeb66f494f07ad Mon Sep 17 00:00:00 2001 From: Pierre-Denis Vanduynslager Date: Sat, 14 Jan 2017 21:46:03 -0500 Subject: Correct reference to Direction.PREV constant. (#21709) --- js/src/carousel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/src') diff --git a/js/src/carousel.js b/js/src/carousel.js index d27600c40..8a75cb240 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -137,7 +137,7 @@ const Carousel = (($) => { if (this._isSliding) { throw new Error('Carousel is sliding') } - this._slide(Direction.PREVIOUS) + this._slide(Direction.PREV) } pause(event) { @@ -195,7 +195,7 @@ const Carousel = (($) => { const direction = index > activeIndex ? Direction.NEXT : - Direction.PREVIOUS + Direction.PREV this._slide(direction, this._items[index]) } @@ -263,7 +263,7 @@ const Carousel = (($) => { _getItemByDirection(direction, activeElement) { const isNextDirection = direction === Direction.NEXT - const isPrevDirection = direction === Direction.PREVIOUS + const isPrevDirection = direction === Direction.PREV const activeIndex = this._getItemIndex(activeElement) const lastItemIndex = this._items.length - 1 const isGoingToWrap = isPrevDirection && activeIndex === 0 || @@ -273,7 +273,7 @@ const Carousel = (($) => { return activeElement } - const delta = direction === Direction.PREVIOUS ? -1 : 1 + const delta = direction === Direction.PREV ? -1 : 1 const itemIndex = (activeIndex + delta) % this._items.length return itemIndex === -1 ? -- cgit v1.2.3