You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
7 lines
7.3 KiB
JavaScript
7 lines
7.3 KiB
JavaScript
/*
|
|
* bootstrap-table - v1.12.1 - 2018-03-12
|
|
* https://github.com/wenzhixin/bootstrap-table
|
|
* Copyright (c) 2018 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="+j(a.options.cookieExpire),a.options.cookiePath?"; path="+a.options.cookiePath:"",a.options.cookieDomain?"; domain="+a.options.cookieDomain:"",a.options.cookieSecure?"; secure":""].join("");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":var d="; "+document.cookie,e=d.split("; "+c+"=");return 2===e.length?e.pop().split(";").shift():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(a){var b=a.replace(/[0-9]*/,"");switch(a=a.replace(/[A-Za-z]{1,2}/,""),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}if(!a)return"";var c=new Date;return c.setTime(c.getTime()+1e3*a),c.toGMTString()},k=function(e){setTimeout(function(){var f=JSON.parse(h(e,e.options.cookieIdTable,b.filterControl));if(!e.options.filterControlValuesLoaded&&f){var g={},i=c(e),j=d(e),k=function(b,c){a(c).each(function(c,d){""!==d.text&&(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),e.options.filterControlValuesLoaded=!0,e.initServer()}},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 l=a.fn.bootstrapTable.Constructor,m=l.prototype.init,n=l.prototype.initTable,o=l.prototype.initServer,p=l.prototype.onSort,q=l.prototype.onPageNumber,r=l.prototype.onPageListChange,s=l.prototype.onPagePre,t=l.prototype.onPageNext,u=l.prototype.toggleColumn,v=l.prototype.selectPage,w=l.prototype.onSearch;l.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",k(a))}m.apply(this,Array.prototype.slice.apply(arguments))},l.prototype.initServer=function(){var a=this;if(a.options.cookie&&a.options.filterControl&&!a.options.filterControlValuesLoaded){var c=JSON.parse(h(a,a.options.cookieIdTable,b.filterControl));if(c)return}o.apply(this,Array.prototype.slice.apply(arguments))},l.prototype.initTable=function(){n.apply(this,Array.prototype.slice.apply(arguments)),this.initCookie()},l.prototype.initCookie=function(){if(this.options.cookie){if(""===this.options.cookieIdTable||""===this.options.cookieExpire||!e())return console.error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies"),void(this.options.cookie=!1);var c=h(this,this.options.cookieIdTable,b.sortOrder),d=h(this,this.options.cookieIdTable,b.sortName),f=h(this,this.options.cookieIdTable,b.pageNumber),g=h(this,this.options.cookieIdTable,b.pageList),i=JSON.parse(h(this,this.options.cookieIdTable,b.columns)),j=h(this,this.options.cookieIdTable,b.searchText);this.options.sortOrder=c?c:this.options.sortOrder,this.options.sortName=d?d:this.options.sortName,this.options.pageNumber=f?+f:this.options.pageNumber,this.options.pageSize=g?g===this.options.formatAllRows()?g:+g:this.options.pageSize,this.options.searchText=j?j:"",i&&a.each(this.columns,function(b,c){c.visible=-1!==a.inArray(c.field,i)})}},l.prototype.onSort=function(){p.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.sortOrder,this.options.sortOrder),g(this,b.sortName,this.options.sortName)},l.prototype.onPageNumber=function(){return q.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber),!1},l.prototype.onPageListChange=function(){return r.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageList,this.options.pageSize),g(this,b.pageNumber,this.options.pageNumber),!1},l.prototype.onPagePre=function(){return s.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber),!1},l.prototype.onPageNext=function(){return t.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber),!1},l.prototype.toggleColumn=function(){u.apply(this,Array.prototype.slice.apply(arguments));var c=[];a.each(this.columns,function(a,b){b.visible&&c.push(b.field)}),g(this,b.columns,JSON.stringify(c))},l.prototype.selectPage=function(a){v.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,a)},l.prototype.onSearch=function(){var c=Array.prototype.slice.apply(arguments);w.apply(this,c),a(c[0].currentTarget).parent().hasClass("search")&&g(this,b.searchText,this.searchText),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.getCookies=function(){var c=this,d={};return a.each(b,function(a,b){d[a]=h(c,c.options.cookieIdTable,b),"columns"===a&&(d[a]=JSON.parse(d[a]))}),d},l.prototype.deleteCookie=function(a){""!==a&&e()&&i(this,this.options.cookieIdTable,b[a])}}(jQuery); |