Global: Replace array push functions in main loops

This commit is contained in:
Rob Garrison 2016-02-21 21:47:59 -06:00
parent 61f38b81b1
commit 2f9fa35e55
4 changed files with 52 additions and 51 deletions

View File

@ -167,7 +167,7 @@
c = table.config, c = table.config,
namespace = c.namespace + 'pager', namespace = c.namespace + 'pager',
sz = parsePageSize( p, p.size, 'get' ); // don't allow dividing by zero sz = parsePageSize( p, p.size, 'get' ); // don't allow dividing by zero
if (p.countChildRows) { t.push(c.cssChildRow); } if (p.countChildRows) { t[ t.length ] = c.cssChildRow; }
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
c.totalRows = p.totalRows; c.totalRows = p.totalRows;
parsePageNumber( table, p ); parsePageNumber( table, p );
@ -254,10 +254,10 @@
option_pages_start_page = (large_collection) ? skip_set_size : 1; option_pages_start_page = (large_collection) ? skip_set_size : 1;
for ( i = option_pages_start_page; i <= pg; ) { for ( i = option_pages_start_page; i <= pg; ) {
option_pages.push(i); option_pages[ option_pages.length ] = i;
i = i + ( large_collection ? skip_set_size : 1 ); i = i + ( large_collection ? skip_set_size : 1 );
} }
option_pages.push(pg); option_pages[ option_pages.length ] = pg;
if (large_collection) { if (large_collection) {
focus_option_pages = []; focus_option_pages = [];
// don't allow central focus size to be > 5 on either side of current page // don't allow central focus size to be > 5 on either side of current page
@ -269,7 +269,7 @@
if (end_page > pg) { end_page = pg; } if (end_page > pg) { end_page = pg; }
// construct an array to get a focus set around the current page // construct an array to get a focus set around the current page
for (i = start_page; i <= end_page ; i++) { for (i = start_page; i <= end_page ; i++) {
focus_option_pages.push(i); focus_option_pages[ focus_option_pages.length ] = i;
} }
// keep unique values // keep unique values
@ -349,7 +349,7 @@
} else { } else {
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none'; rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
if (last !== j && j >= s && j < e) { if (last !== j && j >= s && j < e) {
p.cacheIndex.push(i); p.cacheIndex[ p.cacheIndex.length ] = i;
last = j; last = j;
} }
// don't count child rows // don't count child rows
@ -565,7 +565,7 @@
sortCol = sortCol[1]; sortCol = sortCol[1];
len = sortList.length; len = sortList.length;
for (indx = 0; indx < len; indx++) { for (indx = 0; indx < len; indx++) {
arry.push(sortCol + '[' + sortList[indx][0] + ']=' + sortList[indx][1]); arry[ arry.length ] = sortCol + '[' + sortList[indx][0] + ']=' + sortList[indx][1];
} }
// if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col" // if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col"
url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol ); url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol );
@ -576,7 +576,7 @@
len = filterList.length; len = filterList.length;
for (indx = 0; indx < len; indx++) { for (indx = 0; indx < len; indx++) {
if (filterList[indx]) { if (filterList[indx]) {
arry.push(filterCol + '[' + indx + ']=' + encodeURIComponent(filterList[indx])); arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[indx] );
} }
} }
// if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol" // if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol"
@ -634,7 +634,7 @@
count++; count++;
if (count > s && added <= e) { if (count > s && added <= e) {
added++; added++;
p.cacheIndex.push(index); p.cacheIndex[ p.cacheIndex.length ] = index;
$tb.append(rows[index]); $tb.append(rows[index]);
} }
} }
@ -695,7 +695,7 @@
n = table.config.cache[0].normalized; n = table.config.cache[0].normalized;
p.totalRows = n.length; p.totalRows = n.length;
for (i = 0; i < p.totalRows; i++) { for (i = 0; i < p.totalRows; i++) {
rows.push(n[i][c.columns].$row); rows[ rows.length ] = n[i][c.columns].$row;
} }
c.rowsCopy = rows; c.rowsCopy = rows;
moveToPage(table, p, true); moveToPage(table, p, true);

View File

