Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'js/dist/dom/event-handler.js')
-rw-r--r--js/dist/dom/event-handler.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/js/dist/dom/event-handler.js b/js/dist/dom/event-handler.js
index 428a1df895..efa0cb7118 100644
--- a/js/dist/dom/event-handler.js
+++ b/js/dist/dom/event-handler.js
@@ -1,5 +1,5 @@
/*!
- * Bootstrap event-handler.js v5.0.0-beta3 (https://getbootstrap.com/)
+ * Bootstrap event-handler.js v5.0.0 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
@@ -11,7 +11,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.0-beta3): util/index.js
+ * Bootstrap (v5.0.0): util/index.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -30,7 +30,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.0-beta3): dom/event-handler.js
+ * Bootstrap (v5.0.0): dom/event-handler.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -50,6 +50,7 @@
mouseenter: 'mouseover',
mouseleave: 'mouseout'
};
+ const customEventsRegex = /^(mouseenter|mouseleave)/i;
const nativeEvents = new Set(['click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu', 'mousewheel', 'DOMMouseScroll', 'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend', 'keydown', 'keypress', 'keyup', 'orientationchange', 'touchstart', 'touchmove', 'touchend', 'touchcancel', 'pointerdown', 'pointermove', 'pointerup', 'pointerleave', 'pointercancel', 'gesturestart', 'gesturechange', 'gestureend', 'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout', 'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange', 'error', 'abort', 'scroll']);
/**
* ------------------------------------------------------------------------
@@ -93,7 +94,7 @@
if (handler.oneOff) {
// eslint-disable-next-line unicorn/consistent-destructuring
- EventHandler.off(element, event.type, fn);
+ EventHandler.off(element, event.type, selector, fn);
}
return fn.apply(target, [event]);
@@ -122,15 +123,8 @@
function normalizeParams(originalTypeEvent, handler, delegationFn) {
const delegation = typeof handler === 'string';
- const originalHandler = delegation ? delegationFn : handler; // allow to get the native events from namespaced events ('click.bs.button' --> 'click')
-
- let typeEvent = originalTypeEvent.replace(stripNameRegex, '');
- const custom = customEvents[typeEvent];
-
- if (custom) {
- typeEvent = custom;
- }
-
+ const originalHandler = delegation ? delegationFn : handler;
+ let typeEvent = getTypeEvent(originalTypeEvent);
const isNative = nativeEvents.has(typeEvent);
if (!isNative) {
@@ -148,6 +142,24 @@
if (!handler) {
handler = delegationFn;
delegationFn = null;
+ } // in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position
+ // this prevents the handler from being dispatched the same way as mouseover or mouseout does
+
+
+ if (customEventsRegex.test(originalTypeEvent)) {
+ const wrapFn = fn => {
+ return function (event) {
+ if (!event.relatedTarget || event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget)) {
+ return fn.call(this, event);
+ }
+ };
+ };
+
+ if (delegationFn) {
+ delegationFn = wrapFn(delegationFn);
+ } else {
+ handler = wrapFn(handler);
+ }
}
const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn);
@@ -191,6 +203,12 @@
});
}
+ function getTypeEvent(event) {
+ // allow to get the native events from namespaced events ('click.bs.button' --> 'click')
+ event = event.replace(stripNameRegex, '');
+ return customEvents[event] || event;
+ }
+
const EventHandler = {
on(element, event, handler, delegationFn) {
addHandler(element, event, handler, delegationFn, false);
@@ -243,7 +261,7 @@
}
const $ = getjQuery();
- const typeEvent = event.replace(stripNameRegex, '');
+ const typeEvent = getTypeEvent(event);
const inNamespace = event !== typeEvent;
const isNative = nativeEvents.has(typeEvent);
let jQueryEvent;