You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
5.7 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. 'use strict';
  2. ! function(e) {
  3. "use strict";
  4. e.sessionTimeout = function(t) {
  5. function o() {
  6. f || (e.ajax({
  7. type: d.ajaxType,
  8. url: d.keepAliveUrl,
  9. data: d.ajaxData
  10. }), f = !0, setTimeout(function() {
  11. f = !1
  12. }, d.keepAliveInterval))
  13. }
  14. function i() {
  15. clearTimeout(a), (d.countdownMessage || d.countdownBar) && s("session", !0), "function" == typeof d.onStart && d.onStart(d), d.keepAlive && o(), a = setTimeout(function() {
  16. "function" != typeof d.onWarn ? e("#session-timeout-dialog").modal("show") : d.onWarn(d), n()
  17. }, d.warnAfter)
  18. }
  19. function n() {
  20. clearTimeout(a), e("#session-timeout-dialog").hasClass("in") || !d.countdownMessage && !d.countdownBar || s("dialog", !0), a = setTimeout(function() {
  21. "function" != typeof d.onRedir ? window.location = d.redirUrl : d.onRedir(d)
  22. }, d.redirAfter - d.warnAfter)
  23. }
  24. function s(t, o) {
  25. clearTimeout(l.timer), "dialog" === t && o ? l.timeLeft = Math.floor((d.redirAfter - d.warnAfter) / 1e3) : "session" === t && o && (l.timeLeft = Math.floor(d.redirAfter / 1e3)), d.countdownBar && "dialog" === t ? l.percentLeft = Math.floor(l.timeLeft / ((d.redirAfter - d.warnAfter) / 1e3) * 100) : d.countdownBar && "session" === t && (l.percentLeft = Math.floor(l.timeLeft / (d.redirAfter / 1e3) * 100));
  26. var i = e(".countdown-holder"),
  27. n = l.timeLeft >= 0 ? l.timeLeft : 0;
  28. if (d.countdownSmart) {
  29. var a = Math.floor(n / 60),
  30. r = n % 60,
  31. u = a > 0 ? a + "m" : "";
  32. u.length > 0 && (u += " "), u += r + "s", i.text(u)
  33. } else i.text(n + "s");
  34. d.countdownBar && e(".countdown-bar").css("width", l.percentLeft + "%"), l.timeLeft = l.timeLeft - 1, l.timer = setTimeout(function() {
  35. s(t)
  36. }, 1e3)
  37. }
  38. var a, r = {
  39. title: "Your Session is About to Expire!",
  40. message: "Your session is about to expire.",
  41. logoutButton: "Logout",
  42. keepAliveButton: "Stay Connected",
  43. keepAliveUrl: "pages/ui/session-timeout.html",
  44. ajaxType: "POST",
  45. ajaxData: "",
  46. redirUrl: "/timed-out",
  47. logoutUrl: "/log-out",
  48. warnAfter: 9e5,
  49. redirAfter: 12e5,
  50. keepAliveInterval: 5e3,
  51. keepAlive: !0,
  52. ignoreUserActivity: !1,
  53. onStart: !1,
  54. onWarn: !1,
  55. onRedir: !1,
  56. countdownMessage: !1,
  57. countdownBar: !1,
  58. countdownSmart: !1
  59. },
  60. d = r,
  61. l = {};
  62. if (t && (d = e.extend(r, t)), d.warnAfter >= d.redirAfter) return console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'), !1;
  63. if ("function" != typeof d.onWarn) {
  64. var u = d.countdownMessage ? "<p>" + d.countdownMessage.replace(/{timer}/g, '<span class="countdown-holder"></span>') + "</p>" : "",
  65. c = d.countdownBar ? '<div class="progress progress-lg"> <div class="progress-bar progress-bar-success countdown-bar active" role="progressbar" style="min-width: 15px; width: 100%;"> <span class="countdown-holder"></span> </div> </div>' : "";
  66. e("body").append('<div class="modal fade" id="session-timeout-dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">' + d.title + '</h4> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> </div> <div class="modal-body"> <p>' + d.message + "</p> " + u + " " + c + ' </div> <div class="modal-footer"> <button id="session-timeout-dialog-logout" type="button" class="btn btn-default">' + d.logoutButton + '</button> <button id="session-timeout-dialog-keepalive" type="button" class="btn btn-primary" data-dismiss="modal">' + d.keepAliveButton + "</button> </div> </div> </div> </div>"), e("#session-timeout-dialog-logout").on("click", function() {
  67. window.location = d.logoutUrl
  68. }), e("#session-timeout-dialog").on("hide.bs.modal", function() {
  69. i()
  70. })
  71. }
  72. if (!d.ignoreUserActivity) {
  73. var m = [-1, -1];
  74. e(document).on("keyup mouseup mousemove touchend touchmove", function(t) {
  75. if ("mousemove" === t.type) {
  76. if (t.clientX === m[0] && t.clientY === m[1]) return;
  77. m[0] = t.clientX, m[1] = t.clientY
  78. }
  79. i(), e("#session-timeout-dialog").length > 0 && e("#session-timeout-dialog").data("bs.modal") && e("#session-timeout-dialog").data("bs.modal").isShown && (e("#session-timeout-dialog").modal("hide"), e("body").removeClass("modal-open"), e("div.modal-backdrop").remove())
  80. })
  81. }
  82. var f = !1;
  83. i()
  84. }
  85. }(jQuery);
  86. $(document).ready(function() {
  87. $.sessionTimeout({
  88. warnAfter: 3000,
  89. redirAfter: 300000,
  90. message: 'Your session is expiring soon.',
  91. logoutUrl: 'session-timeout.html'
  92. });
  93. });