mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-14 01:24:06 -08:00
7 lines
7.1 KiB
JavaScript
7 lines
7.1 KiB
JavaScript
/*
|
|
* 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=function(){return b.options.cookie&&b.getCookies(b)};c=a.grep(b.columns,function(a){return d(a)&&!e(a)}),m.prototype.initServer=p,f()&&0===c.length||p.apply(this,Array.prototype.slice.apply(arguments))},m.prototype.initTable=function(){o.apply(this,Array.prototype.slice.apply(arguments)),this.initCookie()},m.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)})}},m.prototype.onSort=function(){q.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.sortOrder,this.options.sortOrder),g(this,b.sortName,this.options.sortName)},m.prototype.onPageNumber=function(){r.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},m.prototype.onPageListChange=function(){s.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageList,this.options.pageSize)},m.prototype.onPageFirst=function(){t.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},m.prototype.onPagePre=function(){u.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},m.prototype.onPageNext=function(){v.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},m.prototype.onPageLast=function(){w.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},m.prototype.toggleColumn=function(){x.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))},m.prototype.selectPage=function(a){y.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,a)},m.prototype.onSearch=function(){var c=Array.prototype.slice.apply(arguments);z.apply(this,c),a(c[0].currentTarget).parent().hasClass("search")&&g(this,b.searchText,this.searchText)},m.prototype.getCookies=function(c){var d=[];return a.each(b,function(){var a=JSON.parse(h(c,c.options.cookieIdTable,b.filterControl));d.concat(a)}),d},m.prototype.deleteCookie=function(a){""!==a&&e()&&j(this.options.cookieIdTable,b[a],this.options.cookiePath,this.options.cookieDomain)}}(jQuery); |