1 | /*! |
||
2 | * Bootstrap collapse.js v4.6.2 (https://getbootstrap.com/) |
||
3 | * Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) |
||
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) |
||
5 | */ |
||
6 | (function (global, factory) { |
||
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) : |
||
8 | typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) : |
||
0 ignored issues
–
show
|
|||
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.jQuery, global.Util)); |
||
0 ignored issues
–
show
The variable
globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() Usage of the sequence operator is discouraged, since it may lead to obfuscated code.
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression. This operator is most often used in Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator. This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements. var a,b,c;
a = 1, b = 1, c= 3;
could just as well be written as: var a,b,c;
a = 1;
b = 1;
c = 3;
To learn more about the sequence operator, please refer to the MDN. ![]() |
|||
10 | })(this, (function ($, Util) { 'use strict'; |
||
11 | |||
12 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } |
||
13 | |||
14 | var $__default = /*#__PURE__*/_interopDefaultLegacy($); |
||
15 | var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util); |
||
16 | |||
17 | function _defineProperties(target, props) { |
||
18 | for (var i = 0; i < props.length; i++) { |
||
19 | var descriptor = props[i]; |
||
20 | descriptor.enumerable = descriptor.enumerable || false; |
||
21 | descriptor.configurable = true; |
||
22 | if ("value" in descriptor) descriptor.writable = true; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
23 | Object.defineProperty(target, descriptor.key, descriptor); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | function _createClass(Constructor, protoProps, staticProps) { |
||
28 | if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
29 | if (staticProps) _defineProperties(Constructor, staticProps); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
30 | Object.defineProperty(Constructor, "prototype", { |
||
31 | writable: false |
||
32 | }); |
||
33 | return Constructor; |
||
34 | } |
||
35 | |||
36 | function _extends() { |
||
37 | _extends = Object.assign ? Object.assign.bind() : function (target) { |
||
0 ignored issues
–
show
|
|||
38 | for (var i = 1; i < arguments.length; i++) { |
||
39 | var source = arguments[i]; |
||
40 | |||
41 | for (var key in source) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
![]() |
|||
42 | if (Object.prototype.hasOwnProperty.call(source, key)) { |
||
43 | target[key] = source[key]; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return target; |
||
49 | }; |
||
50 | return _extends.apply(this, arguments); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Constants |
||
55 | */ |
||
56 | |||
57 | var NAME = 'collapse'; |
||
58 | var VERSION = '4.6.2'; |
||
59 | var DATA_KEY = 'bs.collapse'; |
||
60 | var EVENT_KEY = "." + DATA_KEY; |
||
61 | var DATA_API_KEY = '.data-api'; |
||
62 | var JQUERY_NO_CONFLICT = $__default["default"].fn[NAME]; |
||
63 | var CLASS_NAME_SHOW = 'show'; |
||
64 | var CLASS_NAME_COLLAPSE = 'collapse'; |
||
65 | var CLASS_NAME_COLLAPSING = 'collapsing'; |
||
66 | var CLASS_NAME_COLLAPSED = 'collapsed'; |
||
67 | var DIMENSION_WIDTH = 'width'; |
||
68 | var DIMENSION_HEIGHT = 'height'; |
||
69 | var EVENT_SHOW = "show" + EVENT_KEY; |
||
70 | var EVENT_SHOWN = "shown" + EVENT_KEY; |
||
71 | var EVENT_HIDE = "hide" + EVENT_KEY; |
||
72 | var EVENT_HIDDEN = "hidden" + EVENT_KEY; |
||
73 | var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY; |
||
74 | var SELECTOR_ACTIVES = '.show, .collapsing'; |
||
75 | var SELECTOR_DATA_TOGGLE = '[data-toggle="collapse"]'; |
||
76 | var Default = { |
||
77 | toggle: true, |
||
78 | parent: '' |
||
79 | }; |
||
80 | var DefaultType = { |
||
81 | toggle: 'boolean', |
||
82 | parent: '(string|element)' |
||
83 | }; |
||
84 | /** |
||
85 | * Class definition |
||
86 | */ |
||
87 | |||
88 | var Collapse = /*#__PURE__*/function () { |
||
89 | function Collapse(element, config) { |
||
90 | this._isTransitioning = false; |
||
91 | this._element = element; |
||
92 | this._config = this._getConfig(config); |
||
93 | this._triggerArray = [].slice.call(document.querySelectorAll("[data-toggle=\"collapse\"][href=\"#" + element.id + "\"]," + ("[data-toggle=\"collapse\"][data-target=\"#" + element.id + "\"]"))); |
||
94 | var toggleList = [].slice.call(document.querySelectorAll(SELECTOR_DATA_TOGGLE)); |
||
95 | |||
96 | for (var i = 0, len = toggleList.length; i < len; i++) { |
||
97 | var elem = toggleList[i]; |
||
98 | var selector = Util__default["default"].getSelectorFromElement(elem); |
||
99 | var filterElement = [].slice.call(document.querySelectorAll(selector)).filter(function (foundElem) { |
||
100 | return foundElem === element; |
||
101 | }); |
||
102 | |||
103 | if (selector !== null && filterElement.length > 0) { |
||
104 | this._selector = selector; |
||
105 | |||
106 | this._triggerArray.push(elem); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | this._parent = this._config.parent ? this._getParent() : null; |
||
111 | |||
112 | if (!this._config.parent) { |
||
113 | this._addAriaAndCollapsedClass(this._element, this._triggerArray); |
||
114 | } |
||
115 | |||
116 | if (this._config.toggle) { |
||
117 | this.toggle(); |
||
118 | } |
||
119 | } // Getters |
||
120 | |||
121 | |||
122 | var _proto = Collapse.prototype; |
||
123 | |||
124 | // Public |
||
125 | _proto.toggle = function toggle() { |
||
126 | if ($__default["default"](this._element).hasClass(CLASS_NAME_SHOW)) { |
||
127 | this.hide(); |
||
128 | } else { |
||
129 | this.show(); |
||
130 | } |
||
131 | }; |
||
132 | |||
133 | _proto.show = function show() { |
||
134 | var _this = this; |
||
135 | |||
136 | if (this._isTransitioning || $__default["default"](this._element).hasClass(CLASS_NAME_SHOW)) { |
||
137 | return; |
||
138 | } |
||
139 | |||
140 | var actives; |
||
141 | var activesData; |
||
142 | |||
143 | if (this._parent) { |
||
144 | actives = [].slice.call(this._parent.querySelectorAll(SELECTOR_ACTIVES)).filter(function (elem) { |
||
145 | if (typeof _this._config.parent === 'string') { |
||
146 | return elem.getAttribute('data-parent') === _this._config.parent; |
||
147 | } |
||
148 | |||
149 | return elem.classList.contains(CLASS_NAME_COLLAPSE); |
||
150 | }); |
||
151 | |||
152 | if (actives.length === 0) { |
||
153 | actives = null; |
||
154 | } |
||
155 | } |
||
156 | |||
157 | if (actives) { |
||
158 | activesData = $__default["default"](actives).not(this._selector).data(DATA_KEY); |
||
159 | |||
160 | if (activesData && activesData._isTransitioning) { |
||
161 | return; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | var startEvent = $__default["default"].Event(EVENT_SHOW); |
||
166 | $__default["default"](this._element).trigger(startEvent); |
||
167 | |||
168 | if (startEvent.isDefaultPrevented()) { |
||
169 | return; |
||
170 | } |
||
171 | |||
172 | if (actives) { |
||
173 | Collapse._jQueryInterface.call($__default["default"](actives).not(this._selector), 'hide'); |
||
174 | |||
175 | if (!activesData) { |
||
176 | $__default["default"](actives).data(DATA_KEY, null); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | var dimension = this._getDimension(); |
||
181 | |||
182 | $__default["default"](this._element).removeClass(CLASS_NAME_COLLAPSE).addClass(CLASS_NAME_COLLAPSING); |
||
183 | this._element.style[dimension] = 0; |
||
184 | |||
185 | if (this._triggerArray.length) { |
||
186 | $__default["default"](this._triggerArray).removeClass(CLASS_NAME_COLLAPSED).attr('aria-expanded', true); |
||
187 | } |
||
188 | |||
189 | this.setTransitioning(true); |
||
190 | |||
191 | var complete = function complete() { |
||
192 | $__default["default"](_this._element).removeClass(CLASS_NAME_COLLAPSING).addClass(CLASS_NAME_COLLAPSE + " " + CLASS_NAME_SHOW); |
||
193 | _this._element.style[dimension] = ''; |
||
194 | |||
195 | _this.setTransitioning(false); |
||
196 | |||
197 | $__default["default"](_this._element).trigger(EVENT_SHOWN); |
||
198 | }; |
||
199 | |||
200 | var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1); |
||
201 | var scrollSize = "scroll" + capitalizedDimension; |
||
202 | var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._element); |
||
203 | $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); |
||
204 | this._element.style[dimension] = this._element[scrollSize] + "px"; |
||
205 | }; |
||
206 | |||
207 | _proto.hide = function hide() { |
||
208 | var _this2 = this; |
||
209 | |||
210 | if (this._isTransitioning || !$__default["default"](this._element).hasClass(CLASS_NAME_SHOW)) { |
||
211 | return; |
||
212 | } |
||
213 | |||
214 | var startEvent = $__default["default"].Event(EVENT_HIDE); |
||
215 | $__default["default"](this._element).trigger(startEvent); |
||
216 | |||
217 | if (startEvent.isDefaultPrevented()) { |
||
218 | return; |
||
219 | } |
||
220 | |||
221 | var dimension = this._getDimension(); |
||
222 | |||
223 | this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px"; |
||
224 | Util__default["default"].reflow(this._element); |
||
225 | $__default["default"](this._element).addClass(CLASS_NAME_COLLAPSING).removeClass(CLASS_NAME_COLLAPSE + " " + CLASS_NAME_SHOW); |
||
226 | var triggerArrayLength = this._triggerArray.length; |
||
227 | |||
228 | if (triggerArrayLength > 0) { |
||
229 | for (var i = 0; i < triggerArrayLength; i++) { |
||
230 | var trigger = this._triggerArray[i]; |
||
231 | var selector = Util__default["default"].getSelectorFromElement(trigger); |
||
232 | |||
233 | if (selector !== null) { |
||
234 | var $elem = $__default["default"]([].slice.call(document.querySelectorAll(selector))); |
||
235 | |||
236 | if (!$elem.hasClass(CLASS_NAME_SHOW)) { |
||
237 | $__default["default"](trigger).addClass(CLASS_NAME_COLLAPSED).attr('aria-expanded', false); |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | |||
243 | this.setTransitioning(true); |
||
244 | |||
245 | var complete = function complete() { |
||
246 | _this2.setTransitioning(false); |
||
247 | |||
248 | $__default["default"](_this2._element).removeClass(CLASS_NAME_COLLAPSING).addClass(CLASS_NAME_COLLAPSE).trigger(EVENT_HIDDEN); |
||
249 | }; |
||
250 | |||
251 | this._element.style[dimension] = ''; |
||
252 | var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._element); |
||
253 | $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); |
||
254 | }; |
||
255 | |||
256 | _proto.setTransitioning = function setTransitioning(isTransitioning) { |
||
257 | this._isTransitioning = isTransitioning; |
||
258 | }; |
||
259 | |||
260 | _proto.dispose = function dispose() { |
||
261 | $__default["default"].removeData(this._element, DATA_KEY); |
||
262 | this._config = null; |
||
263 | this._parent = null; |
||
264 | this._element = null; |
||
265 | this._triggerArray = null; |
||
266 | this._isTransitioning = null; |
||
267 | } // Private |
||
268 | ; |
||
269 | |||
270 | _proto._getConfig = function _getConfig(config) { |
||
271 | config = _extends({}, Default, config); |
||
272 | config.toggle = Boolean(config.toggle); // Coerce string values |
||
273 | |||
274 | Util__default["default"].typeCheckConfig(NAME, config, DefaultType); |
||
275 | return config; |
||
276 | }; |
||
277 | |||
278 | _proto._getDimension = function _getDimension() { |
||
279 | var hasWidth = $__default["default"](this._element).hasClass(DIMENSION_WIDTH); |
||
280 | return hasWidth ? DIMENSION_WIDTH : DIMENSION_HEIGHT; |
||
281 | }; |
||
282 | |||
283 | _proto._getParent = function _getParent() { |
||
284 | var _this3 = this; |
||
285 | |||
286 | var parent; |
||
287 | |||
288 | if (Util__default["default"].isElement(this._config.parent)) { |
||
289 | parent = this._config.parent; // It's a jQuery object |
||
290 | |||
291 | if (typeof this._config.parent.jquery !== 'undefined') { |
||
292 | parent = this._config.parent[0]; |
||
293 | } |
||
294 | } else { |
||
295 | parent = document.querySelector(this._config.parent); |
||
296 | } |
||
297 | |||
298 | var selector = "[data-toggle=\"collapse\"][data-parent=\"" + this._config.parent + "\"]"; |
||
299 | var children = [].slice.call(parent.querySelectorAll(selector)); |
||
300 | $__default["default"](children).each(function (i, element) { |
||
301 | _this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]); |
||
302 | }); |
||
303 | return parent; |
||
304 | }; |
||
305 | |||
306 | _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) { |
||
307 | var isOpen = $__default["default"](element).hasClass(CLASS_NAME_SHOW); |
||
308 | |||
309 | if (triggerArray.length) { |
||
310 | $__default["default"](triggerArray).toggleClass(CLASS_NAME_COLLAPSED, !isOpen).attr('aria-expanded', isOpen); |
||
311 | } |
||
312 | } // Static |
||
313 | ; |
||
314 | |||
315 | Collapse._getTargetFromElement = function _getTargetFromElement(element) { |
||
316 | var selector = Util__default["default"].getSelectorFromElement(element); |
||
317 | return selector ? document.querySelector(selector) : null; |
||
318 | }; |
||
319 | |||
320 | Collapse._jQueryInterface = function _jQueryInterface(config) { |
||
321 | return this.each(function () { |
||
322 | var $element = $__default["default"](this); |
||
323 | var data = $element.data(DATA_KEY); |
||
324 | |||
325 | var _config = _extends({}, Default, $element.data(), typeof config === 'object' && config ? config : {}); |
||
326 | |||
327 | if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) { |
||
328 | _config.toggle = false; |
||
329 | } |
||
330 | |||
331 | if (!data) { |
||
332 | data = new Collapse(this, _config); |
||
333 | $element.data(DATA_KEY, data); |
||
334 | } |
||
335 | |||
336 | if (typeof config === 'string') { |
||
337 | if (typeof data[config] === 'undefined') { |
||
338 | throw new TypeError("No method named \"" + config + "\""); |
||
339 | } |
||
340 | |||
341 | data[config](); |
||
342 | } |
||
343 | }); |
||
344 | }; |
||
345 | |||
346 | _createClass(Collapse, null, [{ |
||
347 | key: "VERSION", |
||
348 | get: function get() { |
||
349 | return VERSION; |
||
350 | } |
||
351 | }, { |
||
352 | key: "Default", |
||
353 | get: function get() { |
||
354 | return Default; |
||
355 | } |
||
356 | }]); |
||
357 | |||
358 | return Collapse; |
||
359 | }(); |
||
360 | /** |
||
361 | * Data API implementation |
||
362 | */ |
||
363 | |||
364 | |||
365 | $__default["default"](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { |
||
366 | // preventDefault only for <a> elements (which change the URL) not inside the collapsible element |
||
367 | if (event.currentTarget.tagName === 'A') { |
||
368 | event.preventDefault(); |
||
369 | } |
||
370 | |||
371 | var $trigger = $__default["default"](this); |
||
372 | var selector = Util__default["default"].getSelectorFromElement(this); |
||
373 | var selectors = [].slice.call(document.querySelectorAll(selector)); |
||
374 | $__default["default"](selectors).each(function () { |
||
375 | var $target = $__default["default"](this); |
||
376 | var data = $target.data(DATA_KEY); |
||
377 | var config = data ? 'toggle' : $trigger.data(); |
||
378 | |||
379 | Collapse._jQueryInterface.call($target, config); |
||
380 | }); |
||
381 | }); |
||
382 | /** |
||
383 | * jQuery |
||
384 | */ |
||
385 | |||
386 | $__default["default"].fn[NAME] = Collapse._jQueryInterface; |
||
387 | $__default["default"].fn[NAME].Constructor = Collapse; |
||
388 | |||
389 | $__default["default"].fn[NAME].noConflict = function () { |
||
390 | $__default["default"].fn[NAME] = JQUERY_NO_CONFLICT; |
||
391 | return Collapse._jQueryInterface; |
||
392 | }; |
||
393 | |||
394 | return Collapse; |
||
395 | |||
396 | })); |
||
397 | //# sourceMappingURL=collapse.js.map |
||
398 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.