@ -733,7 +733,7 @@
} }
} }
if ( add ) { if ( add ) {
ts.parsers.push( parser ); ts.parsers[ ts.parsers.length ] = parser;
} }
}, },
@ -953,7 +953,7 @@
} }
// ensure rowData is always in the same location (after the last column) // ensure rowData is always in the same location (after the last column)
cols[ c.columns ] = rowData; cols[ c.columns ] = rowData;
cache.normalized.push( cols ); cache.normalized[ cache.normalized.length ] = cols;
} }
cache.colMax = colMax; cache.colMax = colMax;
// total up rows, not including child rows // total up rows, not including child rows
@ -1022,9 +1022,9 @@
}); });
} }
if ( result !== false ) { if ( result !== false ) {
data.parsed.push( parsed ); data.parsed[ data.parsed.length ] = parsed;
data.raw.push( raw ); data.raw[ data.raw.length ] = raw;
data.$cell.push( $cell ); data.$cell[ data.$cell.length ] = $cell;
} }
} }
} }
@ -1213,7 +1213,7 @@
} }
primary = indx === 0 ? dir : primary; primary = indx === 0 ? dir : primary;
group = [ col, parseInt( dir, 10 ) || 0 ]; group = [ col, parseInt( dir, 10 ) || 0 ];
c.sortList.push( group ); c.sortList[ c.sortList.length ] = group;
dir = $.inArray( group[ 1 ], order ); // fixes issue #167 dir = $.inArray( group[ 1 ], order ); // fixes issue #167
c.sortVars[ col ].count = dir >= 0 ? dir : group[ 1 ] % ( c.sortReset ? 3 : 2 ); c.sortVars[ col ].count = dir >= 0 ? dir : group[ 1 ] % ( c.sortReset ? 3 : 2 );
} }
@ -1312,7 +1312,7 @@
}, },
addRows : function( c, $row, resort, callback ) { addRows : function( c, $row, resort, callback ) {
var txt, val, tbodyIndex, rowIndex, rows, cellIndex, len, var txt, val, tbodyIndex, rowIndex, rows, cellIndex, len, order,
cacheIndex, rowData, cells, cell, span, cacheIndex, rowData, cells, cell, span,
// allow passing a row string if only one non-info tbody exists in the table // allow passing a row string if only one non-info tbody exists in the table
valid = typeof $row === 'string' && c.$tbodies.length === 1 && /<tr/.test( $row || '' ), valid = typeof $row === 'string' && c.$tbodies.length === 1 && /<tr/.test( $row || '' ),
@ -1347,12 +1347,13 @@
for ( rowIndex = 0; rowIndex < rows; rowIndex++ ) { for ( rowIndex = 0; rowIndex < rows; rowIndex++ ) {
cacheIndex = 0; cacheIndex = 0;
len = $row[ rowIndex ].cells.length; len = $row[ rowIndex ].cells.length;
order = c.cache[ tbodyIndex ].normalized.length;
cells = []; cells = [];
rowData = { rowData = {
child : [], child : [],
raw : [], raw : [],
$row : $row.eq( rowIndex ), $row : $row.eq( rowIndex ),
order : c.cache[ tbodyIndex ].normalized.length order : order
}; };
// add each cell // add each cell
for ( cellIndex = 0; cellIndex < len; cellIndex++ ) { for ( cellIndex = 0; cellIndex < len; cellIndex++ ) {
@ -1375,7 +1376,7 @@
// add the row data to the end // add the row data to the end
cells[ c.columns ] = rowData; cells[ c.columns ] = rowData;
// update cache // update cache
c.cache[ tbodyIndex ].normalized.push( cells ); c.cache[ tbodyIndex ].normalized[ order ] = cells;
} }
// resort using current settings // resort using current settings
ts.checkResort( c, resort, callback ); ts.checkResort( c, resort, callback );
@ -1417,7 +1418,7 @@
parsed = cache[ tbodyIndex ].normalized; parsed = cache[ tbodyIndex ].normalized;
totalRows = parsed.length; totalRows = parsed.length;
for ( rowIndex = 0; rowIndex < totalRows; rowIndex++ ) { for ( rowIndex = 0; rowIndex < totalRows; rowIndex++ ) {
rows.push( parsed[ rowIndex ][ c.columns ].$row ); rows[rows.length] = parsed[ rowIndex ][ c.columns ].$row;
// removeRows used by the pager plugin; don't render if using ajax - fixes #411 // removeRows used by the pager plugin; don't render if using ajax - fixes #411
if ( !c.appender || ( c.pager && ( !c.pager.removeRows || !wo.pager_removeRows ) && !c.pager.ajax ) ) { if ( !c.appender || ( c.pager && ( !c.pager.removeRows || !wo.pager_removeRows ) && !c.pager.ajax ) ) {
$curTbody.append( parsed[ rowIndex ][ c.columns ].$row ); $curTbody.append( parsed[ rowIndex ][ c.columns ].$row );
@ -1499,18 +1500,18 @@
arry = c.sortForce; arry = c.sortForce;
for ( indx = 0; indx < arry.length; indx++ ) { for ( indx = 0; indx < arry.length; indx++ ) {
if ( arry[ indx ][ 0 ] !== col ) { if ( arry[ indx ][ 0 ] !== col ) {
c.sortList.push( arry[ indx ] ); c.sortList[ c.sortList.length ] = arry[ indx ];
} }
} }
} }
// add column to sort list // add column to sort list
dir = order[ c.sortVars[ col ].count ]; dir = order[ c.sortVars[ col ].count ];
if ( dir < 2 ) { if ( dir < 2 ) {
c.sortList.push( [ col, dir ] ); c.sortList[ c.sortList.length ] = [ col, dir ];
// add other columns if header spans across multiple // add other columns if header spans across multiple
if ( cell.colSpan > 1 ) { if ( cell.colSpan > 1 ) {
for ( indx = 1; indx < cell.colSpan; indx++ ) { for ( indx = 1; indx < cell.colSpan; indx++ ) {
c.sortList.push( [ col + indx, dir ] ); c.sortList[ c.sortList.length ] = [ col + indx, dir ];
// update count on columns in colSpan // update count on columns in colSpan
c.sortVars[ col + indx ].count = $.inArray( dir, order ); c.sortVars[ col + indx ].count = $.inArray( dir, order );
} }
@ -1539,11 +1540,11 @@
// add column to sort list array // add column to sort list array
dir = order[ c.sortVars[ col ].count ]; dir = order[ c.sortVars[ col ].count ];
if ( dir < 2 ) { if ( dir < 2 ) {
c.sortList.push( [ col, dir ] ); c.sortList[ c.sortList.length ] = [ col, dir ];
// add other columns if header spans across multiple // add other columns if header spans across multiple
if ( cell.colSpan > 1 ) { if ( cell.colSpan > 1 ) {
for ( indx = 1; indx < cell.colSpan; indx++ ) { for ( indx = 1; indx < cell.colSpan; indx++ ) {
c.sortList.push( [ col + indx, dir ] ); c.sortList[ c.sortList.length ] = [ col + indx, dir ];
// update count on columns in colSpan // update count on columns in colSpan
c.sortVars[ col + indx ].count = $.inArray( dir, order ); c.sortVars[ col + indx ].count = $.inArray( dir, order );
} }
@ -1580,7 +1581,7 @@
break; break;
} }
} }
c.sortList.push( [ arry[ indx ][ 0 ], dir ] ); c.sortList[ c.sortList.length ] = [ arry[ indx ][ 0 ], dir ];
} }
} }
} }
@ -1847,7 +1848,7 @@
*/ */
addWidget : function( widget ) { addWidget : function( widget ) {
ts.widgets.push( widget ); ts.widgets[ ts.widgets.length ] = widget;
}, },
hasWidget : function( $table, name ) { hasWidget : function( $table, name ) {
@ -1895,7 +1896,7 @@
len = widgets.length; len = widgets.length;
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
if ( widgets[ indx ].match( widgetClass ) ) { if ( widgets[ indx ].match( widgetClass ) ) {
c.widgets.push( widgets[ indx ].replace( widgetClass, '$1' ) ); c.widgets[ c.widgets.length ] = widgets[ indx ].replace( widgetClass, '$1' );
} }
} }
} }
@ -1912,7 +1913,7 @@
applied = false; applied = false;
// add widget name to option list so it gets reapplied after sorting, filtering, etc // add widget name to option list so it gets reapplied after sorting, filtering, etc
if ( $.inArray( name, c.widgets ) < 0 ) { if ( $.inArray( name, c.widgets ) < 0 ) {
c.widgets.push( name ); c.widgets[ c.widgets.length ] = name;
} }
if ( c.debug ) { time = new Date(); } if ( c.debug ) { time = new Date(); }
@ -2022,7 +2023,7 @@
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
widget = ts.widgets[ indx ]; widget = ts.widgets[ indx ];
if ( widget && widget.id ) { if ( widget && widget.id ) {
name.push( widget.id ); name[ name.length ] = widget.id;
} }
} }
} else { } else {
@ -2063,7 +2064,7 @@
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
widget = widgets[ indx ]; widget = widgets[ indx ];
if ( widget && widget.id && ( doAll || $.inArray( widget.id, curWidgets ) < 0 ) ) { if ( widget && widget.id && ( doAll || $.inArray( widget.id, curWidgets ) < 0 ) ) {
list.push( widget.id ); list[ list.length ] = widget.id;
} }
} }
ts.removeWidget( table, list.join( ',' ), true ); ts.removeWidget( table, list.join( ',' ), true );
@ -2450,7 +2451,7 @@
console = {}; console = {};
console.log = console.warn = console.error = console.table = function() { console.log = console.warn = console.error = console.table = function() {
var arg = arguments.length > 1 ? arguments : arguments[0]; var arg = arguments.length > 1 ? arguments : arguments[0];
ts.logs.push({ date: Date.now(), log: arg }); ts.logs[ ts.logs.length ] = { date: Date.now(), log: arg };
}; };
} }

