diff options
| author | Johann-S <[email protected]> | 2021-02-17 08:22:44 +0100 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2021-09-15 16:42:04 +0200 |
| commit | d73d835380f793ab7ca40b82a6ce09ba8f5946c5 (patch) | |
| tree | 7c98a87a596ae937983498980afb6e2fa239ab53 /js/src/dropdown.js | |
| parent | bdfb4cc54d29c0c7bcd7944d3c8de2e1cd41bb6c (diff) | |
| download | bootstrap-jo-ssr-friendly.tar.xz bootstrap-jo-ssr-friendly.zip | |
being ssr friendly when accessing dom objectsjo-ssr-friendly
Diffstat (limited to 'js/src/dropdown.js')
| -rw-r--r-- | js/src/dropdown.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 874cf907b..32d65f335 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -17,7 +17,8 @@ import { isRTL, isVisible, noop, - typeCheckConfig + typeCheckConfig, + getDocument } from './util/index' import EventHandler from './dom/event-handler' import Manipulator from './dom/manipulator' @@ -151,9 +152,9 @@ class Dropdown extends BaseComponent { // empty mouseover listeners to the body's immediate children; // only needed because of broken event delegation on iOS // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html - if ('ontouchstart' in document.documentElement && + if ('ontouchstart' in this._document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) { - [].concat(...document.body.children) + [].concat(...this._document.body.children) .forEach(elem => EventHandler.on(elem, 'mouseover', noop)) } @@ -478,11 +479,13 @@ class Dropdown extends BaseComponent { * ------------------------------------------------------------------------ */ -EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler) -EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler) -EventHandler.on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus) -EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus) -EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { +const documentRef = getDocument() + +EventHandler.on(documentRef, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler) +EventHandler.on(documentRef, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler) +EventHandler.on(documentRef, EVENT_CLICK_DATA_API, Dropdown.clearMenus) +EventHandler.on(documentRef, EVENT_KEYUP_DATA_API, Dropdown.clearMenus) +EventHandler.on(documentRef, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { event.preventDefault() Dropdown.getOrCreateInstance(this).toggle() }) |
