}
function buildParserCache( table, $headers ) {
- var rows = table.tBodies[0].rows,
- sortType,
+ var sortType, cells, len, i, parser,
+ rows = table.tBodies[0].rows,
parsers = [];
if ( rows[0] ) {
- var cells = rows[0].cells,
- len = cells.length,
- i, parser;
+ cells = rows[0].cells;
+ len = cells.length;
for ( i = 0; i < len; i++ ) {
parser = false;
/* Other utility functions */
function buildCache( table ) {
- var totalRows = ( table.tBodies[0] && table.tBodies[0].rows.length ) || 0,
+ var i, j, $row, cols,
+ totalRows = ( table.tBodies[0] && table.tBodies[0].rows.length ) || 0,
totalCells = ( table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length ) || 0,
parsers = table.config.parsers,
cache = {
normalized: []
};
- for ( var i = 0; i < totalRows; ++i ) {
+ for ( i = 0; i < totalRows; ++i ) {
// Add the table data to main data array
- var $row = $( table.tBodies[0].rows[i] ),
- cols = [];
+ $row = $( table.tBodies[0].rows[i] );
+ cols = [];
// if this is a child row, add it to the last row's children and
// continue to the next row
cache.row.push( $row );
- for ( var j = 0; j < totalCells; ++j ) {
+ for ( j = 0; j < totalCells; ++j ) {
cols.push( parsers[j].format( getElementSortKey( $row[0].cells[j] ), table, $row[0].cells[j] ) );
}
colspanOffset = 0,
columns,
i,
+ rowspan,
+ colspan,
+ headerCount,
+ longestTR,
+ exploded,
$tableHeaders = $( [] ),
$tableRows = $( 'thead:eq(0) > tr', table );
if ( $tableRows.length <= 1 ) {
$tableHeaders = $tableRows.children( 'th' );
} else {
- var rowspan,
- colspan,
- headerCount,
- longestTR,
- matrixRowIndex,
- matrixColumnIndex,
- exploded = [];
+ exploded = [];
// Loop through all the dom cells of the thead
$tableRows.each( function ( rowIndex, row ) {
$.each( row.cells, function ( columnIndex, cell ) {
+ var matrixRowIndex,
+ matrixColumnIndex;
+
rowspan = Number( cell.rowSpan );
colspan = Number( cell.colSpan );
}
function isValueInArray( v, a ) {
- var l = a.length;
- for ( var i = 0; i < l; i++ ) {
+ var i,
+ len = a.length;
+ for ( i = 0; i < len; i++ ) {
if ( a[i][0] === v ) {
return true;
}
// Legacy fix of .sortbottoms
// Wrap them inside inside a tfoot (because that's what they actually want to be) &
// and put the <tfoot> at the end of the <table>
- var $sortbottoms = $table.find( '> tbody > tr.sortbottom' );
+ var $tfoot,
+ $sortbottoms = $table.find( '> tbody > tr.sortbottom' );
if ( $sortbottoms.length ) {
- var $tfoot = $table.children( 'tfoot' );
+ $tfoot = $table.children( 'tfoot' );
if ( $tfoot.length ) {
$tfoot.eq( 0 ).prepend( $sortbottoms );
} else {
// Apply event handling to headers
// this is too big, perhaps break it out?
$headers.not( '.' + table.config.unsortableClass ).on( 'keypress click', function ( e ) {
+ var cell, columns, newSortList, i,
+ totalRows,
+ j, s, o;
+
if ( e.type === 'click' && e.target.nodeName.toLowerCase() === 'a' ) {
// The user clicked on a link inside a table header.
// Do nothing and let the default link click action continue.
// cells get event .change() and bubbles up to the <table> here
cache = buildCache( table );
- var totalRows = ( $table[0].tBodies[0] && $table[0].tBodies[0].rows.length ) || 0;
+ totalRows = ( $table[0].tBodies[0] && $table[0].tBodies[0].rows.length ) || 0;
if ( !table.sortDisabled && totalRows > 0 ) {
// Get current column sort order
this.order = this.count % 2;
this.count++;
- var cell, columns, newSortList, i;
-
cell = this;
// Get current column index
columns = table.headerToColumns[ this.headerIndex ];
if ( isValueInArray( i, config.sortList ) ) {
// The user has clicked on an already sorted column.
// Reverse the sorting direction for all tables.
- for ( var j = 0; j < config.sortList.length; j++ ) {
- var s = config.sortList[j],
- o = config.headerList[s[0]];
+ for ( j = 0; j < config.sortList.length; j++ ) {
+ s = config.sortList[j];
+ o = config.headerList[s[0]];
if ( isValueInArray( s[0], newSortList ) ) {
o.count = s[1];
o.count++;
},
addParser: function ( parser ) {
- var l = parsers.length,
+ var i,
+ len = parsers.length,
a = true;
- for ( var i = 0; i < l; i++ ) {
+ for ( i = 0; i < len; i++ ) {
if ( parsers[i].id.toLowerCase() === parser.id.toLowerCase() ) {
a = false;
}
return ts.rgx.IPAddress[0].test( s );
},
format: function ( s ) {
- var a = s.split( '.' ),
+ var i, item,
+ a = s.split( '.' ),
r = '',
- l = a.length;
- for ( var i = 0; i < l; i++ ) {
- var item = a[i];
+ len = a.length;
+ for ( i = 0; i < len; i++ ) {
+ item = a[i];
if ( item.length === 1 ) {
r += '00' + item;
} else if ( item.length === 2 ) {
return ( ts.dateRegex[0].test( s ) || ts.dateRegex[1].test( s ) || ts.dateRegex[2].test( s ) );
},
format: function ( s ) {
- var match;
+ var match, y;
s = $.trim( s.toLowerCase() );
if ( ( match = s.match( ts.dateRegex[0] ) ) !== null ) {
s[2] = '0' + s[2];
}
- var y;
if ( ( y = parseInt( s[0], 10 ) ) < 100 ) {
// Guestimate years without centuries
if ( y < 30 ) {