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