mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-28 23:19:42 -08:00
7 lines
6.4 KiB
JavaScript
Executable file
7 lines
6.4 KiB
JavaScript
Executable file
/*
|
|
* bootstrap-table - v1.9.1 - 2015-10-25
|
|
* https://github.com/wenzhixin/bootstrap-table
|
|
* Copyright (c) 2015 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*30*24*60*60;break;default:a=void 0}return void 0===a?"":"; max-age="+a};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 l=a.fn.bootstrapTable.Constructor,m=l.prototype.init,n=l.prototype.initTable,o=l.prototype.onSort,p=l.prototype.onPageNumber,q=l.prototype.onPageListChange,r=l.prototype.onPageFirst,s=l.prototype.onPagePre,t=l.prototype.onPageNext,u=l.prototype.onPageLast,v=l.prototype.toggleColumn,w=l.prototype.selectPage,x=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 e=this;this.$el.on("column-search.bs.table",function(a,c,d){for(var f=!0,h=0;h<e.options.filterControls.length;h++)if(e.options.filterControls[h].field===c){e.options.filterControls[h].text=d,f=!1;break}f&&e.options.filterControls.push({field:c,text:d}),g(e,b.filterControl,JSON.stringify(e.options.filterControls))}).on("post-body.bs.table",function(){setTimeout(function(){if(!e.options.filterControlValuesLoaded){e.options.filterControlValuesLoaded=!0;var f=JSON.parse(h(e,e.options.cookieIdTable,b.filterControl));if(f){var g=null,i=[],j=c(e),k=d(e);j.find(k).each(function(){g=a(this).parent().parent().parent().data("field"),i=a.grep(f,function(a){return a.field===g}),i.length>0&&(a(this).val(i[0].text),e.onColumnSearch({currentTarget:a(this)}))})}}},250)})}m.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())throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies");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(){o.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(){p.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageListChange=function(){q.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageList,this.options.pageSize)},l.prototype.onPageFirst=function(){r.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPagePre=function(){s.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageNext=function(){t.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageLast=function(){u.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.toggleColumn=function(){v.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){w.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,a)},l.prototype.onSearch=function(){x.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.searchText,this.searchText)},l.prototype.deleteCookie=function(a){""!==a&&e()&&j(this.options.cookieIdTable,b[a],this.options.cookiePath,this.options.cookieDomain)}}(jQuery); |