snipe-it/bower_components/bootstrap-table/dist/extensions/cookie/bootstrap-table-cookie.min.js

7 lines
7.1 KiB
JavaScript
Raw Normal View History

2017-01-11 03:05:06 -08:00
/*
* bootstrap-table - v1.11.0 - 2016-07-02
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2016 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){return a.options.cookie&&e()&&""!==a.options.cookieIdTable&&-1!==f(b,a.options.cookiesEnabled)?(b=a.options.cookieIdTable+"."+b,!b||/^(?:expires|max\-age|path|domain|secure)$/i.test(b)?!1:(document.cookie=encodeURIComponent(b)+"="+encodeURIComponent(c)+k(a.options.cookieExpire)+(a.options.cookieDomain?"; domain="+a.options.cookieDomain:"")+(a.options.cookiePath?"; path="+a.options.cookiePath:"")+(a.cookieSecure?"; secure":""),!0)):void 0},h=function(a,b,c){return c?-1===f(c,a.options.cookiesEnabled)?null:(c=b+"."+c,decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(c).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null):null},i=function(a){return a?new RegExp("(?:^|;\\s*)"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie):!1},j=function(a,b,c,d){return b=a+"."+b,i(b)?(document.cookie=encodeURIComponent(b)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(d?"; domain="+d:"")+(c?"; path="+c:""),!0):!1},k=function(a){var b=a.replace(/[0-9]*/,"");switch(a=a.replace(/[A-Za-z]/,""),b.toLowerCase()){case"s":a=+a;break;case"mi":a=60*a;break;case"h":a=60*a*60;break;case"d":a=24*a*60*60;break;case"m":a=30*a*24*60*60;break;case"y":a=365*a*24*60*60;break;default:a=void 0}return void 0===a?"":"; max-age="+a},l=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"],filterControls:[],filterControlValuesLoaded:!1}),a.fn.bootstrapTable.methods.push("deleteCookie");var m=a.fn.bootstrapTable.Constructor,n=m.prototype.init,o=m.prototype.initTable,p=m.prototype.initServer,q=m.prototype.onSort,r=m.prototype.onPageNumber,s=m.prototype.onPageListChange,t=m.prototype.onPageFirst,u=m.prototype.onPagePre,v=m.prototype.onPageNext,w=m.prototype.onPageLast,x=m.prototype.toggleColumn,y=m.prototype.selectPage,z=m.prototype.onSearch;m.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 c=this;this.$el.on("column-search.bs.table",function(a,d,e){for(var f=!0,h=0;h<c.options.filterControls.length;h++)if(c.options.filterControls[h].field===d){c.options.filterControls[h].text=e,f=!1;break}f&&c.options.filterControls.push({field:d,text:e}),g(c,b.filterControl,JSON.stringify(c.options.filterControls))}).on("post-body.bs.table",l(c))}n.apply(this,Array.prototype.slice.apply(arguments)),a.extend(a.fn.bootstrapTable.utils,{setCookie:g,getCookie:h})},m.prototype.initServer=function(){var b=this,c=[],d=function(a){return a.filterControl&&"select"===a.filterControl},e=function(a){return a.filterData&&"column"!==a.filterData},f