tablesorter/dist/js/parsers/parser-roman.min.js

2 lines
1.1 KiB
JavaScript
Raw Normal View History

/*! 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=/\b([MCDLXVI]+\b)/gi,d={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 c,e=a.toUpperCase().split(""),f=0;if(!a||!b.test(a))return a;for(;e.length;)c=d[e.shift()],f+=c*(c<d[e[0]]?-1:1);return f},type:"numeric"}),a.tablesorter.addParser({id:"roman-ignore",is:function(){return!1},format:function(e,f,g,h){var i,j,k=f.config,l=a.isArray(k.roman_ignore)?k.roman_ignore[h]:0,m=(isNaN(l)?a.trim(e.replace(l,"")):a.trim(e.substring(0,e.length-l))).match(c),n=b.test(m),o=0;if(!n)return e;for(j=m[0],m=j.toUpperCase().split("");m.length;)i=d[m.shift()],i&&(o+=i*(i<d[m[0]]?-1:1));return o?e.replace(j,o):e},type:"text"}),a.tablesorter.addParser({id:"roman-extract",is:function(){return!1},format:function(e){var f,g=a.grep(e.split(/\b/),function(a,c){return b.test(a)?a:""}).join("").match(c),h=g?b.test(g):0,i=0;if(!h)return e;for(g=g[0].toUpperCase().split("");g.length;)f=d[g.shift()],f&&(i+=f*(f<d[g[0]]?-1:1));return i?i:e},type:"numeric"})}(jQuery);