Commit 7c1d0a10 authored by Johann-S's avatar Johann-S Committed by XhmikosR
Browse files

Wrap our objects into IIFE

parent bcbea028
main cleanup-floating-forms cssvar-function dependabot/npm_and_yarn/stylelint-and-stylelint-config-twbs-bootstrap-15.3.0 extend-snippets feat/data-target floating-always-visible floating-labels-icons fod-main-banner form-controls-with-icons github/fork/719media/patch-13 github/fork/719media/patch-14 github/fork/719media/patch-9 github/fork/ChellyAhmed/fix-typo-reboot.md github/fork/ChellyAhmed/offcanvas-scroll-back github/fork/CtrlAltLilith/main github/fork/Elysiome/offcanvas-optional-window-resizing github/fork/JanSargsyan/main github/fork/LunicLynx/support-different-line-height-for-buttons github/fork/Psixodelik/main github/fork/Ronid1/ronid1/offcanvas_static_backdrop github/fork/RyanBerliner/tooltip-accessibility github/fork/SantiagoPVazquez/Feature-default-border-bottom-to-dropdown-item github/fork/Sir-Genius/utils github/fork/Sumit-Singh-8/main github/fork/Viktor-VERA2020/offcanvas-slide github/fork/Zivangu9/input-group-for-form-control-plaintext github/fork/alpadev/alpadev/call-dispose-on-component-reinstantiation github/fork/astagi/fix/tree-shake-modules github/fork/compnerd/dark-accordion-icon github/fork/derSascha/dropdown-dont-close-on-input-click github/fork/dev-ph1l/main github/fork/donquixote/issue-33861-utl-mixin github/fork/florianlacreuse/mixin-make-row-gutter-y github/fork/gregorw/main github/fork/iteggmbh/transitionend-dispose-race github/fork/jdelStrother/patch-1 github/fork/jonnysp/form-floating github/fork/jonnysp/independent-offcanvas github/fork/jonnysp/theme-dark-on-card-and-modal-fix github/fork/josefdlange/floating-label-placeholder-opacity github/fork/julien-deramond/enhance-change-version.js github/fork/julien-deramond/main-jd-fix-offset-content github/fork/julien-deramond/main-jd-issue-with-utitlies github/fork/julien-deramond/main-xmr-pa11y-ci-jd-add-hideElements github/fork/kyletsang/fix-tooltip-padding github/fork/lacutah/CheckboxCenteringDocumentation github/fork/lekoala/patch-3 github/fork/louismaximepiton/main-kld-lmp-collapse-proposal github/fork/louismaximepiton/main-lmp-card-inner-border-radius-fix github/fork/louismaximepiton/main-lmp-carousel-multiple-images github/fork/louismaximepiton/main-lmp-css-var-init github/fork/louismaximepiton/main-lmp-disabled-floating-label-fix github/fork/louismaximepiton/main-lmp-input-range-fix github/fork/louismaximepiton/main-lmp-shift-color github/fork/louismaximepiton/main-lmp-table-active-tr-fix github/fork/maciek-szn/switch github/fork/michael-roth/feature/19964-multiple-tab-targets github/fork/mistic100/dom-utils github/fork/nkdas91/accordion github/fork/nstungcom/fix-missing-modal-open-class github/fork/oraliahdz/animation-utilities github/fork/pine3ree/patch-7 github/fork/pouwerkerk/unindent-scss-docs-shortcode github/fork/smares/smares-no-scolling-on-modal-close github/fork/tgm-git/patch-1 gs-forms gs-toasts-with-animated-progress-bar gs/add-history-helper gs/change-version-dir-on-docs gs/data-must-set-onlu-one-instance gs/docs/fix-drop-down-error gs/event-handler-2 gs/make-docs-js-build gs/make-simple-attribute-toggler gs/popover-fix-doc gs/provide-steConfig-method gs/scrollspy-smoothscroll-option-use-browser-history gs/streamline-jqueryInterface gs/support-drop-down-in-navbar gs/test-js-generic-trigger gs/try-web-components gs/tweak-collapse-js-selector gs/use-event-handler-in-cocmponent gs/use-rollup-replace-for-version jo-docs-thanks-page jo-ssr-friendly logical-props-spacing-utils main-fod-disabled-form-check-label main-fod-nested-accordion main-fod-simpler-table-structure main-fod-table-separator main-fod-utilities-contrast main-jd-abbr-title main-jd-add-chips main-jd-add-doc-for-sass-custom-colors main-jd-add-enable-host-to-handle-web-components main-jd-browserstack-fine-tune main-jd-browserstack-updates main-jd-docs-consistent-usage-of-css-sections-step-2 main-jd-fix-docs-headers-in-white main-jd-fix-highlight-docs-border-radius main-jd-fix-placeholder-color-background-params-for-img-markup main-jd-glossary-experiment main-jd-postcss-drop-empty-css-vars main-jd-proto-doc-astro main-jd-skip-navigation-component main-jd-stackblitz-for-examples main-jd-upgrade-browserlistrc main-jd-use-host main-lmp-dark-theme-customization main-lmp-handle-scroll-target main-lmp-tab-fix main-mc-opensearch main-xmr-bundlewatch-action main-xmr-eslint-plugin-compat main-xmr-hugo-docs-vendor main-xmr-hugo-rm-ver main-xmr-linkinator-prod main-xmr-min-mangle main-xmr-pa11y-ci more-darkmode-examples nested-dropdowns patrickhlauke-issue37428 patrickhlauke-use-of-color-tweaks pr/34102 pr/37590 previous-next-docs-links sticky-thead utilities-functions-mixin v530-dev v6-postcss-custom-media v6-spinner-dots v6/gs/use-floating-ui-in-place-of-popper xmr/dev xmr/docs-png xmr/docs-svgs xmr/hugo-reorg-files xmr/js-2 xmr/markdownlint xmr/prepare-530-alpha2 xmr/xo v5.3.0-alpha1 v5.2.3 v5.2.2 v5.2.1 v5.2.0 v5.2.0-beta1 v5.1.3 v5.1.2 v5.1.1 v5.1.0 v5.0.2 v5.0.1 v5.0.0 v5.0.0-beta3 v5.0.0-beta2 v5.0.0-beta1 v5.0.0-alpha3 v5.0.0-alpha2 v5.0.0-alpha1
5 merge requests!31948Examples/Floating-labels: fix bad behavior with autofill,!30064test,!29779Responsive sizing,!28882fix custom-select-indicator in IE10,!28721Hot test
Showing with 395 additions and 353 deletions
+395 -353
...@@ -5,56 +5,66 @@ ...@@ -5,56 +5,66 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
const mapData = (() => { const Data = (() => {
const storeData = {}
let id = 1 /**
return { * ------------------------------------------------------------------------
set(element, key, data) { * Constants
if (typeof element.key === 'undefined') { * ------------------------------------------------------------------------
element.key = { */
key,
id
const mapData = (() => {
const storeData = {}
let id = 1
return {
set(element, key, data) {
if (typeof element.key === 'undefined') {
element.key = {
key,
id
}
} }
}
storeData[id] = data storeData[id] = data
id++ id++
}, },
get(element, key) { get(element, key) {
if (typeof element === 'undefined' || typeof element.key === 'undefined') { if (typeof element === 'undefined' || typeof element.key === 'undefined') {
return null
}
const keyProperties = element.key
if (keyProperties.key === key) {
return storeData[keyProperties.id]
}
return null return null
} },
delete(element, key) {
if (typeof element.key === 'undefined') {
return
}
const keyProperties = element.key const keyProperties = element.key
if (keyProperties.key === key) { if (keyProperties.key === key) {
return storeData[keyProperties.id] delete storeData[keyProperties.id]
} delete element.key
return null }
},
delete(element, key) {
if (typeof element.key === 'undefined') {
return
} }
}
})()
const keyProperties = element.key return {
if (keyProperties.key === key) { setData(instance, key, data) {
delete storeData[keyProperties.id] mapData.set(instance, key, data)
delete element.key },
} getData(instance, key) {
return mapData.get(instance, key)
},
removeData(instance, key) {
mapData.delete(instance, key)
} }
} }
})() })()
const Data = {
setData(instance, key, data) {
mapData.set(instance, key, data)
},
getData(instance, key) {
return mapData.get(instance, key)
},
removeData(instance, key) {
mapData.delete(instance, key)
}
}
export default Data export default Data
...@@ -7,325 +7,347 @@ import Util from '../util' ...@@ -7,325 +7,347 @@ import Util from '../util'
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
// defaultPrevented is broken in IE. const EventHandler = (() => {
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
const workingDefaultPrevented = (() => { /**
const e = document.createEvent('CustomEvent') * ------------------------------------------------------------------------
e.initEvent('Bootstrap', true, true) * Polyfills
e.preventDefault() * ------------------------------------------------------------------------
return e.defaultPrevented */
})()
// defaultPrevented is broken in IE.
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
const workingDefaultPrevented = (() => {
const e = document.createEvent('CustomEvent')
e.initEvent('Bootstrap', true, true)
e.preventDefault()
return e.defaultPrevented
})()
let defaultPreventedPreservedOnDispatch = true let defaultPreventedPreservedOnDispatch = true
// CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn) // CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn)
if (typeof window.CustomEvent !== 'function') { if (typeof window.CustomEvent !== 'function') {
window.CustomEvent = (event, params) => { window.CustomEvent = (event, params) => {
params = params || { params = params || {
bubbles: false, bubbles: false,
cancelable: false, cancelable: false,
detail: null detail: null
} }
const evt = document.createEvent('CustomEvent') const evt = document.createEvent('CustomEvent')
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail) evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
if (!workingDefaultPrevented) { if (!workingDefaultPrevented) {
const origPreventDefault = Event.prototype.preventDefault const origPreventDefault = Event.prototype.preventDefault
evt.preventDefault = () => { evt.preventDefault = () => {
if (!evt.cancelable) { if (!evt.cancelable) {
return return
}
origPreventDefault.call(evt)
Object.defineProperty(evt, 'defaultPrevented', {
get() {
return true
},
configurable: true
})
} }
origPreventDefault.call(evt)
Object.defineProperty(evt, 'defaultPrevented', {
get() {
return true
},
configurable: true
})
} }
return evt
} }
return evt
}
window.CustomEvent.prototype = window.Event.prototype window.CustomEvent.prototype = window.Event.prototype
} else { } else {
// MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached // MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
defaultPreventedPreservedOnDispatch = (() => { defaultPreventedPreservedOnDispatch = (() => {
const e = new CustomEvent('Bootstrap', { const e = new CustomEvent('Bootstrap', {
cancelable: true cancelable: true
}) })
const element = document.createElement('div') const element = document.createElement('div')
element.addEventListener('Bootstrap', () => null) element.addEventListener('Bootstrap', () => null)
e.preventDefault() e.preventDefault()
element.dispatchEvent(e) element.dispatchEvent(e)
return e.defaultPrevented return e.defaultPrevented
})() })()
}
// Event constructor shim
if (!window.Event || typeof window.Event !== 'function') {
const origEvent = window.Event
window.Event = (inType, params) => {
params = params || {}
const e = document.createEvent('Event')
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable))
return e
} }
window.Event.prototype = origEvent.prototype
}
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
const keyEventRegex = /^key/
const stripUidRegex = /::\d+$/
// Events storage // Event constructor shim
const eventRegistry = {} if (!window.Event || typeof window.Event !== 'function') {
let uidEvent = 1 const origEvent = window.Event
window.Event = (inType, params) => {
params = params || {}
const e = document.createEvent('Event')
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable))
return e
}
window.Event.prototype = origEvent.prototype
}
function getUidEvent(element, uid) { /**
return element.uidEvent = uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++ * ------------------------------------------------------------------------
} * Constants
* ------------------------------------------------------------------------
*/
function getEvent(element) { const TransitionEndEvent = {
const uid = getUidEvent(element) WebkitTransition : 'webkitTransitionEnd',
return eventRegistry[uid] = eventRegistry[uid] || {} transition : 'transitionend'
} }
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
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',
'orientationchange',
'touchstart', 'touchmove', 'touchend', 'touchcancel',
'gesturestart', 'gesturechange', 'gestureend',
'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout',
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
'error', 'abort', 'scroll'
]
/**
* ------------------------------------------------------------------------
* Private methods
* ------------------------------------------------------------------------
*/
function getUidEvent(element, uid) {
return element.uidEvent = uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++
}
const nativeEvents = [ function getEvent(element) {
'click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu', const uid = getUidEvent(element)
'mousewheel', 'DOMMouseScroll', return eventRegistry[uid] = eventRegistry[uid] || {}
'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend', }
'keydown', 'keypress', 'keyup',
'orientationchange',
'touchstart', 'touchmove', 'touchend', 'touchcancel',
'gesturestart', 'gesturechange', 'gestureend',
'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout',
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
'error', 'abort', 'scroll'
]
const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
}
function fixEvent(event) { function fixEvent(event) {
// Add which for key events // Add which for key events
if (event.which === null && keyEventRegex.test(event.type)) { if (event.which === null && keyEventRegex.test(event.type)) {
event.which = event.charCode !== null ? event.charCode : event.keyCode event.which = event.charCode !== null ? event.charCode : event.keyCode
}
return event
} }
return event
}
function bootstrapHandler(element, fn) { function bootstrapHandler(element, fn) {
return function (event) { return function (event) {
event = fixEvent(event) event = fixEvent(event)
return fn.apply(element, [event]) return fn.apply(element, [event])
}
} }
}
function bootstrapDelegationHandler(element, selector, fn) { function bootstrapDelegationHandler(element, selector, fn) {
return function (event) { return function (event) {
event = fixEvent(event) event = fixEvent(event)
const domElements = element.querySelectorAll(selector) const domElements = element.querySelectorAll(selector)
for (let target = event.target; target && target !== this; target = target.parentNode) { for (let target = event.target; target && target !== this; target = target.parentNode) {
for (let i = domElements.length; i--;) { for (let i = domElements.length; i--;) {
if (domElements[i] === target) { if (domElements[i] === target) {
return fn.apply(target, [event]) return fn.apply(target, [event])
}
} }
} }
// To please ESLint
return null
} }
// To please ESLint
return null
} }
}
function removeHandler(element, events, typeEvent, handler) { function removeHandler(element, events, typeEvent, handler) {
const uidEvent = handler.uidEvent const uidEvent = handler.uidEvent
const fn = events[typeEvent][uidEvent] const fn = events[typeEvent][uidEvent]
element.removeEventListener(typeEvent, fn, fn.delegation) element.removeEventListener(typeEvent, fn, fn.delegation)
delete events[typeEvent][uidEvent] delete events[typeEvent][uidEvent]
} }
function removeNamespacedHandlers(element, events, typeEvent, namespace) { function removeNamespacedHandlers(element, events, typeEvent, namespace) {
const storeElementEvent = events[typeEvent] || {} const storeElementEvent = events[typeEvent] || {}
for (const handlerKey in storeElementEvent) { for (const handlerKey in storeElementEvent) {
if (!Object.prototype.hasOwnProperty.call(storeElementEvent, handlerKey)) { if (!Object.prototype.hasOwnProperty.call(storeElementEvent, handlerKey)) {
continue continue
} }
if (handlerKey.indexOf(namespace) > -1) { if (handlerKey.indexOf(namespace) > -1) {
removeHandler(element, events, typeEvent, storeElementEvent[handlerKey].originalHandler) removeHandler(element, events, typeEvent, storeElementEvent[handlerKey].originalHandler)
}
} }
} }
}
const EventHandler = { return {
on(element, originalTypeEvent, handler, delegationFn) { on(element, originalTypeEvent, handler, delegationFn) {
if (typeof originalTypeEvent !== 'string' || if (typeof originalTypeEvent !== 'string' ||
(typeof element === 'undefined' || element === null)) { (typeof element === 'undefined' || element === null)) {
return return
} }
const delegation = typeof handler === 'string' const delegation = typeof handler === 'string'
const originalHandler = delegation ? delegationFn : handler const originalHandler = delegation ? delegationFn : handler
// allow to get the native events from namespaced events ('click.bs.button' --> 'click') // allow to get the native events from namespaced events ('click.bs.button' --> 'click')
let typeEvent = originalTypeEvent.replace(stripNameRegex, '') let typeEvent = originalTypeEvent.replace(stripNameRegex, '')
const custom = customEvents[typeEvent] const custom = customEvents[typeEvent]
if (custom) { if (custom) {
typeEvent = custom typeEvent = custom
} }
const isNative = nativeEvents.indexOf(typeEvent) > -1 const isNative = nativeEvents.indexOf(typeEvent) > -1
if (!isNative) { if (!isNative) {
typeEvent = originalTypeEvent typeEvent = originalTypeEvent
} }
const events = getEvent(element) const events = getEvent(element)
const handlers = events[typeEvent] || (events[typeEvent] = {}) const handlers = events[typeEvent] || (events[typeEvent] = {})
const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, '')) const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, ''))
if (handlers[uid]) { if (handlers[uid]) {
return return
} }
const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(element, handler, delegationFn) const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(element, handler, delegationFn)
fn.isDelegation = delegation fn.isDelegation = delegation
handlers[uid] = fn handlers[uid] = fn
originalHandler.uidEvent = uid originalHandler.uidEvent = uid
fn.originalHandler = originalHandler fn.originalHandler = originalHandler
element.addEventListener(typeEvent, fn, delegation) element.addEventListener(typeEvent, fn, delegation)
}, },
one(element, event, handler) { one(element, event, handler) {
function complete(e) { function complete(e) {
EventHandler.off(element, event, complete) EventHandler.off(element, event, complete)
handler.apply(element, [e]) handler.apply(element, [e])
} }
EventHandler.on(element, event, complete) EventHandler.on(element, event, complete)
}, },
off(element, originalTypeEvent, handler) { off(element, originalTypeEvent, handler) {
if (typeof originalTypeEvent !== 'string' || if (typeof originalTypeEvent !== 'string' ||
(typeof element === 'undefined' || element === null)) { (typeof element === 'undefined' || element === null)) {
return return
} }
const events = getEvent(element) const events = getEvent(element)
let typeEvent = originalTypeEvent.replace(stripNameRegex, '') let typeEvent = originalTypeEvent.replace(stripNameRegex, '')
const inNamespace = typeEvent !== originalTypeEvent const inNamespace = typeEvent !== originalTypeEvent
const custom = customEvents[typeEvent] const custom = customEvents[typeEvent]
if (custom) { if (custom) {
typeEvent = custom typeEvent = custom
} }
const isNative = nativeEvents.indexOf(typeEvent) > -1 const isNative = nativeEvents.indexOf(typeEvent) > -1
if (!isNative) { if (!isNative) {
typeEvent = originalTypeEvent typeEvent = originalTypeEvent
} }
if (typeof handler !== 'undefined') {
// Simplest case: handler is passed, remove that listener ONLY.
if (!events || !events[typeEvent]) {
return
}
if (typeof handler !== 'undefined') { removeHandler(element, events, typeEvent, handler)
// Simplest case: handler is passed, remove that listener ONLY.
if (!events || !events[typeEvent]) {
return return
} }
removeHandler(element, events, typeEvent, handler) const isNamespace = originalTypeEvent.charAt(0) === '.'
return if (isNamespace) {
} for (const elementEvent in events) {
if (!Object.prototype.hasOwnProperty.call(events, elementEvent)) {
continue
}
const isNamespace = originalTypeEvent.charAt(0) === '.' removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.substr(1))
if (isNamespace) {
for (const elementEvent in events) {
if (!Object.prototype.hasOwnProperty.call(events, elementEvent)) {
continue
} }
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.substr(1))
} }
}
const storeElementEvent = events[typeEvent] || {} const storeElementEvent = events[typeEvent] || {}
for (const keyHandlers in storeElementEvent) { for (const keyHandlers in storeElementEvent) {
if (!Object.prototype.hasOwnProperty.call(storeElementEvent, keyHandlers)) { if (!Object.prototype.hasOwnProperty.call(storeElementEvent, keyHandlers)) {
continue continue
}
const handlerKey = keyHandlers.replace(stripUidRegex, '')
if (!inNamespace || originalTypeEvent.indexOf(handlerKey) > -1) {
removeHandler(element, events, typeEvent, storeElementEvent[keyHandlers].originalHandler)
}
} }
},
const handlerKey = keyHandlers.replace(stripUidRegex, '') trigger(element, event, args) {
if (!inNamespace || originalTypeEvent.indexOf(handlerKey) > -1) { if (typeof event !== 'string' ||
removeHandler(element, events, typeEvent, storeElementEvent[keyHandlers].originalHandler) (typeof element === 'undefined' || element === null)) {
return null
} }
}
},
trigger(element, event, args) { const typeEvent = event.replace(stripNameRegex, '')
if (typeof event !== 'string' || const inNamespace = event !== typeEvent
(typeof element === 'undefined' || element === null)) { const isNative = nativeEvents.indexOf(typeEvent) > -1
return null
}
const typeEvent = event.replace(stripNameRegex, '') const $ = Util.jQuery
const inNamespace = event !== typeEvent let jQueryEvent
const isNative = nativeEvents.indexOf(typeEvent) > -1
const $ = Util.jQuery let bubbles = true
let jQueryEvent let nativeDispatch = true
let defaultPrevented = false
let bubbles = true if (inNamespace && typeof $ !== 'undefined') {
let nativeDispatch = true jQueryEvent = new $.Event(event, args)
let defaultPrevented = false
if (inNamespace && typeof $ !== 'undefined') { $(element).trigger(jQueryEvent)
jQueryEvent = new $.Event(event, args) bubbles = !jQueryEvent.isPropagationStopped()
nativeDispatch = !jQueryEvent.isImmediatePropagationStopped()
defaultPrevented = jQueryEvent.isDefaultPrevented()
}
$(element).trigger(jQueryEvent) let evt = null
bubbles = !jQueryEvent.isPropagationStopped()
nativeDispatch = !jQueryEvent.isImmediatePropagationStopped()
defaultPrevented = jQueryEvent.isDefaultPrevented()
}
let evt = null if (isNative) {
evt = document.createEvent('HTMLEvents')
evt.initEvent(typeEvent, bubbles, true)
} else {
evt = new CustomEvent(event, {
bubbles,
cancelable: true
})
}
if (isNative) { // merge custom informations in our event
evt = document.createEvent('HTMLEvents') if (typeof args !== 'undefined') {
evt.initEvent(typeEvent, bubbles, true) evt = Util.extend(evt, args)
} else { }
evt = new CustomEvent(event, {
bubbles,
cancelable: true
})
}
// merge custom informations in our event if (defaultPrevented) {
if (typeof args !== 'undefined') { evt.preventDefault()
evt = Util.extend(evt, args)
}
if (defaultPrevented) { if (!defaultPreventedPreservedOnDispatch) {
evt.preventDefault() Object.defineProperty(evt, 'defaultPrevented', {
get: () => true
})
}
}
if (!defaultPreventedPreservedOnDispatch) { if (nativeDispatch) {
Object.defineProperty(evt, 'defaultPrevented', { element.dispatchEvent(evt)
get: () => true
})
} }
}
if (nativeDispatch) { if (evt.defaultPrevented && typeof jQueryEvent !== 'undefined') {
element.dispatchEvent(evt) jQueryEvent.preventDefault()
} }
if (evt.defaultPrevented && typeof jQueryEvent !== 'undefined') { return evt
jQueryEvent.preventDefault()
} }
return evt
} }
} })()
// focusin and focusout polyfill // focusin and focusout polyfill
if (typeof window.onfocusin === 'undefined') { if (typeof window.onfocusin === 'undefined') {
......
...@@ -5,76 +5,86 @@ ...@@ -5,76 +5,86 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
// matches polyfill (see: https://mzl.la/2ikXneG) const SelectorEngine = (() => {
let fnMatches = null
if (!Element.prototype.matches) {
fnMatches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
} else {
fnMatches = Element.prototype.matches
}
// closest polyfill (see: https://mzl.la/2vXggaI)
let fnClosest = null
if (!Element.prototype.closest) {
fnClosest = (element, selector) => {
let ancestor = element
if (!document.documentElement.contains(element)) {
return null
}
do {
if (fnMatches.call(ancestor, selector)) {
return ancestor
}
ancestor = ancestor.parentElement /**
} while (ancestor !== null) * ------------------------------------------------------------------------
* Polyfills
* ------------------------------------------------------------------------
*/
return null // matches polyfill (see: https://mzl.la/2ikXneG)
let fnMatches = null
if (!Element.prototype.matches) {
fnMatches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
} else {
fnMatches = Element.prototype.matches
} }
} else {
// eslint-disable-next-line arrow-body-style
fnClosest = (element, selector) => {
return element.closest(selector)
}
}
const SelectorEngine = { // closest polyfill (see: https://mzl.la/2vXggaI)
matches(element, selector) { let fnClosest = null
return fnMatches.call(element, selector) if (!Element.prototype.closest) {
}, fnClosest = (element, selector) => {
let ancestor = element
if (!document.documentElement.contains(element)) {
return null
}
do {
if (fnMatches.call(ancestor, selector)) {
return ancestor
}
ancestor = ancestor.parentElement
} while (ancestor !== null)
find(selector, element = document) {
if (typeof selector !== 'string') {
return null return null
} }
} else {
if (selector.indexOf('#') === 0) { // eslint-disable-next-line arrow-body-style
return SelectorEngine.findOne(selector, element) fnClosest = (element, selector) => {
return element.closest(selector)
} }
}
return element.querySelectorAll(selector) return {
}, matches(element, selector) {
return fnMatches.call(element, selector)
},
findOne(selector, element = document) { find(selector, element = document) {
if (typeof selector !== 'string') { if (typeof selector !== 'string') {
return null return null
} }
let selectorType = 'querySelector' if (selector.indexOf('#') === 0) {
if (selector.indexOf('#') === 0) { return SelectorEngine.findOne(selector, element)
selectorType = 'getElementById' }
selector = selector.substr(1, selector.length)
} return element.querySelectorAll(selector)
},
return element[selectorType](selector) findOne(selector, element = document) {
}, if (typeof selector !== 'string') {
return null
}
let selectorType = 'querySelector'
if (selector.indexOf('#') === 0) {
selectorType = 'getElementById'
selector = selector.substr(1, selector.length)
}
closest(element, selector) { return element[selectorType](selector)
return fnClosest(element, selector) },
closest(element, selector) {
return fnClosest(element, selector)
}
} }
} })()
export default SelectorEngine export default SelectorEngine
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment