Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
          /**
          ?* Author : Larry Li
          ?* Date : 2013-12-5
          ?* Email : larry.li@aicent.com
          ?*/
          var Session = function() {
          ?? ?var defaults = {
          ?? ??? ??? ?title??????? : 'Session Notification',
          ?? ??? ??? ?message????? : 'Your session is about to expire.',
          ?? ??? ??? ?keepAliveUrl : '/admin/session/keep-alive',
          ?? ??? ??? ?redirUrl???? : '/account/timed-out',
          ?? ??? ??? ?logoutUrl??? : '/account/logout',
          ?? ??? ??? ?warnAfter??? : 900000, // 15 minutes
          ?? ??? ??? ?redirAfter?? : 1200000 // 20 minutes
          ?? ?};
          ?? ?
          ?? ?var o = defaults, dialogTimer, redirTimer;
          ?? ?
          ?? ?var controlRedirTimer = function(action) {
          ?? ??? ?switch(action) {
          ?? ??? ??? ?case 'start':
          ?? ??? ??? ??? ?// Dialog has been shown, if no action taken during redir period, redirect
          ?? ??? ??? ??? ?redirTimer = setTimeout(function(){
          ?? ??? ??? ??? ??? ?window.location = o.redirUrl;
          ?? ??? ??? ??? ?}, o.redirAfter - o.warnAfter);
          ?? ??? ??? ??? ?break;
          ?? ?
          ?? ??? ??? ?case 'stop':
          ?? ??? ??? ??? ?clearTimeout(redirTimer);
          ?? ??? ??? ??? ?break;
          ?? ??? ??? ?case 'restart':
          ?? ??? ??? ??? ?clearTimeout(redirTimer);
          ?? ??? ??? ??? ?redirTimer = setTimeout(function(){
          ?? ??? ??? ??? ??? ?window.location = o.redirUrl;
          ?? ??? ??? ??? ?}, o.redirAfter - o.warnAfter);
          ?? ??? ??? ??? ?break;
          ?? ??? ?}
          ?? ?};
          ?? ?
          ?? ?var controlDialogTimer = function(action) {
          ?? ??? ?switch(action) {
          ?? ??? ??? ?case 'start':
          ?? ??? ??? ??? ?dialogTimer = setTimeout(function(){
          ?? ??? ??? ??? ??? ?$('#sessionTimeout-dialog').modal('show');
          ?? ??? ??? ??? ??? ?controlRedirTimer('start');
          ?? ??? ??? ??? ?}, o.warnAfter);
          ?? ??? ??? ??? ?break;
          ?? ??? ??? ?case 'stop':
          ?? ??? ??? ??? ?clearTimeout(dialogTimer);
          ?? ??? ??? ??? ?break;
          ?? ??? ??? ?case 'restart':
          ?? ??? ??? ??? ?clearTimeout(dialogTimer);
          ?? ??? ??? ??? ?dialogTimer = setTimeout(function(){
          ?? ??? ??? ??? ??? ?$('#sessionTimeout-dialog').modal('show');
          ?? ??? ??? ??? ??? ?controlRedirTimer('restart');
          ?? ??? ??? ??? ?}, o.warnAfter);
          ?? ??? ??? ??? ?break;
          ?? ??? ?}
          ?? ?};
          ?? ?
          ?? ?var doKeepAlive = function() {
          ?? ??? ?$.ajax({
          ?? ??? ??? ?type: 'POST',
          ?? ??? ??? ?url: o.keepAliveUrl,
          ?? ??? ??? ?success: function() {
          ?? ??? ??? ??? ?// Stop redirect timer and restart warning timer
          ?? ??? ??? ??? ?controlRedirTimer('restart');
          ?? ??? ??? ??? ?controlDialogTimer('restart');
          ?? ??? ??? ?}
          ?? ??? ?});
          ?? ?};
          ?? ?
          ?? ?return {
          ?? ??? ?sessionTimeout: function(options) {
          ?? ??? ??? ?if ( options ) { o = $.extend( defaults, options ); }
          ?? ??? ??? ?
          ?? ??? ??? ?var warning_dialog = '<div class="modal fade" id="sessionTimeout-dialog">'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ?<div class="modal-dialog modal-small">'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ?<div class="modal-content">'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ?<div class="modal-header">'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ??? ?<button id="_close" type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ??? ?<h4 class="modal-title">'+ o.title +'</h4>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ?</div>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ?<div class="modal-body">'+ o.message +'</div>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ?<div class="modal-footer">'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ??? ?<button id="sessionTimeout-dialog-logout" type="button" class="btn btn-default">Logout</button>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ??? ?<button id="sessionTimeout-dialog-keepalive" type="button" class="btn btn-primary" data-dismiss="modal">Stay Connected</button>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ??? ?</div>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ??? ?</div>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'?? ?</div>'
          ?? ??? ??? ??? ??? ??? ??? ??? ?+'</div>';
          ?? ??? ??? ?
          ?? ??? ??? ?$('body').append(warning_dialog);
          ?? ??? ??? ?
          ?? ??? ??? ?$('#sessionTimeout-dialog-logout').on('click', function () { window.location = o.logoutUrl; });
          ?? ??? ??? ?
          ?? ??? ??? ?$('#_close,#sessionTimeout-dialog-keepalive').click(function() {
          ?? ??? ??? ??? ?doKeepAlive();
          ?? ??? ??? ?});
          ?? ??? ??? ?// Begin warning period
          ?? ??? ??? ?controlDialogTimer('start');
          ?? ??? ?},
          ?? ??? ?
          ?? ??? ?sessionTimeoutKeepAlive: function() {
          ?? ??? ??? ?controlRedirTimer('restart');
          ?? ??? ??? ?controlDialogTimer('restart');
          ?? ??? ?}
          ?? ?};
          }();

          $(function() {
          ?? ?Session.sessionTimeout({
          ?? ??? ?title: 'Session Timeout Notification',
          ?? ??? ?message: 'Your session is about to expire.',
          ?? ??? ?keepAliveUrl: contextPath + '/admin/session/keep-alive',
          ?? ??? ?redirUrl: contextPath + '/account/login',
          ?? ??? ?logoutUrl: contextPath + '/account/logout',
          ?? ??? ?warnAfter: 1500000,
          ?? ??? ?redirAfter: 1780000
          ?? ?});
          ?? ?
          ?? ?$(document).ajaxComplete(function() {
          ?? ??? ?Session.sessionTimeoutKeepAlive();
          ?? ?});
          });
          posted on 2013-12-05 16:11 禮物 閱讀(1391) 評論(1)  編輯  收藏 所屬分類: javascript 、Ajax 、jquery 、Web前端

          評論

          # re: Ajax Session Timeout 超時 處理 2015-08-03 11:14 11
          sads  回復  更多評論
            

          主站蜘蛛池模板: 凌海市| 青岛市| 罗定市| 托里县| 道孚县| 延寿县| 鹤峰县| 双江| 鄄城县| 高尔夫| 富裕县| 博罗县| 岚皋县| 木里| 阿鲁科尔沁旗| 孟津县| 博兴县| 上饶市| 柘荣县| 鸡东县| 新宾| 巴青县| 吉安市| 长春市| 甘孜| 通山县| 庐江县| 收藏| 隆回县| 牙克石市| 噶尔县| 正镶白旗| 平塘县| 峨山| 新郑市| 英德市| 日喀则市| 台北县| 泰和县| 赤壁市| 凤冈县|