]>
git.ipfire.org Git - ipfire.org.git/blob - src/scss/bootstrap-4.0.0-alpha.6/js/src/util.js
2 * --------------------------------------------------------------------------
3 * Bootstrap (v4.0.0-alpha.6): util.js
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5 * --------------------------------------------------------------------------
12 * ------------------------------------------------------------------------
13 * Private TransitionEnd Helpers
14 * ------------------------------------------------------------------------
17 let transition
= false
19 const MAX_UID
= 1000000
21 const TransitionEndEvent
= {
22 WebkitTransition
: 'webkitTransitionEnd',
23 MozTransition
: 'transitionend',
24 OTransition
: 'oTransitionEnd otransitionend',
25 transition
: 'transitionend'
28 // shoutout AngusCroll (https://goo.gl/pxwQGp)
29 function toType(obj
) {
30 return {}.toString
.call(obj
).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
33 function isElement(obj
) {
34 return (obj
[0] || obj
).nodeType
37 function getSpecialTransitionEndEvent() {
39 bindType
: transition
.end
,
40 delegateType
: transition
.end
,
42 if ($(event
.target
).is(this)) {
43 return event
.handleObj
.handler
.apply(this, arguments
) // eslint-disable-line prefer-rest-params
50 function transitionEndTest() {
55 const el
= document
.createElement('bootstrap')
57 for (const name
in TransitionEndEvent
) {
58 if (el
.style
[name
] !== undefined) {
60 end
: TransitionEndEvent
[name
]
68 function transitionEndEmulator(duration
) {
71 $(this).one(Util
.TRANSITION_END
, () => {
77 Util
.triggerTransitionEnd(this)
84 function setTransitionEndSupport() {
85 transition
= transitionEndTest()
87 $.fn
.emulateTransitionEnd
= transitionEndEmulator
89 if (Util
.supportsTransitionEnd()) {
90 $.event
.special
[Util
.TRANSITION_END
] = getSpecialTransitionEndEvent()
96 * --------------------------------------------------------------------------
98 * --------------------------------------------------------------------------
103 TRANSITION_END
: 'bsTransitionEnd',
107 // eslint-disable-next-line no-bitwise
108 prefix
+= ~~(Math
.random() * MAX_UID
) // "~~" acts like a faster Math.floor() here
109 } while (document
.getElementById(prefix
))
113 getSelectorFromElement(element
) {
114 let selector
= element
.getAttribute('data-target')
117 selector
= element
.getAttribute('href') || ''
118 selector
= /^#[a-z]/i.test(selector
) ? selector
: null
125 return element
.offsetHeight
128 triggerTransitionEnd(element
) {
129 $(element
).trigger(transition
.end
)
132 supportsTransitionEnd() {
133 return Boolean(transition
)
136 typeCheckConfig(componentName
, config
, configTypes
) {
137 for (const property
in configTypes
) {
138 if (configTypes
.hasOwnProperty(property
)) {
139 const expectedTypes
= configTypes
[property
]
140 const value
= config
[property
]
141 const valueType
= value
&& isElement(value
) ?
142 'element' : toType(value
)
144 if (!new RegExp(expectedTypes
).test(valueType
)) {
146 `${componentName.toUpperCase()}: ` +
147 `Option "${property}" provided type "${valueType}" ` +
148 `but expected type "${expectedTypes}".`)
155 setTransitionEndSupport()