tablesorter/dist/js/jquery.tablesorter.min.js

2 lines
34 KiB
JavaScript
Raw Normal View History

!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&"object"==typeof module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return function(a){"use strict";a.extend({tablesorter:new function(){function b(a){for(var b in a)return!1;return!0}function c(b,c,d,e){for(var f,g,h=s.parsers.length,i=!1,j="",k=!0;""===j&&k;)d++,c[d]?(i=c[d].cells[e],j=s.getElementText(b,i,e),g=a(i),b.debug&&console.log("Checking if value was empty on row "+d+", column: "+e+': "'+j+'"')):k=!1;for(;--h>=0;)if(f=s.parsers[h],f&&"text"!==f.id&&f.is&&f.is(j,b.table,i,g))return f;return s.getParserById("text")}function d(a,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=a.table,r=0,t={};if(a.$tbodies=a.$table.children("tbody:not(."+a.cssInfoBlock+")"),o="undefined"==typeof d?a.$tbodies:d,p=o.length,0===p)return a.debug?console.warn("Warning: *Empty table!* Not building a parser cache"):"";for(a.debug&&(n=new Date,console[console.group?"group":"log"]("Detecting parsers for each column")),f={extractors:[],parsers:[]};p>r;){if(e=o[r].rows,e.length)for(g=a.columns,h=0;g>h;h++)i=a.$headerIndexed[h],j=s.getColumnData(q,a.headers,h),m=s.getParserById(s.getData(i,j,"extractor")),l=s.getParserById(s.getData(i,j,"sorter")),k="false"===s.getData(i,j,"parser"),a.empties[h]=(s.getData(i,j,"empty")||a.emptyTo||(a.emptyToBottom?"bottom":"top")).toLowerCase(),a.strings[h]=(s.getData(i,j,"string")||a.stringTo||"max").toLowerCase(),k&&(l=s.getParserById("no-parser")),m||(m=!1),l||(l=c(a,e,-1,h)),a.debug&&(t["("+h+") "+i.text()]={parser:l.id,extractor:m?m.id:"none",string:a.strings[h],empty:a.empties[h]}),f.parsers[h]=l,f.extractors[h]=m;r+=f.parsers.length?p:1}a.debug&&(b(t)?console.warn(" No parsers detected!"):console[console.table?"table":"log"](t),console.log("Completed detecting parsers"+s.benchmark(n)),console.groupEnd&&console.groupEnd()),a.parsers=f.parsers,a.extractors=f.extractors}function e(b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=b.config,t=r.parsers;if(r.$tbodies=r.$table.children("tbody:not(."+r.cssInfoBlock+")"),j="undefined"==typeof c?r.$tbodies:c,r.cache={},r.totalRows=0,!t)return r.debug?console.warn("Warning: *Empty table!* Not building a cache"):"";for(r.debug&&(m=new Date),r.showProcessing&&s.isProcessing(b,!0),i=0;i<j.length;i++){for(q=[],d=r.cache[i]={normalized:[]},n=j[i]&&j[i].rows.length||0,g=0;n>g;++g)if(o={child:[],raw:[]},k=a(j[i].rows[g]),l=[],k.hasClass(r.cssChildRow)&&0!==g)for(e=d.normalized.length-1,p=d.normalized[e][r.columns],p.$row=p.$row.add(k),k.prev().hasClass(r.cssChildRow)||k.prev().addClass(s.css.cssHasChild),f=k.children("th, td"),e=p.child.length,p.child[e]=[],h=0;h<r.columns;h++)p.child[e][h]=s.getParsedText(r,f[h],h);else{for(o.$row=k,o.order=g,h=0;h<r.columns;++h)"undefined"!=typeof t[h]?(e=s.getElementText(r,k[0].cells[h],h),o.raw.push(e),f=s.getParsedText(r,k[0].cells[h],h,e),l.push(f),"numeric"===(t[h].type||"").toLowerCase()&&(q[h]=Math.max(Math.abs(f)||0,q[h]||0))):r.debug&&console.warn("No parser found for cell:",k[0].cells[h],"does it have a header?");l[r.columns]=o,d.normalized.push(l)}d.colMax=q,r.totalRows+=d.normalized.length}r.showProcessing&&s.isProcessing(b),r.debug&&console.log("Building cache for "+n+" rows"+s.benchmark(m))}function f(a,c){var d,e,f,g,h,i,j,k=a.config,l=k.widgetOptions,m=k.$tbodies,n=[],o=k.cache;if(b(o))return k.appender?k.appender(a,n):a.isUpdating?k.$table.trigger("updateComplete",a):"";for(k.debug&&(j=new Date),i=0;i<m.length;i++)if(f=m.eq(i),f.length){for(g=s.processTbody(a,f,!0),d=o[i].normalized,e=d.length,h=0;e>h;h++)n.push(d[h][k.columns].$row),k.appender&&(!k.pager||k.pager.removeRows&&l.pager_removeRows||k.pager.ajax)||g.append(d[h][k.columns].$row);s.processTbody(a,g,!1)}k.appender&&k.appender(a,n),k.debug&&console.log("Rebuilt table"+s.benchmark(j)),c||k.appender||s.applyWidget(a),a.isUpdating&&k.$table.trigger("updateComplete",a)}function g(a){return/^d/i.test(a)||1===a}function h(b){var c,d,e,f,h,i,k,l,m=b.config;for(m.headerList=[],m.headerContent=[],m.debug&&(k=new Date),m.columns=s.computeColumnIndex(m.$table.children("thead
var e=b.formatFloat((c||"").replace(/[^\w,. \-()]/g,""),d);return c&&"number"==typeof e?e:c?a.trim(c&&d.config.ignoreCase?c.toLocaleLowerCase():c):c},type:"numeric"}),b.addParser({id:"url",is:function(a){return/^(https?|ftp|file):\/\//.test(a)},format:function(b){return b?a.trim(b.replace(/(https?|ftp|file):\/\//,"")):b},parsed:!0,type:"text"}),b.addParser({id:"isoDate",is:function(a){return/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/.test(a)},format:function(a,b){var c=a?new Date(a.replace(/-/g,"/")):a;return c instanceof Date&&isFinite(c)?c.getTime():a},type:"numeric"}),b.addParser({id:"percent",is:function(a){return/(\d\s*?%|%\s*?\d)/.test(a)&&a.length<15},format:function(a,c){return a?b.formatFloat(a.replace(/%/g,""),c):a},type:"numeric"}),b.addParser({id:"image",is:function(a,b,c,d){return d.find("img").length>0},format:function(b,c,d){return a(d).find("img").attr(c.config.imgAttr||"alt")||b},parsed:!0,type:"text"}),b.addParser({id:"usLongDate",is:function(a){return/^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i.test(a)||/^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i.test(a)},format:function(a,b){var c=a?new Date(a.replace(/(\S)([AP]M)$/i,"$1 $2")):a;return c instanceof Date&&isFinite(c)?c.getTime():a},type:"numeric"}),b.addParser({id:"shortDate",is:function(a){return/(^\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4})|(^\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2})/.test((a||"").replace(/\s+/g," ").replace(/[\-.,]/g,"/"))},format:function(a,c,d,e){if(a){var f,g,h=c.config,i=h.$headerIndexed[e],j=i.length&&i[0].dateFormat||b.getData(i,b.getColumnData(c,h.headers,e),"dateFormat")||h.dateFormat;return g=a.replace(/\s+/g," ").replace(/[\-.,]/g,"/"),"mmddyyyy"===j?g=g.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$1/$2"):"ddmmyyyy"===j?g=g.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$2/$1"):"yyyymmdd"===j&&(g=g.replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/,"$1/$2/$3")),f=new Date(g),f instanceof Date&&isFinite(f)?f.getTime():a}return a},type:"numeric"}),b.addParser({id:"time",is:function(a){return/^(([0-2]?\d:[0-5]\d)|([0-1]?\d:[0-5]\d\s?([AP]M)))$/i.test(a)},format:function(a,b){var c=a?new Date("2000/01/01 "+a.replace(/(\S)([AP]M)$/i,"$1 $2")):a;return c instanceof Date&&isFinite(c)?c.getTime():a},type:"numeric"}),b.addParser({id:"metadata",is:function(){return!1},format:function(b,c,d){var e=c.config,f=e.parserMetadataName?e.parserMetadataName:"sortValue";return a(d).metadata()[f]},type:"numeric"}),b.addWidget({id:"zebra",priority:90,format:function(b,c,d){var e,f,g,h,i,j,k,l,m=new RegExp(c.cssChildRow,"i"),n=c.$tbodies.add(a(c.namespace+"_extra_table").children("tbody:not(."+c.cssInfoBlock+")"));for(c.debug&&(i=new Date),j=0;j<n.length;j++)for(g=0,e=n.eq(j).children("tr:visible").not(c.selectorRemove),l=e.length,k=0;l>k;k++)f=e.eq(k),m.test(f[0].className)||g++,h=g%2===0,f.removeClass(d.zebra[h?1:0]).addClass(d.zebra[h?0:1])},remove:function(a,c,d,e){if(!e){var f,g,h=c.$tbodies,i=(d.zebra||["even","odd"]).join(" ");for(f=0;f<h.length;f++)g=b.processTbody(a,h.eq(f),!0),g.children().removeClass(i),b.processTbody(a,g,!1)}}})}(jQuery),a.tablesorter});