corrade-http-templates – Blame information for rev 61

Subversion Repositories:
Rev:
Rev Author Line No. Line
61 office 1 import $ from 'jquery'
2  
3 /**
4 * --------------------------------------------------------------------------
5 * Bootstrap (v4.1.3): button.js
6 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7 * --------------------------------------------------------------------------
8 */
9  
10 const Button = (($) => {
11 /**
12 * ------------------------------------------------------------------------
13 * Constants
14 * ------------------------------------------------------------------------
15 */
16  
17 const NAME = 'button'
18 const VERSION = '4.1.3'
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]
23  
24 const ClassName = {
25 ACTIVE : 'active',
26 BUTTON : 'btn',
27 FOCUS : 'focus'
28 }
29  
30 const Selector = {
31 DATA_TOGGLE_CARROT : '[data-toggle^="button"]',
32 DATA_TOGGLE : '[data-toggle="buttons"]',
33 INPUT : 'input',
34 ACTIVE : '.active',
35 BUTTON : '.btn'
36 }
37  
38 const Event = {
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}`
42 }
43  
44 /**
45 * ------------------------------------------------------------------------
46 * Class Definition
47 * ------------------------------------------------------------------------
48 */
49  
50 class Button {
51 constructor(element) {
52 this._element = element
53 }
54  
55 // Getters
56  
57 static get VERSION() {
58 return VERSION
59 }
60  
61 // Public
62  
63 toggle() {
64 let triggerChangeEvent = true
65 let addAriaPressed = true
66 const rootElement = $(this._element).closest(
67 Selector.DATA_TOGGLE
68 )[0]
69  
70 if (rootElement) {
71 const input = this._element.querySelector(Selector.INPUT)
72  
73 if (input) {
74 if (input.type === 'radio') {
75 if (input.checked &&
76 this._element.classList.contains(ClassName.ACTIVE)) {
77 triggerChangeEvent = false
78 } else {
79 const activeElement = rootElement.querySelector(Selector.ACTIVE)
80  
81 if (activeElement) {
82 $(activeElement).removeClass(ClassName.ACTIVE)
83 }
84 }
85 }
86  
87 if (triggerChangeEvent) {
88 if (input.hasAttribute('disabled') ||
89 rootElement.hasAttribute('disabled') ||
90 input.classList.contains('disabled') ||
91 rootElement.classList.contains('disabled')) {
92 return
93 }
94 input.checked = !this._element.classList.contains(ClassName.ACTIVE)
95 $(input).trigger('change')
96 }
97  
98 input.focus()
99 addAriaPressed = false
100 }
101 }
102  
103 if (addAriaPressed) {
104 this._element.setAttribute('aria-pressed',
105 !this._element.classList.contains(ClassName.ACTIVE))
106 }
107  
108 if (triggerChangeEvent) {
109 $(this._element).toggleClass(ClassName.ACTIVE)
110 }
111 }
112  
113 dispose() {
114 $.removeData(this._element, DATA_KEY)
115 this._element = null
116 }
117  
118 // Static
119  
120 static _jQueryInterface(config) {
121 return this.each(function () {
122 let data = $(this).data(DATA_KEY)
123  
124 if (!data) {
125 data = new Button(this)
126 $(this).data(DATA_KEY, data)
127 }
128  
129 if (config === 'toggle') {
130 data[config]()
131 }
132 })
133 }
134 }
135  
136 /**
137 * ------------------------------------------------------------------------
138 * Data Api implementation
139 * ------------------------------------------------------------------------
140 */
141  
142 $(document)
143 .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
144 event.preventDefault()
145  
146 let button = event.target
147  
148 if (!$(button).hasClass(ClassName.BUTTON)) {
149 button = $(button).closest(Selector.BUTTON)
150 }
151  
152 Button._jQueryInterface.call($(button), 'toggle')
153 })
154 .on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
155 const button = $(event.target).closest(Selector.BUTTON)[0]
156 $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type))
157 })
158  
159 /**
160 * ------------------------------------------------------------------------
161 * jQuery
162 * ------------------------------------------------------------------------
163 */
164  
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
170 }
171  
172 return Button
173 })($)
174  
175 export default Button