zoneminder/web/skins/classic/js/bootstrap-table-cookie.min.js

9 lines
11 KiB
JavaScript
Raw Normal View History

2020-08-16 04:27:58 +08:00
/**
2020-08-18 01:10:35 +08:00
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @update zhixin wen <wenzhixin2010@gmail.com>
* git a84b084
*/
2020-08-16 04:27:58 +08:00
2020-08-18 01:10:35 +08:00
const Utils=$.fn.bootstrapTable.utils,UtilsCookie={cookieIds:{sortOrder:"bs.table.sortOrder",sortName:"bs.table.sortName",pageNumber:"bs.table.pageNumber",pageList:"bs.table.pageList",columns:"bs.table.columns",searchText:"bs.table.searchText",reorderColumns:"bs.table.reorderColumns",filterControl:"bs.table.filterControl",filterBy:"bs.table.filterBy"},getCurrentHeader(o){let e=o.$header;return o.options.height&&(e=o.$tableHeader),e},getCurrentSearchControls(o){let e="select, input";return o.options.height&&(e="table select, table input"),e},cookieEnabled:()=>!!navigator.cookieEnabled,inArrayCookiesEnabled(o,e){let t=-1;for(let i=0;i<e.length;i++)if(o.toLowerCase()===e[i].toLowerCase()){t=i;break}return t},setCookie(o,e,t){if(o.options.cookie&&UtilsCookie.cookieEnabled()&&""!==o.options.cookieIdTable&&-1!==UtilsCookie.inArrayCookiesEnabled(e,o.options.cookiesEnabled)){switch(e=`${o.options.cookieIdTable}.${e}`,o.options.cookieStorage){case"cookieStorage":document.cookie=[e,"=",encodeURIComponent(t),`; expires=${UtilsCookie.calculateExpiration(o.options.cookieExpire)}`,o.options.cookiePath?`; path=${o.options.cookiePath}`:"",o.options.cookieDomain?`; domain=${o.options.cookieDomain}`:"",o.options.cookieSecure?"; secure":""].join("");break;case"localStorage":localStorage.setItem(e,t);break;case"sessionStorage":sessionStorage.setItem(e,t);break;case"customStorage":if(!o.options.cookieCustomStorageSet||!o.options.cookieCustomStorageGet||!o.options.cookieCustomStorageDelete)throw new Error("The following options must be set while using the customStorage: cookieCustomStorageSet, cookieCustomStorageGet and cookieCustomStorageDelete");Utils.calculateObjectValue(o.options,o.options.cookieCustomStorageSet,[e,t],"");break;default:return!1}return!0}},getCookie(o,e,t){if(!t)return null;if(-1===UtilsCookie.inArrayCookiesEnabled(t,o.options.cookiesEnabled))return null;switch(t=`${e}.${t}`,o.options.cookieStorage){case"cookieStorage":const i=`; ${document.cookie}`.split(`; ${t}=`);return 2===i.length?decodeURIComponent(i.pop().split(";").shift()):null;case"localStorage":return localStorage.getItem(t);case"sessionStorage":return sessionStorage.getItem(t);case"customStorage":if(!o.options.cookieCustomStorageSet||!o.options.cookieCustomStorageGet||!o.options.cookieCustomStorageDelete)throw new Error("The following options must be set while using the customStorage: cookieCustomStorageSet, cookieCustomStorageGet and cookieCustomStorageDelete");return Utils.calculateObjectValue(o.options,o.options.cookieCustomStorageGet,[t],"");default:return null}},deleteCookie(o,e,t){switch(t=`${e}.${t}`,o.options.cookieStorage){case"cookieStorage":document.cookie=[encodeURIComponent(t),"=","; expires=Thu, 01 Jan 1970 00:00:00 GMT",o.options.cookiePath?`; path=${o.options.cookiePath}`:"",o.options.cookieDomain?`; domain=${o.options.cookieDomain}`:""].join("");break;case"localStorage":localStorage.removeItem(t);break;case"sessionStorage":sessionStorage.removeItem(t);break;case"customStorage":if(!o.options.cookieCustomStorageSet||!o.options.cookieCustomStorageGet||!o.options.cookieCustomStorageDelete)throw new Error("The following options must be set while using the customStorage: cookieCustomStorageSet, cookieCustomStorageGet and cookieCustomStorageDelete");Utils.calculateObjectValue(o.options,o.options.cookieCustomStorageDelete,[t],"");break;default:return!1}return!0},calculateExpiration(o){const e=o.replace(/[0-9]*/,"");switch(o=o.replace(/[A-Za-z]{1,2}/,""),e.toLowerCase()){case"s":o=+o;break;case"mi":o*=60;break;case"h":o=60*o*60;break;case"d":o=24*o*60*60;break;case"m":o=30*o*24*60*60;break;case"y":o=365*o*24*60*60;break;default:o=void 0}if(!o)return"";const t=new Date;return t.setTime(t.getTime()+1e3*o),t.toGMTString()},initCookieFilters(o){setTimeout(()=>{const e=JSON.parse(UtilsCookie.getCookie(o,o.options.cookieIdTable,UtilsCookie.cookieIds.filterControl));if(!o.options.filterControlValuesLoaded&&e){const t={},i=UtilsCookie.getCurrentHeader(o),s=UtilsCookie.getCurrentSearchControls(o),r=(e,i)=>{i.forEach(i=>{if(""!==i.text&&("radio"!==e.type||e.valu