]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - static/scss/bootstrap-4.0.0-alpha.6/js/src/button.js
2 * --------------------------------------------------------------------------
3 * Bootstrap (v4.0.0-alpha.6): button.js
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5 * --------------------------------------------------------------------------
8 const Button
= (($) => {
12 * ------------------------------------------------------------------------
14 * ------------------------------------------------------------------------
18 const VERSION
= '4.0.0-alpha.6'
19 const DATA_KEY
= 'bs.button'
20 const EVENT_KEY
= `.${DATA_KEY}`
21 const DATA_API_KEY
= '.data-api'
22 const JQUERY_NO_CONFLICT
= $.fn
[NAME
]
31 DATA_TOGGLE_CARROT
: '[data-toggle^="button"]',
32 DATA_TOGGLE
: '[data-toggle="buttons"]',
39 CLICK_DATA_API
: `click${EVENT_KEY}${DATA_API_KEY}`,
40 FOCUS_BLUR_DATA_API
: `focus${EVENT_KEY}${DATA_API_KEY} `
41 + `blur${EVENT_KEY}${DATA_API_KEY}`
46 * ------------------------------------------------------------------------
48 * ------------------------------------------------------------------------
53 constructor(element
) {
54 this._element
= element
60 static get VERSION() {
68 let triggerChangeEvent
= true
69 const rootElement
= $(this._element
).closest(
74 const input
= $(this._element
).find(Selector
.INPUT
)[0]
77 if (input
.type
=== 'radio') {
79 $(this._element
).hasClass(ClassName
.ACTIVE
)) {
80 triggerChangeEvent
= false
83 const activeElement
= $(rootElement
).find(Selector
.ACTIVE
)[0]
86 $(activeElement
).removeClass(ClassName
.ACTIVE
)
91 if (triggerChangeEvent
) {
92 input
.checked
= !$(this._element
).hasClass(ClassName
.ACTIVE
)
93 $(input
).trigger('change')
101 this._element
.setAttribute('aria-pressed',
102 !$(this._element
).hasClass(ClassName
.ACTIVE
))
104 if (triggerChangeEvent
) {
105 $(this._element
).toggleClass(ClassName
.ACTIVE
)
110 $.removeData(this._element
, DATA_KEY
)
117 static _jQueryInterface(config
) {
118 return this.each(function () {
119 let data
= $(this).data(DATA_KEY
)
122 data
= new Button(this)
123 $(this).data(DATA_KEY
, data
)
126 if (config
=== 'toggle') {
136 * ------------------------------------------------------------------------
137 * Data Api implementation
138 * ------------------------------------------------------------------------
142 .on(Event
.CLICK_DATA_API
, Selector
.DATA_TOGGLE_CARROT
, (event
) => {
143 event
.preventDefault()
145 let button
= event
.target
147 if (!$(button
).hasClass(ClassName
.BUTTON
)) {
148 button
= $(button
).closest(Selector
.BUTTON
)
151 Button
._jQueryInterface
.call($(button
), 'toggle')
153 .on(Event
.FOCUS_BLUR_DATA_API
, Selector
.DATA_TOGGLE_CARROT
, (event
) => {
154 const button
= $(event
.target
).closest(Selector
.BUTTON
)[0]
155 $(button
).toggleClass(ClassName
.FOCUS
, /^focus(in)?$/.test(event
.type
))
160 * ------------------------------------------------------------------------
162 * ------------------------------------------------------------------------
165 $.fn
[NAME
] = Button
._jQueryInterface
166 $.fn
[NAME
].Constructor
= Button
167 $.fn
[NAME
].noConflict = function () {
168 $.fn
[NAME
] = JQUERY_NO_CONFLICT
169 return Button
._jQueryInterface
176 export default Button