mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-29 14:59:16 +02:00
fix(data): do not use data object in our unit tests
This commit is contained in:
@@ -137,6 +137,10 @@ class Alert {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -112,6 +112,10 @@ class Button {
|
||||
if (triggerChangeEvent) {
|
||||
this._element.classList.toggle(ClassName.ACTIVE)
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
@@ -579,6 +579,10 @@ class Carousel {
|
||||
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -597,7 +601,6 @@ EventHandler.on(window, Event.LOAD_DATA_API, () => {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* jQuery
|
||||
|
@@ -373,6 +373,10 @@ class Collapse {
|
||||
Collapse._collapseInterface(this, config)
|
||||
})
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
94
js/src/dom/polyfill.js
Normal file
94
js/src/dom/polyfill.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import EventHandler from './eventHandler'
|
||||
|
||||
const Polyfill = (() => {
|
||||
// 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
|
||||
|
||||
// CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn)
|
||||
if (typeof window.CustomEvent !== 'function') {
|
||||
window.CustomEvent = (event, params) => {
|
||||
params = params || {
|
||||
bubbles: false,
|
||||
cancelable: false,
|
||||
detail: null
|
||||
}
|
||||
const evt = document.createEvent('CustomEvent')
|
||||
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
|
||||
if (!workingDefaultPrevented) {
|
||||
const origPreventDefault = Event.prototype.preventDefault
|
||||
evt.preventDefault = () => {
|
||||
if (!evt.cancelable) {
|
||||
return
|
||||
}
|
||||
|
||||
origPreventDefault.call(evt)
|
||||
Object.defineProperty(evt, 'defaultPrevented', {
|
||||
get() {
|
||||
return true
|
||||
},
|
||||
configurable: true
|
||||
})
|
||||
}
|
||||
}
|
||||
return evt
|
||||
}
|
||||
|
||||
window.CustomEvent.prototype = window.Event.prototype
|
||||
} else {
|
||||
// MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
|
||||
defaultPreventedPreservedOnDispatch = (() => {
|
||||
const e = new CustomEvent('Bootstrap', {
|
||||
cancelable: true
|
||||
})
|
||||
|
||||
const element = document.createElement('div')
|
||||
element.addEventListener('Bootstrap', () => null)
|
||||
|
||||
e.preventDefault()
|
||||
element.dispatchEvent(e)
|
||||
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
|
||||
}
|
||||
|
||||
// focusin and focusout polyfill
|
||||
if (typeof window.onfocusin === 'undefined') {
|
||||
(() => {
|
||||
function listenerFocus(event) {
|
||||
EventHandler.trigger(event.target, 'focusin')
|
||||
}
|
||||
function listenerBlur(event) {
|
||||
EventHandler.trigger(event.target, 'focusout')
|
||||
}
|
||||
EventHandler.on(document, 'focus', 'input', listenerFocus)
|
||||
EventHandler.on(document, 'blur', 'input', listenerBlur)
|
||||
})()
|
||||
}
|
||||
|
||||
return {
|
||||
get defaultPreventedPreservedOnDispatch() {
|
||||
return defaultPreventedPreservedOnDispatch
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
export default Polyfill
|
@@ -505,6 +505,10 @@ class Dropdown {
|
||||
|
||||
items[index].focus()
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -5,7 +5,7 @@ import Collapse from './collapse'
|
||||
import Dropdown from './dropdown'
|
||||
import Modal from './modal'
|
||||
import Popover from './popover'
|
||||
import Scrollspy from './scrollspy'
|
||||
import ScrollSpy from './scrollspy'
|
||||
import Tab from './tab'
|
||||
import Toast from './toast'
|
||||
import Tooltip from './tooltip'
|
||||
@@ -27,7 +27,7 @@ export {
|
||||
Dropdown,
|
||||
Modal,
|
||||
Popover,
|
||||
Scrollspy,
|
||||
ScrollSpy,
|
||||
Tab,
|
||||
Toast,
|
||||
Tooltip
|
||||
|
@@ -498,6 +498,10 @@ class Modal {
|
||||
} else {
|
||||
document.body.style.paddingRight = ''
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
_getScrollbarWidth() { // thx d.walsh
|
||||
|
@@ -165,6 +165,10 @@ class Popover extends Tooltip {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -308,6 +308,10 @@ class ScrollSpy {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -219,6 +219,10 @@ class Tab {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -741,6 +741,10 @@ class Tooltip {
|
||||
.map((token) => token.trim())
|
||||
.forEach((tClass) => tip.classList.remove(tClass))
|
||||
}
|
||||
|
||||
static _getInstance(element) {
|
||||
return Data.getData(element, DATA_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
_handlePopperPlacementChange(popperData) {
|
||||
|
Reference in New Issue
Block a user