Fix file-size plugin with string containing spaces

pull/230/head
Philippe Vaucher 9 years ago
parent 1d8f976a88
commit e5fcf4496f

@ -19,24 +19,16 @@
*/ */
jQuery.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) { jQuery.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) {
var units = data.replace( /[\d\.\s]/g, '' ).toLowerCase(); var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i );
var multiplier = 1; var multipliers = {
b: 1,
kb: 1000,
mb: 1000000,
gb: 1000000000,
tb: 1000000000000,
pb: 1000000000000000
};
if ( units === 'kb' ) { var multiplier = multipliers[matches[2].toLowerCase()];
multiplier = 1000; return parseFloat( matches[1] ) * multiplier;
}
else if ( units === 'mb' ) {
multiplier = 1000000;
}
else if ( units === 'gb' ) {
multiplier = 1000000000;
}
else if ( units === 'tb' ) {
multiplier = 1000000000000;
}
else if ( units === 'pb' ) {
multiplier = 1000000000000000;
}
return parseFloat( data ) * multiplier;
}; };

@ -13,12 +13,8 @@ jQuery.fn.dataTable.ext.type.detect.unshift( function ( data ) {
return null; return null;
} }
var units = data.replace( /[\d\.]/g, '' ).toLowerCase(); var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i );
if ( units !== '' && units !== 'b' && units !== 'kb' && units !== 'mb' && units !== 'gb' ) { var units = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
return null; var is_file_size = ( matches && jQuery.inArray(matches[2].toLowerCase(), units) !== -1 );
} return is_file_size ? 'file-size' : null;
return isNaN( parseFloat( data ) ) ?
null :
'file-size';
} ); } );
Loading…
Cancel
Save