1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-19 11:51:23 +02:00

Release v5.0.0 (#33647)

* Bump version to 5.0.0

* Fix npm tag

* Dist
This commit is contained in:
XhmikosR
2021-05-05 22:32:12 +03:00
committed by GitHub
parent 48ae5a7149
commit bf09367486
113 changed files with 2497 additions and 2028 deletions

View File

@@ -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;