bootstrap-table-cookie.min.js 2.9 KB

1234567
  1. /*
  2. * bootstrap-table - v1.7.0 - 2015-04-01
  3. * https://github.com/wenzhixin/bootstrap-table
  4. * Copyright (c) 2015 zhixin wen
  5. * Licensed MIT License
  6. */
  7. !function(a){"use strict";var b="",c={sortOrder:"bs.table.sortOrder",sortName:"bs.table.sortName",pageNumber:"bs.table.pageNumber",pageList:"bs.table.pageList"},d=function(){return navigator.cookieEnabled?!0:!1},e=function(a,c,d,e,f,g){if(a=b+a,!a||/^(?:expires|max\-age|path|domain|secure)$/i.test(a))return!1;var h="",i="";switch(i=d.replace(/[0-9]/,""),d=d.replace(/[A-Za-z]/,""),i.toLowerCase()){case"s":d=+d;break;case"mi":d=60*d;break;case"h":d=60*d*60;break;case"d":d=24*d*60*60;break;case"m":d=30*d*24*60*60;break;case"y":d=365*d*30*24*60*60;break;default:d=void 0}return h=void 0===d?"":"; max-age="+d,document.cookie=encodeURIComponent(a)+"="+encodeURIComponent(c)+h+(f?"; domain="+f:"")+(e?"; path="+e:"")+(g?"; secure":""),!0},f=function(a){return a=b+a,a?decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null:null},g=function(a){return a?new RegExp("(?:^|;\\s*)"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie):!1},h=function(a,c,d){return a=b+a,g(a)?(document.cookie=encodeURIComponent(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(d?"; domain="+d:"")+(c?"; path="+c:""),!0):!1};a.extend(a.fn.bootstrapTable.defaults,{stateSave:!1,stateSaveExpire:"2h",stateSaveIdTable:""}),a.fn.bootstrapTable.methods.push("deleteCookie");var i=a.fn.bootstrapTable.Constructor,j=i.prototype.init,k=i.prototype.onSort,l=i.prototype.onPageNumber,m=i.prototype.onPageListChange;i.prototype.init=function(){this.initStateSave(),j.apply(this,Array.prototype.slice.apply(arguments))},i.prototype.initStateSave=function(){if(this.options.stateSave&&d()&&""!==this.options.stateSaveIdTable){b=this.options.stateSaveIdTable+".";var a=f(c.sortOrder),e=f(c.sortName),g=f(c.pageNumber),h=f(c.pageList);void 0!==a&&null!==a&&(this.options.sortOrder=a,this.options.sortName=e),void 0!==g&&null!==g&&(this.options.pageNumber=+g),void 0!==h&&null!==h&&(this.options.pageSize=h===this.options.formatAllRows()?h:+h)}},i.prototype.onSort=function(){k.apply(this,Array.prototype.slice.apply(arguments)),this.options.stateSave&&d()&&""!==this.options.stateSaveIdTable&&(e(c.sortOrder,this.options.sortOrder,this.options.stateSaveExpire),e(c.sortName,this.options.sortName,this.options.stateSaveExpire))},i.prototype.onPageNumber=function(){l.apply(this,Array.prototype.slice.apply(arguments)),this.options.stateSave&&d()&&""!==this.options.stateSaveIdTable&&e(c.pageNumber,this.options.pageNumber,this.options.stateSaveExpire)},i.prototype.onPageListChange=function(){m.apply(this,Array.prototype.slice.apply(arguments)),this.options.stateSave&&d()&&""!==this.options.stateSaveIdTable&&e(c.pageList,this.options.pageSize,this.options.stateSaveExpire)},i.prototype.deleteCookie=function(a){""!==a&&d()&&h(c[a])}}(jQuery);