1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00

Event handler: replace deprecated initEvent

This commit is contained in:
GeoSot 2021-12-16 13:23:17 +02:00 committed by XhmikosR
parent 640542e606
commit fa93995123
4 changed files with 6 additions and 15 deletions

View file

@ -289,7 +289,6 @@ const EventHandler = {
let bubbles = true
let nativeDispatch = true
let defaultPrevented = false
let evt = null
if (inNamespace && $) {
jQueryEvent = $.Event(event, args)
@ -300,12 +299,9 @@ const EventHandler = {
defaultPrevented = jQueryEvent.isDefaultPrevented()
}
if (isNative) {
evt = document.createEvent('HTMLEvents')
evt.initEvent(typeEvent, bubbles, true)
} else {
evt = new CustomEvent(event, { bubbles, cancelable: true })
}
const evt = isNative ?
new Event(event, { bubbles, cancelable: true }) :
new CustomEvent(event, { bubbles, cancelable: true })
// merge custom information in our event
if (typeof args !== 'undefined') {

View file

@ -24,10 +24,7 @@ export const clearFixture = () => {
}
export const createEvent = (eventName, parameters = {}) => {
const event = document.createEvent('Event')
event.initEvent(eventName, Boolean(parameters.bubbles), Boolean(parameters.cancelable))
return event
return new Event(eventName, parameters)
}
export const jQueryMock = {

View file

@ -191,8 +191,7 @@ describe('Offcanvas', () => {
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl, { backdrop: true })
const clickEvent = document.createEvent('MouseEvents')
clickEvent.initEvent('mousedown', true, true)
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {

View file

@ -169,8 +169,7 @@ describe('Backdrop', () => {
}
instance.show(() => {
const clickEvent = document.createEvent('MouseEvents')
clickEvent.initEvent('mousedown', true, true)
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
document.querySelector(CLASS_BACKDROP).dispatchEvent(clickEvent)
endTest()
})