From 9962c09cf337baf038e34342bc2342dd5a3c1b79 Mon Sep 17 00:00:00 2001 From: Vladimir Grezin Date: Wed, 19 Jul 2017 13:57:16 +0300 Subject: [PATCH 1/2] Fix cookie-exparation feature --- .../cookie/bootstrap-table-cookie.js | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/extensions/cookie/bootstrap-table-cookie.js b/src/extensions/cookie/bootstrap-table-cookie.js index c5586b79d9..1076a4f6dd 100644 --- a/src/extensions/cookie/bootstrap-table-cookie.js +++ b/src/extensions/cookie/bootstrap-table-cookie.js @@ -68,19 +68,18 @@ switch(that.options.cookieStorage) { case 'cookieStorage': document.cookie = [ - cookieName, '=', cookieValue, - '; expires=' + that.options.cookieExpire, - that.options.cookiePath ? '; path=' + that.options.cookiePath : '', - that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', - that.options.cookieSecure ? '; secure' : '' - ].join(''); - break; + cookieName, '=', cookieValue, + '; expires=' + calculateExpiration(that.options.cookieExpire), + that.options.cookiePath ? '; path=' + that.options.cookiePath : '', + that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', + that.options.cookieSecure ? '; secure' : '' + ].join(''); case 'localStorage': localStorage.setItem(cookieName, cookieValue); - break; + break; case 'sessionStorage': sessionStorage.setItem(cookieName, cookieValue); - break; + break; default: return false; } @@ -113,22 +112,22 @@ var deleteCookie = function (that, tableName, cookieName) { cookieName = tableName + '.' + cookieName; - + switch(that.options.cookieStorage) { case 'cookieStorage': document.cookie = [ - encodeURIComponent(cookieName), '=', - '; expires=Thu, 01 Jan 1970 00:00:00 GMT', - that.options.cookiePath ? '; path=' + that.options.cookiePath : '', - that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', - ].join(''); + encodeURIComponent(cookieName), '=', + '; expires=Thu, 01 Jan 1970 00:00:00 GMT', + that.options.cookiePath ? '; path=' + that.options.cookiePath : '', + that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', + ].join(''); break; case 'localStorage': localStorage.removeItem(cookieName); - break; + break; case 'sessionStorage': sessionStorage.removeItem(cookieName); - break; + break; } return true; @@ -136,7 +135,7 @@ var calculateExpiration = function(cookieExpire) { var time = cookieExpire.replace(/[0-9]*/, ''); //s,mi,h,d,m,y - cookieExpire = cookieExpire.replace(/[A-Za-z]{1,2}}/, ''); //number + cookieExpire = cookieExpire.replace(/[A-Za-z]{1,2}/, ''); //number switch (time.toLowerCase()) { case 's': @@ -161,8 +160,12 @@ cookieExpire = undefined; break; } - - return cookieExpire === undefined ? '' : '; max-age=' + cookieExpire; + if(!cookieExpire){ + return ''; + } + var d = new Date(); + d.setTime(d.getTime() + cookieExpire*1000); + return d.toGMTString(); }; var initCookieFilters = function (bootstrapTable) { @@ -247,7 +250,7 @@ this.options.cookiesEnabled = typeof this.options.cookiesEnabled === 'string' ? this.options.cookiesEnabled.replace('[', '').replace(']', '') .replace(/ /g, '').toLowerCase().split(',') : - this.options.cookiesEnabled; + this.options.cookiesEnabled; if (this.options.filterControl) { var that = this; @@ -392,7 +395,7 @@ _onSearch.apply(this, target); if ($(target[0].currentTarget).parent().hasClass('search')) { - setCookie(this, cookieIds.searchText, this.searchText); + setCookie(this, cookieIds.searchText, this.searchText); } }; From 34a5c65d9797010ca96382813e9eec86e1b3aec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E7=BF=BC?= Date: Mon, 8 Jan 2018 23:32:53 +0800 Subject: [PATCH 2/2] Update bootstrap-table-cookie.js --- src/extensions/cookie/bootstrap-table-cookie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/cookie/bootstrap-table-cookie.js b/src/extensions/cookie/bootstrap-table-cookie.js index 1076a4f6dd..643ae932e4 100644 --- a/src/extensions/cookie/bootstrap-table-cookie.js +++ b/src/extensions/cookie/bootstrap-table-cookie.js @@ -160,11 +160,11 @@ cookieExpire = undefined; break; } - if(!cookieExpire){ + if (!cookieExpire) { return ''; } var d = new Date(); - d.setTime(d.getTime() + cookieExpire*1000); + d.setTime(d.getTime() + cookieExpire * 1000); return d.toGMTString(); };