OSDN Git Service

fix bug and add tool for claim tx
[bytom/vapor.git] / tools / side_chain_tool / web / node_modules / bootstrap / js / src / util.js
1 import $ from 'jquery'
2
3 /**
4  * --------------------------------------------------------------------------
5  * Bootstrap (v4.1.3): util.js
6  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7  * --------------------------------------------------------------------------
8  */
9
10 const Util = (($) => {
11   /**
12    * ------------------------------------------------------------------------
13    * Private TransitionEnd Helpers
14    * ------------------------------------------------------------------------
15    */
16
17   const TRANSITION_END = 'transitionend'
18   const MAX_UID = 1000000
19   const MILLISECONDS_MULTIPLIER = 1000
20
21   // Shoutout AngusCroll (https://goo.gl/pxwQGp)
22   function toType(obj) {
23     return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
24   }
25
26   function getSpecialTransitionEndEvent() {
27     return {
28       bindType: TRANSITION_END,
29       delegateType: TRANSITION_END,
30       handle(event) {
31         if ($(event.target).is(this)) {
32           return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params
33         }
34         return undefined // eslint-disable-line no-undefined
35       }
36     }
37   }
38
39   function transitionEndEmulator(duration) {
40     let called = false
41
42     $(this).one(Util.TRANSITION_END, () => {
43       called = true
44     })
45
46     setTimeout(() => {
47       if (!called) {
48         Util.triggerTransitionEnd(this)
49       }
50     }, duration)
51
52     return this
53   }
54
55   function setTransitionEndSupport() {
56     $.fn.emulateTransitionEnd = transitionEndEmulator
57     $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent()
58   }
59
60   /**
61    * --------------------------------------------------------------------------
62    * Public Util Api
63    * --------------------------------------------------------------------------
64    */
65
66   const Util = {
67
68     TRANSITION_END: 'bsTransitionEnd',
69
70     getUID(prefix) {
71       do {
72         // eslint-disable-next-line no-bitwise
73         prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
74       } while (document.getElementById(prefix))
75       return prefix
76     },
77
78     getSelectorFromElement(element) {
79       let selector = element.getAttribute('data-target')
80       if (!selector || selector === '#') {
81         selector = element.getAttribute('href') || ''
82       }
83
84       try {
85         return document.querySelector(selector) ? selector : null
86       } catch (err) {
87         return null
88       }
89     },
90
91     getTransitionDurationFromElement(element) {
92       if (!element) {
93         return 0
94       }
95
96       // Get transition-duration of the element
97       let transitionDuration = $(element).css('transition-duration')
98       const floatTransitionDuration = parseFloat(transitionDuration)
99
100       // Return 0 if element or transition duration is not found
101       if (!floatTransitionDuration) {
102         return 0
103       }
104
105       // If multiple durations are defined, take the first
106       transitionDuration = transitionDuration.split(',')[0]
107
108       return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER
109     },
110
111     reflow(element) {
112       return element.offsetHeight
113     },
114
115     triggerTransitionEnd(element) {
116       $(element).trigger(TRANSITION_END)
117     },
118
119     // TODO: Remove in v5
120     supportsTransitionEnd() {
121       return Boolean(TRANSITION_END)
122     },
123
124     isElement(obj) {
125       return (obj[0] || obj).nodeType
126     },
127
128     typeCheckConfig(componentName, config, configTypes) {
129       for (const property in configTypes) {
130         if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
131           const expectedTypes = configTypes[property]
132           const value         = config[property]
133           const valueType     = value && Util.isElement(value)
134             ? 'element' : toType(value)
135
136           if (!new RegExp(expectedTypes).test(valueType)) {
137             throw new Error(
138               `${componentName.toUpperCase()}: ` +
139               `Option "${property}" provided type "${valueType}" ` +
140               `but expected type "${expectedTypes}".`)
141           }
142         }
143       }
144     }
145   }
146
147   setTransitionEndSupport()
148
149   return Util
150 })($)
151
152 export default Util