Debian Codegraph @

js/parsers/parser-globalize.js

raw symbols SCIP
1 /*! Parser: jQuery Globalize - updated 11/2/2015 (v2.24.1) */
2 /* Extract localized data using jQuery's Globalize parsers; set
3 Globalize.locale( 'xx' ) in the globalize settings */
4 /*jshint jquery:true, newcap: false */
5 /*global Globalize:false */
6 ;( function( $ ) {
7 'use strict';
8
9 /*! jQuery Globalize date parser (https://github.com/jquery/globalize#date-module) */
10 $.tablesorter.addParser({
11 id: 'globalize-date',
12 is: function () {
13 return false;
14 },
15 format: function ( str, table, cell, cellIndex ) {
16 var globalize, date,
17 c = table.config,
18 // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
19 // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
20 options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {};
21 if ( Globalize ) {
22 globalize = typeof options.Globalize === 'object' ?
23 // initialized Globalize object
24 options.Globalize :
25 // Globalize initialized from "lang" option
26 Globalize( options.lang || 'en' );
27 if ( !options.Globalize ) {
28 // cache the object
29 options.Globalize = globalize;
30 }
31 }
32 date = globalize && globalize.dateParser ? globalize.dateParser( options )( str ) :
33 str ? new Date( str ) : str;
34 return date instanceof Date && isFinite( date ) ? date.getTime() : str;
35 },
36 type: 'numeric'
37 });
38
39 /*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */
40 $.tablesorter.addParser({
41 id: 'globalize-number',
42 is: function () {
43 return false;
44 },
45 format: function ( str, table, cell, cellIndex ) {
46 var globalize, num,
47 c = table.config,
48 // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
49 // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
50 options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {};
51 if ( Globalize ) {
52 globalize = typeof options.Globalize === 'object' ?
53 // initialized Globalize object
54 options.Globalize :
55 // Globalize initialized from "lang" option
56 Globalize( options.lang || 'en' );
57 if ( !options.Globalize ) {
58 // cache the object
59 options.Globalize = globalize;
60 }
61 }
62 num = globalize && globalize.numberParser ? globalize.numberParser( options )( str ) :
63 str ? $.tablesorter.formatFloat( ( str || '' ).replace( /[^\w,. \-()]/g, '' ), table ) : str;
64 return str && typeof num === 'number' ? num : str;
65 },
66 type: 'numeric'
67 });
68
69 })( jQuery );