twbs--bootstrap/js/dist/alert.js

176 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-09-30 21:28:03 +00:00
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2017-09-06 04:05:12 +00:00
2017-09-30 21:28:03 +00:00
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2015-05-07 19:48:22 +00:00
/**
* --------------------------------------------------------------------------
2017-12-28 17:16:39 +00:00
* Bootstrap (v4.0.0-beta.3): alert.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2015-05-07 19:48:22 +00:00
* --------------------------------------------------------------------------
*/
2017-10-25 19:31:55 +00:00
var Alert = function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'alert';
2017-12-28 17:16:39 +00:00
var VERSION = '4.0.0-beta.3';
var DATA_KEY = 'bs.alert';
2017-09-30 21:28:03 +00:00
var EVENT_KEY = "." + DATA_KEY;
2015-05-13 19:48:34 +00:00
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 150;
var Selector = {
DISMISS: '[data-dismiss="alert"]'
};
var Event = {
2017-09-30 21:28:03 +00:00
CLOSE: "close" + EVENT_KEY,
CLOSED: "closed" + EVENT_KEY,
CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
ALERT: 'alert',
FADE: 'fade',
2016-12-20 05:48:24 +00:00
SHOW: 'show'
2017-09-13 05:24:15 +00:00
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2017-09-13 05:24:15 +00:00
};
2017-09-30 21:28:03 +00:00
var Alert =
/*#__PURE__*/
function () {
function Alert(element) {
2015-05-08 05:26:40 +00:00
this._element = element;
2018-01-12 06:42:40 +00:00
} // Getters
2017-09-30 21:28:03 +00:00
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
var _proto = Alert.prototype;
2015-08-13 04:12:03 +00:00
2018-01-12 06:42:40 +00:00
// Public
2017-09-30 21:28:03 +00:00
_proto.close = function close(element) {
element = element || this._element;
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
var rootElement = this._getRootElement(element);
2015-05-08 00:07:38 +00:00
2017-09-30 21:28:03 +00:00
var customEvent = this._triggerCloseEvent(rootElement);
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
if (customEvent.isDefaultPrevented()) {
return;
}
2016-10-10 00:26:51 +00:00
2017-09-30 21:28:03 +00:00
this._removeElement(rootElement);
};
2016-10-10 00:26:51 +00:00
2017-09-30 21:28:03 +00:00
_proto.dispose = function dispose() {
$.removeData(this._element, DATA_KEY);
this._element = null;
2018-01-12 06:42:40 +00:00
}; // Private
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
_proto._getRootElement = function _getRootElement(element) {
var selector = Util.getSelectorFromElement(element);
var parent = false;
if (selector) {
parent = $(selector)[0];
2015-05-07 19:48:22 +00:00
}
2017-09-30 21:28:03 +00:00
if (!parent) {
parent = $(element).closest("." + ClassName.ALERT)[0];
2015-05-13 19:48:34 +00:00
}
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
return parent;
};
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
_proto._triggerCloseEvent = function _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE);
$(element).trigger(closeEvent);
return closeEvent;
};
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
_proto._removeElement = function _removeElement(element) {
var _this = this;
2016-11-01 04:36:10 +00:00
2017-09-30 21:28:03 +00:00
$(element).removeClass(ClassName.SHOW);
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) {
this._destroyElement(element);
2015-08-19 03:28:28 +00:00
2017-09-30 21:28:03 +00:00
return;
2017-09-06 04:05:12 +00:00
}
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
$(element).one(Util.TRANSITION_END, function (event) {
return _this._destroyElement(element, event);
}).emulateTransitionEnd(TRANSITION_DURATION);
};
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
_proto._destroyElement = function _destroyElement(element) {
$(element).detach().trigger(Event.CLOSED).remove();
2018-01-12 06:42:40 +00:00
}; // Static
2015-05-07 19:48:22 +00:00
2016-10-10 00:26:51 +00:00
2017-09-30 21:28:03 +00:00
Alert._jQueryInterface = function _jQueryInterface(config) {
return this.each(function () {
var $element = $(this);
var data = $element.data(DATA_KEY);
2017-09-06 04:05:12 +00:00
2017-09-30 21:28:03 +00:00
if (!data) {
data = new Alert(this);
$element.data(DATA_KEY, data);
}
2016-10-10 00:26:51 +00:00
2017-09-30 21:28:03 +00:00
if (config === 'close') {
data[config](this);
}
});
};
2016-10-10 00:26:51 +00:00
2017-09-30 21:28:03 +00:00
Alert._handleDismiss = function _handleDismiss(alertInstance) {
return function (event) {
if (event) {
event.preventDefault();
}
alertInstance.close(this);
};
};
_createClass(Alert, null, [{
key: "VERSION",
2015-08-13 04:12:03 +00:00
get: function get() {
return VERSION;
}
}]);
2015-05-07 19:48:22 +00:00
return Alert;
2016-10-10 00:26:51 +00:00
}();
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
2015-05-07 19:48:22 +00:00
2017-09-30 21:28:03 +00:00
$(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()));
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
2015-05-07 19:48:22 +00:00
2017-07-02 17:40:27 +00:00
$.fn[NAME] = Alert._jQueryInterface;
$.fn[NAME].Constructor = Alert;
2017-09-30 21:28:03 +00:00
$.fn[NAME].noConflict = function () {
2015-05-08 00:07:38 +00:00
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Alert._jQueryInterface;
};
2015-05-07 19:48:22 +00:00
return Alert;
2017-10-15 22:51:44 +00:00
}($);
2017-04-22 06:58:09 +00:00
//# sourceMappingURL=alert.js.map