lavkach3

Форк
0
156 строк · 5.7 Кб
1
!(function (e) {
2
  "use strict";
3
  e.sessionTimeout = function (t) {
4
    function o() {
5
      f ||
6
        (e.ajax({ type: d.ajaxType, url: d.keepAliveUrl, data: d.ajaxData }),
7
        (f = !0),
8
        setTimeout(function () {
9
          f = !1;
10
        }, d.keepAliveInterval));
11
    }
12

13
    function i() {
14
      clearTimeout(a),
15
        (d.countdownMessage || d.countdownBar) && s("session", !0),
16
        "function" == typeof d.onStart && d.onStart(d),
17
        d.keepAlive && o(),
18
        (a = setTimeout(function () {
19
          "function" != typeof d.onWarn
20
            ? e("#session-timeout-dialog").modal("show")
21
            : d.onWarn(d),
22
            n();
23
        }, d.warnAfter));
24
    }
25

26
    function n() {
27
      clearTimeout(a),
28
        e("#session-timeout-dialog").hasClass("in") ||
29
          (!d.countdownMessage && !d.countdownBar) ||
30
          s("dialog", !0),
31
        (a = setTimeout(function () {
32
          "function" != typeof d.onRedir
33
            ? (window.location = d.redirUrl)
34
            : d.onRedir(d);
35
        }, d.redirAfter - d.warnAfter));
36
    }
37

38
    function s(t, o) {
39
      clearTimeout(l.timer),
40
        "dialog" === t && o
41
          ? (l.timeLeft = Math.floor((d.redirAfter - d.warnAfter) / 1e3))
42
          : "session" === t &&
43
            o &&
44
            (l.timeLeft = Math.floor(d.redirAfter / 1e3)),
45
        d.countdownBar && "dialog" === t
46
          ? (l.percentLeft = Math.floor(
47
              (l.timeLeft / ((d.redirAfter - d.warnAfter) / 1e3)) * 100
48
            ))
49
          : d.countdownBar &&
50
            "session" === t &&
51
            (l.percentLeft = Math.floor(
52
              (l.timeLeft / (d.redirAfter / 1e3)) * 100
53
            ));
54
      var i = e(".countdown-holder"),
55
        n = l.timeLeft >= 0 ? l.timeLeft : 0;
56
      if (d.countdownSmart) {
57
        var a = Math.floor(n / 60),
58
          r = n % 60,
59
          u = a > 0 ? a + "m" : "";
60
        u.length > 0 && (u += " "), (u += r + "s"), i.text(u);
61
      } else i.text(n + "s");
62
      d.countdownBar && e(".countdown-bar").css("width", l.percentLeft + "%"),
63
        (l.timeLeft = l.timeLeft - 1),
64
        (l.timer = setTimeout(function () {
65
          s(t);
66
        }, 1e3));
67
    }
68
    var a,
69
      r = {
70
        title: "Your Session is About to Expire!",
71
        message: "Your session is about to expire.",
72
        logoutButton: "Logout",
73
        keepAliveButton: "Stay Connected",
74
        keepAliveUrl: "/keep-alive",
75
        ajaxType: "POST",
76
        ajaxData: "",
77
        redirUrl: "/timed-out",
78
        logoutUrl: "/log-out",
79
        warnAfter: 9e5,
80
        redirAfter: 12e5,
81
        keepAliveInterval: 5e3,
82
        keepAlive: !0,
83
        ignoreUserActivity: !1,
84
        onStart: !1,
85
        onWarn: !1,
86
        onRedir: !1,
87
        countdownMessage: !1,
88
        countdownBar: !1,
89
        countdownSmart: !1,
90
      },
91
      d = r,
92
      l = {};
93
    if ((t && (d = e.extend(r, t)), d.warnAfter >= d.redirAfter))
94
      return (
95
        console.error(
96
          'Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'
97
        ),
98
        !1
99
      );
100
    if ("function" != typeof d.onWarn) {
101
      var u = d.countdownMessage
102
          ? "<p>" +
103
            d.countdownMessage.replace(
104
              /{timer}/g,
105
              '<span class="countdown-holder"></span>'
106
            ) +
107
            "</p>"
108
          : "",
109
        c = d.countdownBar
110
          ? '<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
          : "";
112
      e("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">' +
114
          d.title +
115
          '</h4>    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>               </div>                   <div class="modal-body">                     <p>' +
116
          d.message +
117
          "</p>                     " +
118
          u +
119
          "                     " +
120
          c +
121
          '                   </div>                   <div class="modal-footer">                     <button id="session-timeout-dialog-logout" type="button" class="btn btn-danger">' +
122
          d.logoutButton +
123
          '</button>                     <button id="session-timeout-dialog-keepalive" type="button" class="btn btn-success" data-dismiss="modal">' +
124
          d.keepAliveButton +
125
          "</button>                   </div>                 </div>               </div>              </div>"
126
      ),
127
        e("#session-timeout-dialog-logout").on("click", function () {
128
          window.location = d.logoutUrl;
129
        }),
130
        e("#session-timeout-dialog").on("hide.bs.modal", function () {
131
          i();
132
        });
133
    }
134
    if (!d.ignoreUserActivity) {
135
      var m = [-1, -1];
136
      e(document).on(
137
        "keyup mouseup mousemove touchend touchmove",
138
        function (t) {
139
          if ("mousemove" === t.type) {
140
            if (t.clientX === m[0] && t.clientY === m[1]) return;
141
            (m[0] = t.clientX), (m[1] = t.clientY);
142
          }
143
          i(),
144
            e("#session-timeout-dialog").length > 0 &&
145
              e("#session-timeout-dialog").data("bs.modal") &&
146
              e("#session-timeout-dialog").data("bs.modal").isShown &&
147
              (e("#session-timeout-dialog").modal("hide"),
148
              e("body").removeClass("modal-open"),
149
              e("div.modal-backdrop").remove());
150
        }
151
      );
152
    }
153
    var f = !1;
154
    i();
155
  };
156
})(jQuery);
157

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.