1 | /*! |
||
2 | * Bootstrap toast.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.Toast = 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 = 'toast'; |
||
58 | var VERSION = '4.6.2'; |
||
59 | var DATA_KEY = 'bs.toast'; |
||
60 | var EVENT_KEY = "." + DATA_KEY; |
||
61 | var JQUERY_NO_CONFLICT = $__default["default"].fn[NAME]; |
||
62 | var CLASS_NAME_FADE = 'fade'; |
||
63 | var CLASS_NAME_HIDE = 'hide'; |
||
64 | var CLASS_NAME_SHOW = 'show'; |
||
65 | var CLASS_NAME_SHOWING = 'showing'; |
||
66 | var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY; |
||
67 | var EVENT_HIDE = "hide" + EVENT_KEY; |
||
68 | var EVENT_HIDDEN = "hidden" + EVENT_KEY; |
||
69 | var EVENT_SHOW = "show" + EVENT_KEY; |
||
70 | var EVENT_SHOWN = "shown" + EVENT_KEY; |
||
71 | var SELECTOR_DATA_DISMISS = '[data-dismiss="toast"]'; |
||
72 | var Default = { |
||
73 | animation: true, |
||
74 | autohide: true, |
||
75 | delay: 500 |
||
76 | }; |
||
77 | var DefaultType = { |
||
78 | animation: 'boolean', |
||
79 | autohide: 'boolean', |
||
80 | delay: 'number' |
||
81 | }; |
||
82 | /** |
||
83 | * Class definition |
||
84 | */ |
||
85 | |||
86 | var Toast = /*#__PURE__*/function () { |
||
87 | function Toast(element, config) { |
||
88 | this._element = element; |
||
89 | this._config = this._getConfig(config); |
||
90 | this._timeout = null; |
||
91 | |||
92 | this._setListeners(); |
||
93 | } // Getters |
||
94 | |||
95 | |||
96 | var _proto = Toast.prototype; |
||
97 | |||
98 | // Public |
||
99 | _proto.show = function show() { |
||
100 | var _this = this; |
||
101 | |||
102 | var showEvent = $__default["default"].Event(EVENT_SHOW); |
||
103 | $__default["default"](this._element).trigger(showEvent); |
||
104 | |||
105 | if (showEvent.isDefaultPrevented()) { |
||
106 | return; |
||
107 | } |
||
108 | |||
109 | this._clearTimeout(); |
||
110 | |||
111 | if (this._config.animation) { |
||
112 | this._element.classList.add(CLASS_NAME_FADE); |
||
113 | } |
||
114 | |||
115 | var complete = function complete() { |
||
116 | _this._element.classList.remove(CLASS_NAME_SHOWING); |
||
117 | |||
118 | _this._element.classList.add(CLASS_NAME_SHOW); |
||
119 | |||
120 | $__default["default"](_this._element).trigger(EVENT_SHOWN); |
||
121 | |||
122 | if (_this._config.autohide) { |
||
123 | _this._timeout = setTimeout(function () { |
||
124 | _this.hide(); |
||
125 | }, _this._config.delay); |
||
126 | } |
||
127 | }; |
||
128 | |||
129 | this._element.classList.remove(CLASS_NAME_HIDE); |
||
130 | |||
131 | Util__default["default"].reflow(this._element); |
||
132 | |||
133 | this._element.classList.add(CLASS_NAME_SHOWING); |
||
134 | |||
135 | if (this._config.animation) { |
||
136 | var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._element); |
||
137 | $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); |
||
138 | } else { |
||
139 | complete(); |
||
140 | } |
||
141 | }; |
||
142 | |||
143 | _proto.hide = function hide() { |
||
144 | if (!this._element.classList.contains(CLASS_NAME_SHOW)) { |
||
145 | return; |
||
146 | } |
||
147 | |||
148 | var hideEvent = $__default["default"].Event(EVENT_HIDE); |
||
149 | $__default["default"](this._element).trigger(hideEvent); |
||
150 | |||
151 | if (hideEvent.isDefaultPrevented()) { |
||
152 | return; |
||
153 | } |
||
154 | |||
155 | this._close(); |
||
156 | }; |
||
157 | |||
158 | _proto.dispose = function dispose() { |
||
159 | this._clearTimeout(); |
||
160 | |||
161 | if (this._element.classList.contains(CLASS_NAME_SHOW)) { |
||
162 | this._element.classList.remove(CLASS_NAME_SHOW); |
||
163 | } |
||
164 | |||
165 | $__default["default"](this._element).off(EVENT_CLICK_DISMISS); |
||
166 | $__default["default"].removeData(this._element, DATA_KEY); |
||
167 | this._element = null; |
||
168 | this._config = null; |
||
169 | } // Private |
||
170 | ; |
||
171 | |||
172 | _proto._getConfig = function _getConfig(config) { |
||
173 | config = _extends({}, Default, $__default["default"](this._element).data(), typeof config === 'object' && config ? config : {}); |
||
174 | Util__default["default"].typeCheckConfig(NAME, config, this.constructor.DefaultType); |
||
175 | return config; |
||
176 | }; |
||
177 | |||
178 | _proto._setListeners = function _setListeners() { |
||
179 | var _this2 = this; |
||
180 | |||
181 | $__default["default"](this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function () { |
||
182 | return _this2.hide(); |
||
183 | }); |
||
184 | }; |
||
185 | |||
186 | _proto._close = function _close() { |
||
187 | var _this3 = this; |
||
188 | |||
189 | var complete = function complete() { |
||
190 | _this3._element.classList.add(CLASS_NAME_HIDE); |
||
191 | |||
192 | $__default["default"](_this3._element).trigger(EVENT_HIDDEN); |
||
193 | }; |
||
194 | |||
195 | this._element.classList.remove(CLASS_NAME_SHOW); |
||
196 | |||
197 | if (this._config.animation) { |
||
198 | var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._element); |
||
199 | $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); |
||
200 | } else { |
||
201 | complete(); |
||
202 | } |
||
203 | }; |
||
204 | |||
205 | _proto._clearTimeout = function _clearTimeout() { |
||
206 | clearTimeout(this._timeout); |
||
207 | this._timeout = null; |
||
208 | } // Static |
||
209 | ; |
||
210 | |||
211 | Toast._jQueryInterface = function _jQueryInterface(config) { |
||
212 | return this.each(function () { |
||
213 | var $element = $__default["default"](this); |
||
214 | var data = $element.data(DATA_KEY); |
||
215 | |||
216 | var _config = typeof config === 'object' && config; |
||
217 | |||
218 | if (!data) { |
||
219 | data = new Toast(this, _config); |
||
220 | $element.data(DATA_KEY, data); |
||
221 | } |
||
222 | |||
223 | if (typeof config === 'string') { |
||
224 | if (typeof data[config] === 'undefined') { |
||
225 | throw new TypeError("No method named \"" + config + "\""); |
||
226 | } |
||
227 | |||
228 | data[config](this); |
||
229 | } |
||
230 | }); |
||
231 | }; |
||
232 | |||
233 | _createClass(Toast, null, [{ |
||
234 | key: "VERSION", |
||
235 | get: function get() { |
||
236 | return VERSION; |
||
237 | } |
||
238 | }, { |
||
239 | key: "DefaultType", |
||
240 | get: function get() { |
||
241 | return DefaultType; |
||
242 | } |
||
243 | }, { |
||
244 | key: "Default", |
||
245 | get: function get() { |
||
246 | return Default; |
||
247 | } |
||
248 | }]); |
||
249 | |||
250 | return Toast; |
||
251 | }(); |
||
252 | /** |
||
253 | * jQuery |
||
254 | */ |
||
255 | |||
256 | |||
257 | $__default["default"].fn[NAME] = Toast._jQueryInterface; |
||
258 | $__default["default"].fn[NAME].Constructor = Toast; |
||
259 | |||
260 | $__default["default"].fn[NAME].noConflict = function () { |
||
261 | $__default["default"].fn[NAME] = JQUERY_NO_CONFLICT; |
||
262 | return Toast._jQueryInterface; |
||
263 | }; |
||
264 | |||
265 | return Toast; |
||
266 | |||
267 | })); |
||
268 | //# sourceMappingURL=toast.js.map |
||
269 |
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.