From 7ae25e7d8d909872796e188c6a73e430a97894d8 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Wed, 13 Jun 2012 18:29:50 +0100 Subject: [PATCH] =?UTF-8?q?Update=20to=20current=20type=20detection=20-=20?= =?UTF-8?q?Nuno=20Gomes=20points=20out=20that=20European=20convention=20is?= =?UTF-8?q?=20not=20always=20to=20have=20the=20=E2=82=AC=20first=20-=20you?= =?UTF-8?q?=20can=20have=20it=20at=20the=20end=20etc.=20As=20such,=20rewri?= =?UTF-8?q?te=20this=20plug-in=20to=20be=20a=20lot=20more=20lenient=20as?= =?UTF-8?q?=20to=20how=20it=20detects=20currency.=20Also=20use=20a=20regex?= =?UTF-8?q?=20rather=20than=20looping=20over=20the=20characters=20external?= =?UTF-8?q?ly,=20and=20cope=20with=20non-string=20data.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- type-detection/currency.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/type-detection/currency.js b/type-detection/currency.js index dd6efc8..bed22e4 100644 --- a/type-detection/currency.js +++ b/type-detection/currency.js @@ -8,27 +8,27 @@ * @author Allan Jardine, Nuno Gomes */ +(function(){ + +// Change this list to the valid characters you want +var validChars = "$£€c" + "0123456789" + ".-,'"; + +// Init the regex just once for speed - it is "closure locked" +var + str = jQuery.fn.dataTableExt.oApi._fnEscapeRegex( validChars ), + re = new RegExp('[^'+str+']'); + + jQuery.fn.dataTableExt.aTypes.unshift( - function ( sData ) + function ( data ) { - var sValidChars = "0123456789.-,"; - var sValidSymbols = "$£€"; - var c; - var symbolMatch = false; - - if ( sValidSymbols.indexOf( sData.charAt(0) ) === -1 ) { + if ( typeof data !== 'string' || re.test(data) ) { return null; } - for ( i=1 ; i