View File

@ -971,7 +971,7 @@
end = c.columns - 1; end = c.columns - 1;
} }
for ( ; start <= end; start++ ) { for ( ; start <= end; start++ ) {
columns.push( start ); columns[ columns.length ] = start;
} }
// remove processed range from val // remove processed range from val
val = val.replace( ranges[ indx ], '' ); val = val.replace( ranges[ indx ], '' );
@ -985,7 +985,7 @@
if ( singles[ i ] !== '' ) { if ( singles[ i ] !== '' ) {
indx = parseInt( singles[ i ], 10 ); indx = parseInt( singles[ i ], 10 );
if ( indx < c.columns ) { if ( indx < c.columns ) {
columns.push( indx ); columns[ columns.length ] = indx;
} }
} }
} }
@ -993,7 +993,7 @@
// return all columns // return all columns
if ( !columns.length ) { if ( !columns.length ) {
for ( indx = 0; indx < c.columns; indx++ ) { for ( indx = 0; indx < c.columns; indx++ ) {
columns.push( indx ); columns[ columns.length ] = indx;
} }
} }
return columns; return columns;
@ -1491,13 +1491,13 @@
// table cell to the parser format function // table cell to the parser format function
if ( txt.text ) { if ( txt.text ) {
txt.parsed = parsedTxt; txt.parsed = parsedTxt;
parsed.push( txt ); parsed[ parsed.length ] = txt;
} else { } else {
parsed.push({ parsed[ parsed.length ] = {
text : txt, text : txt,
// check parser length - fixes #934 // check parser length - fixes #934
parsed : parsedTxt parsed : parsedTxt
}); };
} }
} }
// sort parsed select options // sort parsed select options
@ -1522,7 +1522,7 @@
arry = []; arry = [];
len = parsed.length; len = parsed.length;
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
arry.push( parsed[indx] ); arry[ arry.length ] = parsed[indx];
} }
return arry; return arry;
} }
@ -1551,23 +1551,23 @@
if ( wo.filter_useParsedData || if ( wo.filter_useParsedData ||
c.parsers[column].parsed || c.parsers[column].parsed ||
c.$headerIndexed[column].hasClass( 'filter-parsed' ) ) { c.$headerIndexed[column].hasClass( 'filter-parsed' ) ) {
arry.push( '' + cache.normalized[ rowIndex ][ column ] ); arry[ arry.length ] = '' + cache.normalized[ rowIndex ][ column ];
// child row parsed data // child row parsed data
if ( wo.filter_childRows && wo.filter_childByColumn ) { if ( wo.filter_childRows && wo.filter_childByColumn ) {
childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length - 1; childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length - 1;
for ( indx = 0; indx < childLen; indx++ ) { for ( indx = 0; indx < childLen; indx++ ) {
arry.push( '' + cache.normalized[ rowIndex ][ c.columns ].child[ indx ][ column ] ); arry[ arry.length ] = '' + cache.normalized[ rowIndex ][ c.columns ].child[ indx ][ column ];
} }
} }
} else { } else {
// get raw cached data instead of content directly from the cells // get raw cached data instead of content directly from the cells
arry.push( cache.normalized[ rowIndex ][ c.columns ].raw[ column ] ); arry[ arry.length ] = cache.normalized[ rowIndex ][ c.columns ].raw[ column ];
// child row unparsed data // child row unparsed data
if ( wo.filter_childRows && wo.filter_childByColumn ) { if ( wo.filter_childRows && wo.filter_childByColumn ) {
childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length; childLen = cache.normalized[ rowIndex ][ c.columns ].$row.length;
for ( indx = 1; indx < childLen; indx++ ) { for ( indx = 1; indx < childLen; indx++ ) {
child = cache.normalized[ rowIndex ][ c.columns ].$row.eq( indx ).children().eq( column ); child = cache.normalized[ rowIndex ][ c.columns ].$row.eq( indx ).children().eq( column );
arry.push( '' + ts.getElementText( c, child, column ) ); arry[ arry.length ] = '' + ts.getElementText( c, child, column );
} }
} }
} }

