Completed
Push — master ( ff1498...661f20 )
by Jeroen De
27s queued 13s
created

resources/bootstrap/js/alert.js   A

Complexity

Total Complexity 36
Complexity/F 1.8

Size

Lines of Code 186
Function Count 20

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 97
dl 0
loc 186
rs 9.52
c 0
b 0
f 0
wmc 36
mnd 16
bc 16
fnc 20
bpm 0.8
cpm 1.8
noi 7

13 Functions

Rating   Name   Duplication   Size   Complexity  
B alert.js ➔ _interopDefaultLegacy 0 1 7
A alert.js ➔ _defineProperties 0 9 3
A alert.js ➔ _removeElement 0 16 3
A alert.js ➔ _handleDismiss 0 9 3
A alert.js ➔ dispose 0 4 1
A alert.js ➔ get 0 3 1
A alert.js ➔ _destroyElement 0 3 1
A alert.js ➔ close 0 15 3
A alert.js ➔ _getRootElement 0 14 3
A alert.js ➔ Alert 0 3 2
A alert.js ➔ _triggerCloseEvent 0 5 1
A alert.js ➔ _jQueryInterface 0 15 4
A alert.js ➔ _createClass 0 5 3
1
/*!
2
  * Bootstrap alert.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 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
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ 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.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.jQuery, global.Util));
0 ignored issues
show
Bug introduced by
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.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
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 for statements.

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.

Loading history...
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
Coding Style Best Practice introduced by
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 b = 42 will always be executed, while the logging statement will be executed conditionally.

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.

Loading history...
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
Coding Style Best Practice introduced by
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 b = 42 will always be executed, while the logging statement will be executed conditionally.

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.

Loading history...
29
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
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 b = 42 will always be executed, while the logging statement will be executed conditionally.

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.

Loading history...
30
    return Constructor;
31
  }
32
33
  /**
34
   * ------------------------------------------------------------------------
35
   * Constants
36
   * ------------------------------------------------------------------------
37
   */
38
39
  var NAME = 'alert';
40
  var VERSION = '4.6.0';
41
  var DATA_KEY = 'bs.alert';
42
  var EVENT_KEY = "." + DATA_KEY;
43
  var DATA_API_KEY = '.data-api';
44
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
45
  var SELECTOR_DISMISS = '[data-dismiss="alert"]';
46
  var EVENT_CLOSE = "close" + EVENT_KEY;
47
  var EVENT_CLOSED = "closed" + EVENT_KEY;
48
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
49
  var CLASS_NAME_ALERT = 'alert';
50
  var CLASS_NAME_FADE = 'fade';
51
  var CLASS_NAME_SHOW = 'show';
52
  /**
53
   * ------------------------------------------------------------------------
54
   * Class Definition
55
   * ------------------------------------------------------------------------
56
   */
57
58
  var Alert = /*#__PURE__*/function () {
59
    function Alert(element) {
60
      this._element = element;
61
    } // Getters
62
63
64
    var _proto = Alert.prototype;
65
66
    // Public
67
    _proto.close = function close(element) {
68
      var rootElement = this._element;
69
70
      if (element) {
71
        rootElement = this._getRootElement(element);
72
      }
73
74
      var customEvent = this._triggerCloseEvent(rootElement);
75
76
      if (customEvent.isDefaultPrevented()) {
77
        return;
78
      }
79
80
      this._removeElement(rootElement);
81
    };
82
83
    _proto.dispose = function dispose() {
84
      $__default['default'].removeData(this._element, DATA_KEY);
85
      this._element = null;
86
    } // Private
87
    ;
88
89
    _proto._getRootElement = function _getRootElement(element) {
90
      var selector = Util__default['default'].getSelectorFromElement(element);
91
      var parent = false;
92
93
      if (selector) {
94
        parent = document.querySelector(selector);
95
      }
96
97
      if (!parent) {
98
        parent = $__default['default'](element).closest("." + CLASS_NAME_ALERT)[0];
99
      }
100
101
      return parent;
102
    };
103
104
    _proto._triggerCloseEvent = function _triggerCloseEvent(element) {
105
      var closeEvent = $__default['default'].Event(EVENT_CLOSE);
106
      $__default['default'](element).trigger(closeEvent);
107
      return closeEvent;
108
    };
109
110
    _proto._removeElement = function _removeElement(element) {
111
      var _this = this;
112
113
      $__default['default'](element).removeClass(CLASS_NAME_SHOW);
114
115
      if (!$__default['default'](element).hasClass(CLASS_NAME_FADE)) {
116
        this._destroyElement(element);
117
118
        return;
119
      }
120
121
      var transitionDuration = Util__default['default'].getTransitionDurationFromElement(element);
122
      $__default['default'](element).one(Util__default['default'].TRANSITION_END, function (event) {
123
        return _this._destroyElement(element, event);
124
      }).emulateTransitionEnd(transitionDuration);
125
    };
126
127
    _proto._destroyElement = function _destroyElement(element) {
128
      $__default['default'](element).detach().trigger(EVENT_CLOSED).remove();
129
    } // Static
130
    ;
131
132
    Alert._jQueryInterface = function _jQueryInterface(config) {
133
      return this.each(function () {
134
        var $element = $__default['default'](this);
135
        var data = $element.data(DATA_KEY);
136
137
        if (!data) {
138
          data = new Alert(this);
139
          $element.data(DATA_KEY, data);
140
        }
141
142
        if (config === 'close') {
143
          data[config](this);
144
        }
145
      });
146
    };
147
148
    Alert._handleDismiss = function _handleDismiss(alertInstance) {
149
      return function (event) {
150
        if (event) {
151
          event.preventDefault();
152
        }
153
154
        alertInstance.close(this);
155
      };
156
    };
157
158
    _createClass(Alert, null, [{
159
      key: "VERSION",
160
      get: function get() {
161
        return VERSION;
162
      }
163
    }]);
164
165
    return Alert;
166
  }();
167
  /**
168
   * ------------------------------------------------------------------------
169
   * Data Api implementation
170
   * ------------------------------------------------------------------------
171
   */
172
173
174
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert._handleDismiss(new Alert()));
175
  /**
176
   * ------------------------------------------------------------------------
177
   * jQuery
178
   * ------------------------------------------------------------------------
179
   */
180
181
  $__default['default'].fn[NAME] = Alert._jQueryInterface;
182
  $__default['default'].fn[NAME].Constructor = Alert;
183
184
  $__default['default'].fn[NAME].noConflict = function () {
185
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
186
    return Alert._jQueryInterface;
187
  };
188
189
  return Alert;
190
191
})));
192
//# sourceMappingURL=alert.js.map
193