mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
2 lines
1.2 KiB
JavaScript
2 lines
1.2 KiB
JavaScript
/*! Parser: roman - updated 6/28/MMXIV (v2.17.3) */
|
|
!function(a){"use strict";var b=/^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/i,c={I:1,V:5,X:10,L:50,C:100,D:500,M:1e3};a.tablesorter.addParser({id:"roman",is:function(){return!1},format:function(a){var d,e=a.toUpperCase().split(""),f=0;if(!a||!b.test(a))return a;for(;e.length;)d=c[e.shift()],f+=d*(d<c[e[0]]?-1:1);return f},type:"numeric"}),a.tablesorter.addParser({id:"roman-ignore",is:function(){return!1},format:function(d,e,f,g){var h,i,j=e.config,k=a.isArray(j.roman_ignore)?j.roman_ignore[g]:0,l=(isNaN(k)?a.trim(d.replace(k,"")):a.trim(d.substring(0,d.length-k))).match(/\b([MCDLXVI]+\b)/gi),m=b.test(l),n=0;if(!m)return d;for(i=l[0],l=i.toUpperCase().split("");l.length;)(h=c[l.shift()])&&(n+=h*(h<c[l[0]]?-1:1));return n?d.replace(i,n):d},type:"text"}),a.tablesorter.addParser({id:"roman-extract",is:function(){return!1},format:function(d){var e,f=a.grep(d.split(/\b/),function(a,c){return b.test(a)?a:""}).join("").match(/\b([MCDLXVI]+\b)/gi),g=f?b.test(f):0,h=0;if(!g)return d;for(f=f[0].toUpperCase().split("");f.length;)(e=c[f.shift()])&&(h+=e*(e<c[f[0]]?-1:1));return h||d},type:"numeric"})}(jQuery); |