0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Fix detection of nativeEvents + trigger events with arguments

This commit is contained in:
Johann-S 2017-08-26 12:34:24 +02:00 committed by XhmikosR
parent 3e8bc9d9ec
commit 79144adb12

View File

@ -74,17 +74,18 @@ function getEvent(element) {
return eventRegistry[uid] = eventRegistry[uid] || {}
}
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,
'load,unload,beforeunload,resize,move,DOMContentLoaded,readystatechange,
'error,abort,scroll`.split(',')
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',
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
'error', 'abort', 'scroll'
]
function bootstrapHandler(element, fn) {
return function (event) {
@ -165,7 +166,7 @@ const EventHandler = {
delete events[typeEvent][uidEvent]
},
trigger(element, event) {
trigger(element, event, args) {
if (typeof event !== 'string' ||
(typeof element === 'undefined' || element === null)) {
return null
@ -175,13 +176,14 @@ const EventHandler = {
let returnedEvent = null
if (isNative) {
const evt = document.createEvent('HTMLEvents')
evt.initEvent(typeEvent, true, true)
evt.initEvent(typeEvent, true, true, typeof args !== 'undefined' ? args : {})
element.dispatchEvent(evt)
returnedEvent = evt
} else {
const eventToDispatch = new CustomEvent(event, {
bubbles: true,
cancelable: true
cancelable: true,
detail: typeof args !== 'undefined' ? args : {}
})
element.dispatchEvent(eventToDispatch)
returnedEvent = eventToDispatch