snipe-it/resources/assets/js/extensions/cookie/bootstrap-table-cookie.min.js

8 lines
7.3 KiB
JavaScript
Raw Normal View History

/*
* bootstrap-table - v1.11.1 - 2017-02-22
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2017 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b={sortOrder:"bs.table.sortOrder",sortName:"bs.table.sortName",pageNumber:"bs.table.pageNumber",pageList:"bs.table.pageList",columns:"bs.table.columns",searchText:"bs.table.searchText",filterControl:"bs.table.filterControl"},c=function(a){var b=a.$header;return a.options.height&&(b=a.$tableHeader),b},d=function(a){var b="select, input";return a.options.height&&(b="table select, table input"),b},e=function(){return!!navigator.cookieEnabled},f=function(a,b){for(var c=-1,d=0;d<b.length;d++)if(a.toLowerCase()===b[d].toLowerCase()){c=d;break}return c},g=function(a,b,c){if(a.options.cookie&&e()&&""!==a.options.cookieIdTable&&-1!==f(b,a.options.cookiesEnabled)){switch(b=a.options.cookieIdTable+"."+b,a.options.cookieStorage){case"cookieStorage":document.cookie=[b,"=",c,"; expires="+a.options.cookieExpire,a.options.cookiePath?"; path="+a.options.cookiePath:"",a.options.cookieDomain?"; domain="+a.options.cookieDomain:"",a.options.cookieSecure?"; secure":""].join("");break;case"localStorage":localStorage.setItem(b,c);break;case"sessionStorage":sessionStorage.setItem(b,c);break;default:return!1}return!0}},h=function(a,b,c){if(!c)return null;if(-1===f(c,a.options.cookiesEnabled))return null;switch(c=b+"."+c,a.options.cookieStorage){case"cookieStorage":return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(c).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null;case"localStorage":return localStorage.getItem(c);case"sessionStorage":return sessionStorage.getItem(c);default:return null}},i=function(a,b,c){switch(c=b+"."+c,a.options.cookieStorage){case"cookieStorage":document.cookie=[encodeURIComponent(c),"=","; expires=Thu, 01 Jan 1970 00:00:00 GMT",a.options.cookiePath?"; path="+a.options.cookiePath:"",a.options.cookieDomain?"; domain="+a.options.cookieDomain:""].join("");break;case"localStorage":localStorage.removeItem(c);break;case"sessionStorage":sessionStorage.removeItem(c)}return!0},j=function(e){setTimeout(function(){var f=JSON.parse(h(e,e.options.cookieIdTable,b.filterControl));if(!e.options.filterControlValuesLoaded&&f){e.options.filterControlValuesLoaded=!0;var g={},i=c(e),j=d(e),k=function(b,c){a(c).each(function(c,d){a(b).val(d.text),g[d.field]=d.text})};i.find(j).each(function(){var b=a(this).closest("[data-field]").data("field"),c=a.grep(f,function(a){return a.field===b});k(this,c)}),e.initColumnSearch(g)}},250)};a.extend(a.fn.bootstrapTable.defaults,{cookie:!1,cookieExpire:"2h",cookiePath:null,cookieDomain:null,cookieSecure:null,cookieIdTable:"",cookiesEnabled:["bs.table.sortOrder","bs.table.sortName","bs.table.pageNumber","bs.table.pageList","bs.table.columns","bs.table.searchText","bs.table.filterControl"],cookieStorage:"cookieStorage",filterControls:[],filterControlValuesLoaded:!1}),a.fn.bootstrapTable.methods.push("getCookies"),a.fn.bootstrapTable.methods.push("deleteCookie"),a.extend(a.fn.bootstrapTable.utils,{setCookie:g,getCookie:h});var k=a.fn.bootstrapTable.Constructor,l=k.prototype.init,m=k.prototype.initTable,n=k.prototype.initServer,o=k.prototype.onSort,p=k.prototype.onPageNumber,q=k.prototype.onPageListChange,r=k.prototype.onPageFirst,s=k.prototype.onPagePre,t=k.prototype.onPageNext,u=k.prototype.onPageLast,v=k.prototype.toggleColumn,w=k.prototype.selectPage,x=k.prototype.onSearch;k.prototype.init=function(){if(this.options.filterControls=[],this.options.filterControlValuesLoaded=!1,this.options.cookiesEnabled="string"==typeof this.options.cookiesEnabled?this.options.cookiesEnabled.replace("[","").replace("]","").replace(/ /g,"").toLowerCase().split(","):this.options.cookiesEnabled,this.options.filterControl){var a=this;this.$el.on("column-search.bs.table",function(c,d,e){for(var f=!0,h=0;h<a.options.filterControls.length;h++)if(a.options.filterControls[h].field===d){a.options.filterControls[h].text=e,f=!1;break}f&&a.options.filterControls.push({field:d,text:e}),g(a,b.filterControl,JSON.stringify(a.options.filterControls))}).on("post-body.bs.table",j(a))}l.apply(this,Array.prototype.slice.apply(arguments))},k.protot