diff --git a/docs/example-parsers-globalize.html b/docs/example-parsers-globalize.html new file mode 100644 index 00000000..83435b5a --- /dev/null +++ b/docs/example-parsers-globalize.html @@ -0,0 +1,297 @@ + + + + + jQuery plugin: Tablesorter 2.0 - Parsers Globalize + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ NOTE! +

+

+ +

Demo

+
parsed values within the column + + + + + + + + + + + + + + + + + + +
AlphaNumericNumeric (Globalize)AnimalsDate (Globalize)
abc 12312,735.00KoalaJan 22, 2015 AD
abc 165.34OxMar 30, 2015 AD
abc 9GirafeeDec 31, 2014 AD
zyx 24-∞BisonApr 13, 2015 AD
abc 110.44ChimpOct 31, 2015 AD
abc 25.6ElephantMay 3, 2015 AD
abc 91,345,155LionJun 30, 2014 AD
ABC 102,875.33ZebraFeb 14, 2015 AD
zyx 199.9KoalaMar 20, 2015 AD
zyx 121.2LlamaMar 2, 2015 AD
+
+ +

Javascript

+
+

+	
+

HTML

+
+

+	
+ +
+ + + diff --git a/docs/index.html b/docs/index.html index 014e0f4e..3b731bf0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -522,7 +522,7 @@
  • File type parser (v2.13).
  • Ignore leading articles parser (Ignore "A", "An" and "The" in titles) (v2.8).
  • Input/select parsers (used by Grouping rows widget) (v2.8; v2.23.0).
  • -
  • jQuery Globalize (number & date parsers; v2.22.0).
  • +
  • jQuery Globalize (number & date parsers; v2.22.0; v2.23.6).
  • Metric parser (v2.8).
  • Named Numbers parser (v2.18.0; v2.22.0).
  • Network (IPv4, IPv6 and MAC address parser (v2.12; v2.22.0).
  • diff --git a/js/parsers/parser-globalize.js b/js/parsers/parser-globalize.js index aa64fc70..6b9b05c9 100644 --- a/js/parsers/parser-globalize.js +++ b/js/parsers/parser-globalize.js @@ -1,24 +1,27 @@ -/*! Parser: jQuery Globalize - updated 5/17/2015 (v2.22.0) */ +/*! Parser: jQuery Globalize - updated 10/26/2015 (v2.23.6) */ /* Extract localized data using jQuery's Globalize parsers; set - Globalize.locale( 'xx' ) prior to initializing tablesorter! */ + Globalize.locale( 'xx' ) in the globalize settings */ /*jshint jquery:true */ /*global Globalize:false */ ;( function( $ ) { 'use strict'; /*! jQuery Globalize date parser (https://github.com/jquery/globalize#date-module) */ - /* demo: http://jsfiddle.net/Mottie/0j18Lw8r/ */ $.tablesorter.addParser({ id: 'globalize-date', is: function () { return false; }, format: function ( str, table, cell, cellIndex ) { - var c = table.config, - // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } - // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } - options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}, - date = Globalize && Globalize.dateParser ? Globalize.dateParser( options )( str ) : + var globalize, date, + c = table.config, + // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } + // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } + options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}; + if ( Globalize ) { + globalize = typeof options.lang === 'object' ? options.lang : Globalize( options.lang || 'en' ); + } + date = globalize && globalize.dateParser ? globalize.dateParser( options )( str ) : str ? new Date( str ) : str; return date instanceof Date && isFinite( date ) ? date.getTime() : str; }, @@ -26,18 +29,21 @@ }); /*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */ - /* demo: http://jsfiddle.net/Mottie/0j18Lw8r/ */ $.tablesorter.addParser({ id: 'globalize-number', is: function () { return false; }, format: function ( str, table, cell, cellIndex ) { - var c = table.config, - // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } - // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } - options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}, - num = Globalize && Globalize.numberParser ? Globalize.numberParser( options )( str ) : + var globalize, num, + c = table.config, + // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } + // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } + options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}; + if ( Globalize ) { + globalize = typeof options.lang === 'object' ? options.lang : Globalize( options.lang || 'en' ); + } + num = globalize && globalize.numberParser ? globalize.numberParser( options )( str ) : str ? $.tablesorter.formatFloat( ( str || '' ).replace( /[^\w,. \-()]/g, '' ), table ) : str; return str && typeof num === 'number' ? num : str; },