mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
176 lines
No EOL
4.8 KiB
JavaScript
176 lines
No EOL
4.8 KiB
JavaScript
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); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
/**
|
|
* --------------------------------------------------------------------------
|
|
* Bootstrap (v4.0.0-beta): alert.js
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* --------------------------------------------------------------------------
|
|
*/
|
|
var Alert = function () {
|
|
/**
|
|
* ------------------------------------------------------------------------
|
|
* Constants
|
|
* ------------------------------------------------------------------------
|
|
*/
|
|
var NAME = 'alert';
|
|
var VERSION = '4.0.0-beta';
|
|
var DATA_KEY = 'bs.alert';
|
|
var EVENT_KEY = "." + DATA_KEY;
|
|
var DATA_API_KEY = '.data-api';
|
|
var JQUERY_NO_CONFLICT = $.fn[NAME];
|
|
var TRANSITION_DURATION = 150;
|
|
var Selector = {
|
|
DISMISS: '[data-dismiss="alert"]'
|
|
};
|
|
var Event = {
|
|
CLOSE: "close" + EVENT_KEY,
|
|
CLOSED: "closed" + EVENT_KEY,
|
|
CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
|
|
};
|
|
var ClassName = {
|
|
ALERT: 'alert',
|
|
FADE: 'fade',
|
|
SHOW: 'show'
|
|
/**
|
|
* ------------------------------------------------------------------------
|
|
* Class Definition
|
|
* ------------------------------------------------------------------------
|
|
*/
|
|
|
|
};
|
|
|
|
var Alert =
|
|
/*#__PURE__*/
|
|
function () {
|
|
function Alert(element) {
|
|
this._element = element;
|
|
} // getters
|
|
|
|
|
|
var _proto = Alert.prototype;
|
|
|
|
// public
|
|
_proto.close = function close(element) {
|
|
element = element || this._element;
|
|
|
|
var rootElement = this._getRootElement(element);
|
|
|
|
var customEvent = this._triggerCloseEvent(rootElement);
|
|
|
|
if (customEvent.isDefaultPrevented()) {
|
|
return;
|
|
}
|
|
|
|
this._removeElement(rootElement);
|
|
};
|
|
|
|
_proto.dispose = function dispose() {
|
|
$.removeData(this._element, DATA_KEY);
|
|
this._element = null;
|
|
}; // private
|
|
|
|
|
|
_proto._getRootElement = function _getRootElement(element) {
|
|
var selector = Util.getSelectorFromElement(element);
|
|
var parent = false;
|
|
|
|
if (selector) {
|
|
parent = $(selector)[0];
|
|
}
|
|
|
|
if (!parent) {
|
|
parent = $(element).closest("." + ClassName.ALERT)[0];
|
|
}
|
|
|
|
return parent;
|
|
};
|
|
|
|
_proto._triggerCloseEvent = function _triggerCloseEvent(element) {
|
|
var closeEvent = $.Event(Event.CLOSE);
|
|
$(element).trigger(closeEvent);
|
|
return closeEvent;
|
|
};
|
|
|
|
_proto._removeElement = function _removeElement(element) {
|
|
var _this = this;
|
|
|
|
$(element).removeClass(ClassName.SHOW);
|
|
|
|
if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) {
|
|
this._destroyElement(element);
|
|
|
|
return;
|
|
}
|
|
|
|
$(element).one(Util.TRANSITION_END, function (event) {
|
|
return _this._destroyElement(element, event);
|
|
}).emulateTransitionEnd(TRANSITION_DURATION);
|
|
};
|
|
|
|
_proto._destroyElement = function _destroyElement(element) {
|
|
$(element).detach().trigger(Event.CLOSED).remove();
|
|
}; // static
|
|
|
|
|
|
Alert._jQueryInterface = function _jQueryInterface(config) {
|
|
return this.each(function () {
|
|
var $element = $(this);
|
|
var data = $element.data(DATA_KEY);
|
|
|
|
if (!data) {
|
|
data = new Alert(this);
|
|
$element.data(DATA_KEY, data);
|
|
}
|
|
|
|
if (config === 'close') {
|
|
data[config](this);
|
|
}
|
|
});
|
|
};
|
|
|
|
Alert._handleDismiss = function _handleDismiss(alertInstance) {
|
|
return function (event) {
|
|
if (event) {
|
|
event.preventDefault();
|
|
}
|
|
|
|
alertInstance.close(this);
|
|
};
|
|
};
|
|
|
|
_createClass(Alert, null, [{
|
|
key: "VERSION",
|
|
get: function get() {
|
|
return VERSION;
|
|
}
|
|
}]);
|
|
|
|
return Alert;
|
|
}();
|
|
/**
|
|
* ------------------------------------------------------------------------
|
|
* Data Api implementation
|
|
* ------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
$(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()));
|
|
/**
|
|
* ------------------------------------------------------------------------
|
|
* jQuery
|
|
* ------------------------------------------------------------------------
|
|
*/
|
|
|
|
$.fn[NAME] = Alert._jQueryInterface;
|
|
$.fn[NAME].Constructor = Alert;
|
|
|
|
$.fn[NAME].noConflict = function () {
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT;
|
|
return Alert._jQueryInterface;
|
|
};
|
|
|
|
return Alert;
|
|
}(jQuery);
|
|
//# sourceMappingURL=alert.js.map
|