1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-02 09:52:43 +02:00

Comply to the new rules.

This commit is contained in:
XhmikosR
2019-02-26 13:20:34 +02:00
parent 44e6abcba5
commit 46c037410b
44 changed files with 854 additions and 771 deletions

View File

@@ -35,6 +35,7 @@ const mapData = (() => {
if (keyProperties.key === key) {
return storeData[keyProperties.id]
}
return null
},
delete(element, key) {

View File

@@ -18,26 +18,61 @@ import Polyfill from './polyfill'
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
const keyEventRegex = /^key/
const stripUidRegex = /::\d+$/
const eventRegistry = {} // Events storage
let uidEvent = 1
const customEvents = {
const keyEventRegex = /^key/
const stripUidRegex = /::\d+$/
const eventRegistry = {} // Events storage
let uidEvent = 1
const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
}
const nativeEvents = [
'click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu',
'mousewheel', 'DOMMouseScroll',
'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend',
'keydown', 'keypress', 'keyup',
const nativeEvents = [
'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'
'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'
]
/**
@@ -60,7 +95,7 @@ function getEvent(element) {
function fixEvent(event, element) {
// Add which for key events
if (event.which === null && keyEventRegex.test(event.type)) {
event.which = event.charCode !== null ? event.charCode : event.keyCode
event.which = event.charCode === null ? event.keyCode : event.charCode
}
event.delegateTarget = element
@@ -81,7 +116,7 @@ function bootstrapDelegationHandler(element, selector, fn) {
return function handler(event) {
const domElements = element.querySelectorAll(selector)
for (let target = event.target; target && target !== this; target = target.parentNode) {
for (let { target } = event; target && target !== this; target = target.parentNode) {
for (let i = domElements.length; i--;) {
if (domElements[i] === target) {
fixEvent(event, target)
@@ -147,8 +182,8 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
}
const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn)
const events = getEvent(element)
const handlers = events[typeEvent] || (events[typeEvent] = {})
const events = getEvent(element)
const handlers = events[typeEvent] || (events[typeEvent] = {})
const previousFn = findHandler(handlers, originalHandler, delegation ? handler : null)
if (previousFn) {
@@ -158,7 +193,7 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
}
const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, ''))
const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(element, handler, delegationFn)
const fn = delegation ? bootstrapDelegationHandler(element, handler, delegationFn) : bootstrapHandler(element, handler)
fn.delegationSelector = delegation ? handler : null
fn.originalHandler = originalHandler
@@ -184,7 +219,7 @@ function removeNamespacedHandlers(element, events, typeEvent, namespace) {
const storeElementEvent = events[typeEvent] || {}
Object.keys(storeElementEvent)
.forEach((handlerKey) => {
.forEach(handlerKey => {
if (handlerKey.indexOf(namespace) > -1) {
const event = storeElementEvent[handlerKey]
@@ -224,14 +259,14 @@ const EventHandler = {
if (isNamespace) {
Object.keys(events)
.forEach((elementEvent) => {
.forEach(elementEvent => {
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.substr(1))
})
}
const storeElementEvent = events[typeEvent] || {}
Object.keys(storeElementEvent)
.forEach((keyHandlers) => {
.forEach(keyHandlers => {
const handlerKey = keyHandlers.replace(stripUidRegex, '')
if (!inNamespace || originalTypeEvent.indexOf(handlerKey) > -1) {
@@ -247,9 +282,9 @@ const EventHandler = {
return null
}
const typeEvent = event.replace(stripNameRegex, '')
const typeEvent = event.replace(stripNameRegex, '')
const inNamespace = event !== typeEvent
const isNative = nativeEvents.indexOf(typeEvent) > -1
const isNative = nativeEvents.indexOf(typeEvent) > -1
let jQueryEvent
let bubbles = true
@@ -279,7 +314,7 @@ const EventHandler = {
// merge custom informations in our event
if (typeof args !== 'undefined') {
Object.keys(args)
.forEach((key) => {
.forEach(key => {
Object.defineProperty(evt, key, {
get() {
return args[key]

View File

@@ -26,7 +26,7 @@ function normalizeData(val) {
}
function normalizeDataKey(key) {
return key.replace(/[A-Z]/g, (chr) => chr.toLowerCase())
return key.replace(/[A-Z]/g, chr => chr.toLowerCase())
}
const Manipulator = {
@@ -47,7 +47,7 @@ const Manipulator = {
...element.dataset
}
Object.keys(attributes).forEach((key) => {
Object.keys(attributes).forEach(key => {
attributes[key] = normalizeData(attributes[key])
})

View File

@@ -34,7 +34,7 @@ const Polyfill = (() => {
try {
element.querySelectorAll(':scope *')
} catch (e) {
} catch (error) {
return false
}

View File

@@ -16,8 +16,7 @@ import {
* ------------------------------------------------------------------------
*/
const findFn = Polyfill.find
const findOne = Polyfill.findOne
const { find: findFn, findOne } = Polyfill
const NODE_TEXT = 3
const SelectorEngine = {
@@ -48,7 +47,7 @@ const SelectorEngine = {
const children = makeArray(element.children)
return children.filter((child) => this.matches(child, selector))
return children.filter(child => this.matches(child, selector))
},
parents(element, selector) {