mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
Event handler: replace deprecated initEvent
This commit is contained in:
parent
640542e606
commit
fa93995123
@ -289,7 +289,6 @@ const EventHandler = {
|
|||||||
let bubbles = true
|
let bubbles = true
|
||||||
let nativeDispatch = true
|
let nativeDispatch = true
|
||||||
let defaultPrevented = false
|
let defaultPrevented = false
|
||||||
let evt = null
|
|
||||||
|
|
||||||
if (inNamespace && $) {
|
if (inNamespace && $) {
|
||||||
jQueryEvent = $.Event(event, args)
|
jQueryEvent = $.Event(event, args)
|
||||||
@ -300,12 +299,9 @@ const EventHandler = {
|
|||||||
defaultPrevented = jQueryEvent.isDefaultPrevented()
|
defaultPrevented = jQueryEvent.isDefaultPrevented()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNative) {
|
const evt = isNative ?
|
||||||
evt = document.createEvent('HTMLEvents')
|
new Event(event, { bubbles, cancelable: true }) :
|
||||||
evt.initEvent(typeEvent, bubbles, true)
|
new CustomEvent(event, { bubbles, cancelable: true })
|
||||||
} else {
|
|
||||||
evt = new CustomEvent(event, { bubbles, cancelable: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge custom information in our event
|
// merge custom information in our event
|
||||||
if (typeof args !== 'undefined') {
|
if (typeof args !== 'undefined') {
|
||||||
|
@ -24,10 +24,7 @@ export const clearFixture = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const createEvent = (eventName, parameters = {}) => {
|
export const createEvent = (eventName, parameters = {}) => {
|
||||||
const event = document.createEvent('Event')
|
return new Event(eventName, parameters)
|
||||||
|
|
||||||
event.initEvent(eventName, Boolean(parameters.bubbles), Boolean(parameters.cancelable))
|
|
||||||
return event
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const jQueryMock = {
|
export const jQueryMock = {
|
||||||
|
@ -191,8 +191,7 @@ describe('Offcanvas', () => {
|
|||||||
const offCanvasEl = fixtureEl.querySelector('div')
|
const offCanvasEl = fixtureEl.querySelector('div')
|
||||||
const offCanvas = new Offcanvas(offCanvasEl, { backdrop: true })
|
const offCanvas = new Offcanvas(offCanvasEl, { backdrop: true })
|
||||||
|
|
||||||
const clickEvent = document.createEvent('MouseEvents')
|
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
|
||||||
clickEvent.initEvent('mousedown', true, true)
|
|
||||||
spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
|
spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
|
||||||
|
|
||||||
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
||||||
|
@ -169,8 +169,7 @@ describe('Backdrop', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance.show(() => {
|
instance.show(() => {
|
||||||
const clickEvent = document.createEvent('MouseEvents')
|
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
|
||||||
clickEvent.initEvent('mousedown', true, true)
|
|
||||||
document.querySelector(CLASS_BACKDROP).dispatchEvent(clickEvent)
|
document.querySelector(CLASS_BACKDROP).dispatchEvent(clickEvent)
|
||||||
endTest()
|
endTest()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user