From 280402d05e1eb236e7bbf4c2b8b1c6f10fa9412c Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 25 Aug 2016 16:37:02 +0100 Subject: [PATCH] Sorting: Fix mix of tabs and spaces for datetime-moment plug-in - Also use $.trim for whitespace removal. We've got jQuery, so might as well use it for compatibility --- sorting/datetime-moment.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/sorting/datetime-moment.js b/sorting/datetime-moment.js index f3ffd5c..c9cdded 100644 --- a/sorting/datetime-moment.js +++ b/sorting/datetime-moment.js @@ -35,14 +35,13 @@ $.fn.dataTable.moment = function ( format, locale ) { types.detect.unshift( function ( d ) { if ( d ) { // Strip HTML tags and newline characters if possible - if ( d.replace ) { - d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); - } - // Strip out surrounding whitespace if possible - if ( d.trim ) { - d = d.trim(); - } - } + if ( d.replace ) { + d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); + } + + // Strip out surrounding white space + d = $.trim( d ); + } // Null and empty values are acceptable if ( d === '' || d === null ) { @@ -57,15 +56,14 @@ $.fn.dataTable.moment = function ( format, locale ) { // Add sorting method - use an integer for the sorting types.order[ 'moment-'+format+'-pre' ] = function ( d ) { if ( d ) { - // Strip HTML tags and newline characters if possible - if ( d.replace ) { - d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); - } - // Strip out surrounding whitespace if possible - if ( d.trim ) { - d = d.trim(); - } - } + // Strip HTML tags and newline characters if possible + if ( d.replace ) { + d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); + } + + // Strip out surrounding white space + d = $.trim( d ); + } return d === '' || d === null ? -Infinity :