in security-admin/src/main/webapp/libs/bower/bootprompt/bootprompt.js [204:423]
function dialog(options) {
var e_2, _a, e_3, _b;
var finalOptions = sanitize(options);
var $modal = $(templates.dialog);
var modal = $modal[0];
var innerDialog = modal.getElementsByClassName("modal-dialog")[0];
var body = modal.getElementsByClassName("modal-body")[0];
var footer = $(templates.footer)[0];
var callbacks = {
onEscape: finalOptions.onEscape,
onClose: finalOptions.onClose,
};
if (callbacks.onEscape === undefined) {
callbacks.onEscape = true;
}
var buttons = finalOptions.buttons, backdrop = finalOptions.backdrop, className = finalOptions.className, closeButton = finalOptions.closeButton, message = finalOptions.message, size = finalOptions.size, title = finalOptions.title;
// tslint:disable-next-line:no-non-null-assertion
var bpBody = body.getElementsByClassName("bootprompt-body")[0];
if (typeof message === "string") {
// tslint:disable-next-line:no-inner-html
bpBody.innerHTML = message;
}
else {
// tslint:disable-next-line:no-inner-html
bpBody.innerHTML = "";
$(bpBody).append(message);
}
var hadButtons = false;
// tslint:disable-next-line:forin
for (var key in buttons) {
hadButtons = true;
var b = buttons[key];
var $button = $(templates.button);
var button = $button[0];
$button.data("bp-handler", key);
try {
// On IE10/11 it is not possible to just do x.classList.add(a, b, c).
for (var _c = __values(b.className.split(" ")), _d = _c.next(); !_d.done; _d = _c.next()) {
var cl = _d.value;
button.classList.add(cl);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
switch (key) {
case "ok":
case "confirm":
button.classList.add("bootprompt-accept");
break;
case "cancel":
button.classList.add("bootprompt-cancel");
break;
default:
}
// tslint:disable-next-line:no-inner-html
button.innerHTML = b.label;
footer.appendChild(button);
callbacks[key] = b.callback;
}
// Only attempt to create buttons if at least one has been defined in the
// options object.
if (hadButtons) {
// tslint:disable-next-line:no-non-null-assertion
body.parentNode.insertBefore(footer, body.nextSibling);
}
if (finalOptions.animate === true) {
modal.classList.add("fade");
}
if (className !== undefined) {
try {
// On IE10/11 it is not possible to just do x.classList.add(a, b, c).
for (var _e = __values(className.split(" ")), _f = _e.next(); !_f.done; _f = _e.next()) {
var cl = _f.value;
modal.classList.add(cl);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
}
if (size !== undefined) {
// Requires Bootstrap 3.1.0 or higher
/* istanbul ignore if: we don't systematically test with old versions */
if (fullBootstrapVersion.substring(0, 3) < "3.1") {
// tslint:disable-next-line:no-console
console.warn("\"size\" requires Bootstrap 3.1.0 or higher. You appear to be using " + fullBootstrapVersion + ". Please upgrade to use this option.");
}
switch (size) {
case "large":
innerDialog.classList.add("modal-lg");
break;
case "small":
innerDialog.classList.add("modal-sm");
break;
default:
var q = size;
throw new Error("unknown size value: " + q);
}
}
if (title !== undefined) {
// tslint:disable-next-line:no-non-null-assertion
body.parentNode.insertBefore($(templates.header)[0], body);
var modalTitle = modal.getElementsByClassName("modal-title")[0];
if (typeof title === "string") {
// tslint:disable-next-line:no-inner-html
modalTitle.innerHTML = title;
}
else {
// tslint:disable-next-line:no-inner-html
modalTitle.innerHTML = "";
$(modalTitle).append(title);
}
}
if (closeButton === true) {
var closeButtonEl = $(templates.closeButton)[0];
if (title !== undefined) {
var modalHeader = modal.getElementsByClassName("modal-header")[0];
/* istanbul ignore else: we don't systematically test on old versions */
if (bootstrapVersion > 3) {
modalHeader.appendChild(closeButtonEl);
}
else {
modalHeader.insertBefore(closeButtonEl, modalHeader.firstChild);
}
}
else {
body.insertBefore(closeButtonEl, body.firstChild);
}
}
if (finalOptions.centerVertical !== undefined) {
// Requires Bootstrap 4.0.0 or higher
/* istanbul ignore if: we don't systematically test with old versions */
if (fullBootstrapVersion < "4.0.0") {
// tslint:disable-next-line:no-console
console.warn("\"centerVertical\" requires Bootstrap 4.0.0 or higher. You appear to be using " + fullBootstrapVersion + ". Please upgrade to use this option.");
}
innerDialog.classList.add("modal-dialog-centered");
}
// Bootstrap event listeners; these handle extra setup & teardown required
// after the underlying modal has performed certain actions.
$modal.one("hidden.bs.modal", function () {
$modal.off("escape.close.bp");
$modal.off("click");
$modal.remove();
});
$modal.one("shown.bs.modal", function () {
// tslint:disable-next-line:no-non-null-assertion
$(modal.querySelector(".btn-primary")).trigger("focus");
});
// Bootprompt event listeners; used to decouple some
// behaviours from their respective triggers
if (backdrop !== "static") {
// A boolean true/false according to the Bootstrap docs
// should show a dialog the user can dismiss by clicking on
// the background.
// We always only ever pass static/false to the actual
// $.modal function because with "true" we can't trap
// this event (the .modal-backdrop swallows it)
// However, we still want to sort of respect true
// and invoke the escape mechanism instead
$modal.on("click.dismiss.bs.modal", function (e) {
// The target varies in 3.3.x releases since the modal backdrop moved
// *inside* the outer dialog rather than *alongside* it
var backdrops = modal.getElementsByClassName("modal-backdrop");
var target = backdrops.length !== 0 ?
/* istanbul ignore next: we don't systematically test with 3.3.x */
backdrops[0] :
e.currentTarget;
if (e.target !== target) {
return;
}
$modal.trigger("escape.close.bp");
});
}
$modal.on("escape.close.bp", function (e) {
// the if statement looks redundant but it isn't; without it
// if we *didn't* have an onEscape handler then processCallback
// would automatically dismiss the dialog
if (callbacks.onEscape === true ||
typeof callbacks.onEscape === "function") {
processCallback(e, $modal, callbacks.onEscape);
}
});
$modal.on("click", ".modal-footer button", function (e) {
var callbackKey = $(this).data("bp-handler");
processCallback(e, $modal, callbacks[callbackKey]);
});
$modal.on("click", ".bootprompt-close-button", function (e) {
// onEscape might be falsy but that's fine; the fact is
// if the user has managed to click the close button we
// have to close the dialog, callback or not
processCallback(e, $modal, callbacks.onClose);
});
$modal.on("keyup", function (e) {
if (e.which === 27) {
$modal.trigger("escape.close.bp");
}
});
// The interface defined for $ messes up type inferrence so we have to assert
// the type here.
$(finalOptions.container).append($modal);
$modal.modal({
backdrop: (backdrop === true || backdrop === "static") ? "static" : false,
keyboard: false,
show: false,
});
if (finalOptions.show === true) {
$modal.modal("show");
}
return $modal;
}