source: trip-planner-front/node_modules/bootstrap/js/src/button.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * --------------------------------------------------------------------------
3 * Bootstrap (v5.1.3): button.js
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5 * --------------------------------------------------------------------------
6 */
7
8import { defineJQueryPlugin } from './util/index'
9import EventHandler from './dom/event-handler'
10import BaseComponent from './base-component'
11
12/**
13 * ------------------------------------------------------------------------
14 * Constants
15 * ------------------------------------------------------------------------
16 */
17
18const NAME = 'button'
19const DATA_KEY = 'bs.button'
20const EVENT_KEY = `.${DATA_KEY}`
21const DATA_API_KEY = '.data-api'
22
23const CLASS_NAME_ACTIVE = 'active'
24
25const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]'
26
27const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
28
29/**
30 * ------------------------------------------------------------------------
31 * Class Definition
32 * ------------------------------------------------------------------------
33 */
34
35class Button extends BaseComponent {
36 // Getters
37
38 static get NAME() {
39 return NAME
40 }
41
42 // Public
43
44 toggle() {
45 // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
46 this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE))
47 }
48
49 // Static
50
51 static jQueryInterface(config) {
52 return this.each(function () {
53 const data = Button.getOrCreateInstance(this)
54
55 if (config === 'toggle') {
56 data[config]()
57 }
58 })
59 }
60}
61
62/**
63 * ------------------------------------------------------------------------
64 * Data Api implementation
65 * ------------------------------------------------------------------------
66 */
67
68EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
69 event.preventDefault()
70
71 const button = event.target.closest(SELECTOR_DATA_TOGGLE)
72 const data = Button.getOrCreateInstance(button)
73
74 data.toggle()
75})
76
77/**
78 * ------------------------------------------------------------------------
79 * jQuery
80 * ------------------------------------------------------------------------
81 * add .Button to jQuery only if jQuery is present
82 */
83
84defineJQueryPlugin(Button)
85
86export default Button
Note: See TracBrowser for help on using the repository browser.