Terry.Li-彬

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

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評(píng)論 :: 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 禮物 閱讀(1390) 評(píng)論(1)  編輯  收藏 所屬分類: javascriptAjaxjqueryWeb前端

          評(píng)論

          # re: Ajax Session Timeout 超時(shí) 處理 2015-08-03 11:14 11
          sads  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 汕头市| 治县。| 都昌县| 利津县| 南岸区| 桑植县| 崇礼县| 申扎县| 商水县| 白沙| 通河县| 丽江市| 扎囊县| 清河县| 赤城县| 青岛市| 土默特左旗| 通江县| 隆回县| 云龙县| 罗城| 田阳县| 潞西市| 德州市| 柘城县| 烟台市| 拉孜县| 东阳市| 手游| 鸡泽县| 江陵县| 嘉兴市| 林西县| 察隅县| 普兰店市| 临城县| 开原市| 洱源县| 青海省| 万载县| 黎平县|