View File

@ -443,7 +443,7 @@
p = c.pager, p = c.pager,
namespace = c.namespace + 'pager', namespace = c.namespace + 'pager',
sz = tsp.parsePageSize( c, p.size, 'get' ); // don't allow dividing by zero sz = tsp.parsePageSize( c, p.size, 'get' ); // don't allow dividing by zero
if ( wo.pager_countChildRows ) { t.push( c.cssChildRow ); } if ( wo.pager_countChildRows ) { t[ t.length ] = c.cssChildRow; }
p.$size p.$size
.add( p.$goto ) .add( p.$goto )
.removeClass( wo.pager_css.disabled ) .removeClass( wo.pager_css.disabled )
@ -542,10 +542,10 @@
optionPagesStartPage = largeCollection ? skipSetSize : 1; optionPagesStartPage = largeCollection ? skipSetSize : 1;
for ( i = optionPagesStartPage; i <= pg; ) { for ( i = optionPagesStartPage; i <= pg; ) {
optionPages.push( i ); optionPages[ optionPages.length ] = i;
i = i + ( largeCollection ? skipSetSize : 1 ); i = i + ( largeCollection ? skipSetSize : 1 );
} }
optionPages.push( pg ); optionPages[ optionPages.length ] = pg;
if ( largeCollection ) { if ( largeCollection ) {
focusOptionPages = []; focusOptionPages = [];
@ -558,7 +558,7 @@
if ( endPage > pg ) { endPage = pg; } if ( endPage > pg ) { endPage = pg; }
// construct an array to get a focus set around the current page // construct an array to get a focus set around the current page
for ( i = startPage; i <= endPage ; i++ ) { for ( i = startPage; i <= endPage ; i++ ) {
focusOptionPages.push( i ); focusOptionPages[ focusOptionPages.length ] = i;
} }
// keep unique values // keep unique values
@ -649,7 +649,7 @@
} else { } else {
$rows[ rowIndex ].style.display = ( size >= start && size < end ) ? '' : 'none'; $rows[ rowIndex ].style.display = ( size >= start && size < end ) ? '' : 'none';
if ( last !== size && size >= start && size < end ) { if ( last !== size && size >= start && size < end ) {
p.cacheIndex.push( rowIndex ); p.cacheIndex[ p.cacheIndex.length ] = rowIndex;
last = size; last = size;
} }
// don't count child rows // don't count child rows
@ -875,7 +875,7 @@
sortCol = sortCol[ 1 ]; sortCol = sortCol[ 1 ];
len = sortList.length; len = sortList.length;
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
arry.push( sortCol + '[' + sortList[ indx ][ 0 ] + ']=' + sortList[ indx ][ 1 ] ); arry[ arry.length ] = sortCol + '[' + sortList[ indx ][ 0 ] + ']=' + sortList[ indx ][ 1 ];
} }
// if the arry is empty, just add the col parameter... '&{sortList:col}' becomes '&col' // if the arry is empty, just add the col parameter... '&{sortList:col}' becomes '&col'
url = url.replace( /\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join( '&' ) : sortCol ); url = url.replace( /\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join( '&' ) : sortCol );
@ -886,7 +886,7 @@
len = filterList.length; len = filterList.length;
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
if ( filterList[ indx ] ) { if ( filterList[ indx ] ) {
arry.push( filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[ indx ] ) ); arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[ indx ] );
} }
} }
// if the arry is empty, just add the fcol parameter... '&{filterList:fcol}' becomes '&fcol' // if the arry is empty, just add the fcol parameter... '&{filterList:fcol}' becomes '&fcol'
@ -945,7 +945,7 @@
count++; count++;
if ( count > s && added <= e ) { if ( count > s && added <= e ) {
added++; added++;
p.cacheIndex.push( index ); p.cacheIndex[ p.cacheIndex.length ] = index;
$tb.append( rows[ index ] ); $tb.append( rows[ index ] );
} }
} }
@ -1015,7 +1015,7 @@
normalized = c.cache[ 0 ].normalized; normalized = c.cache[ 0 ].normalized;
p.totalRows = normalized.length; p.totalRows = normalized.length;
for ( index = 0; index < p.totalRows; index++ ) { for ( index = 0; index < p.totalRows; index++ ) {
rows.push( normalized[ index ][ c.columns ].$row ); rows[ rows.length ] = normalized[ index ][ c.columns ].$row;
} }
c.rowsCopy = rows; c.rowsCopy = rows;
tsp.moveToPage( c, p, true ); tsp.moveToPage( c, p, true );