0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01: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()
})