lavkach3
156 строк · 5.7 Кб
1!(function (e) {2"use strict";3e.sessionTimeout = function (t) {4function o() {5f ||6(e.ajax({ type: d.ajaxType, url: d.keepAliveUrl, data: d.ajaxData }),7(f = !0),8setTimeout(function () {9f = !1;10}, d.keepAliveInterval));11}12
13function i() {14clearTimeout(a),15(d.countdownMessage || d.countdownBar) && s("session", !0),16"function" == typeof d.onStart && d.onStart(d),17d.keepAlive && o(),18(a = setTimeout(function () {19"function" != typeof d.onWarn20? e("#session-timeout-dialog").modal("show")21: d.onWarn(d),22n();23}, d.warnAfter));24}25
26function n() {27clearTimeout(a),28e("#session-timeout-dialog").hasClass("in") ||29(!d.countdownMessage && !d.countdownBar) ||30s("dialog", !0),31(a = setTimeout(function () {32"function" != typeof d.onRedir33? (window.location = d.redirUrl)34: d.onRedir(d);35}, d.redirAfter - d.warnAfter));36}37
38function s(t, o) {39clearTimeout(l.timer),40"dialog" === t && o41? (l.timeLeft = Math.floor((d.redirAfter - d.warnAfter) / 1e3))42: "session" === t &&43o &&44(l.timeLeft = Math.floor(d.redirAfter / 1e3)),45d.countdownBar && "dialog" === t46? (l.percentLeft = Math.floor(47(l.timeLeft / ((d.redirAfter - d.warnAfter) / 1e3)) * 10048))49: d.countdownBar &&50"session" === t &&51(l.percentLeft = Math.floor(52(l.timeLeft / (d.redirAfter / 1e3)) * 10053));54var i = e(".countdown-holder"),55n = l.timeLeft >= 0 ? l.timeLeft : 0;56if (d.countdownSmart) {57var a = Math.floor(n / 60),58r = n % 60,59u = a > 0 ? a + "m" : "";60u.length > 0 && (u += " "), (u += r + "s"), i.text(u);61} else i.text(n + "s");62d.countdownBar && e(".countdown-bar").css("width", l.percentLeft + "%"),63(l.timeLeft = l.timeLeft - 1),64(l.timer = setTimeout(function () {65s(t);66}, 1e3));67}68var a,69r = {70title: "Your Session is About to Expire!",71message: "Your session is about to expire.",72logoutButton: "Logout",73keepAliveButton: "Stay Connected",74keepAliveUrl: "/keep-alive",75ajaxType: "POST",76ajaxData: "",77redirUrl: "/timed-out",78logoutUrl: "/log-out",79warnAfter: 9e5,80redirAfter: 12e5,81keepAliveInterval: 5e3,82keepAlive: !0,83ignoreUserActivity: !1,84onStart: !1,85onWarn: !1,86onRedir: !1,87countdownMessage: !1,88countdownBar: !1,89countdownSmart: !1,90},91d = r,92l = {};93if ((t && (d = e.extend(r, t)), d.warnAfter >= d.redirAfter))94return (95console.error(96'Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'97),98!199);100if ("function" != typeof d.onWarn) {101var u = d.countdownMessage102? "<p>" +103d.countdownMessage.replace(104/{timer}/g,105'<span class="countdown-holder"></span>'106) +107"</p>"108: "",109c = d.countdownBar110? '<div class="progress" style="height: 15px;"> <div class="progress-bar bg-info countdown-bar active" role="progressbar" style="min-width: 15px; width: 100%;"> <span class="countdown-holder"></span> </div> </div>'111: "";112e("body").append(113'<div class="modal fade" id="session-timeout-dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">' +114d.title +115'</h4> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <p>' +116d.message +117"</p> " +118u +119" " +120c +121' </div> <div class="modal-footer"> <button id="session-timeout-dialog-logout" type="button" class="btn btn-danger">' +122d.logoutButton +123'</button> <button id="session-timeout-dialog-keepalive" type="button" class="btn btn-success" data-dismiss="modal">' +124d.keepAliveButton +125"</button> </div> </div> </div> </div>"126),127e("#session-timeout-dialog-logout").on("click", function () {128window.location = d.logoutUrl;129}),130e("#session-timeout-dialog").on("hide.bs.modal", function () {131i();132});133}134if (!d.ignoreUserActivity) {135var m = [-1, -1];136e(document).on(137"keyup mouseup mousemove touchend touchmove",138function (t) {139if ("mousemove" === t.type) {140if (t.clientX === m[0] && t.clientY === m[1]) return;141(m[0] = t.clientX), (m[1] = t.clientY);142}143i(),144e("#session-timeout-dialog").length > 0 &&145e("#session-timeout-dialog").data("bs.modal") &&146e("#session-timeout-dialog").data("bs.modal").isShown &&147(e("#session-timeout-dialog").modal("hide"),148e("body").removeClass("modal-open"),149e("div.modal-backdrop").remove());150}151);152}153var f = !1;154i();155};156})(jQuery);157