Permalink
Browse files

Table: Stop querying the table for "thead tr" in a loop

  • Loading branch information...
gabrielschulhof authored and arschmitz committed May 15, 2014
1 parent 65555bf commit 04f66f76d1669baa3ccaefc26b4984179ae3db01
Showing with 13 additions and 18 deletions.
  1. +12 −17 js/widgets/table.js
  2. +1 −1 js/widgets/table.reflow.js
View
@@ -63,20 +63,17 @@ return $.widget( "mobile.table", {
},
_setHeaders: function() {
var headerRows = this.element.children( "thead" ).children( "tr" );
this.headers = headerRows.first().children();
this.allHeaders = headerRows.children();
this.headerRows = this.element.children( "thead" ).children( "tr" );
this.headers = this.headerRows.first().children();
this.allHeaders = this.headerRows.children();
},
rebuild: function() {
this.refresh();
},
_refreshHeadCell: function( cellIndex, element, columnCount ) {
_refreshHeaderCell: function( cellIndex, element, columnCount ) {
var columnIndex,
table = this.element,
trs = table.find( "thead tr" ),
span = parseInt( element.getAttribute( "colspan" ), 10 ),
selector = ":nth-child(" + ( columnCount + 1 ) + ")";
@@ -89,33 +86,31 @@ return $.widget( "mobile.table", {
// Store "cells" data on header as a reference to all cells in the same column as this TH
$( element ).jqmData( "cells",
table
.find( "tr" )
.not( trs.eq( 0 ) )
this.element
.children( "thead,tbody" )
.children( "tr" )
.not( this.headerRows.eq( 0 ) )
.not( element )
.children( selector ) );
return columnCount;
},
_refreshHeadRow: function( rowIndex, element ) {
_refreshHeaderRow: function( rowIndex, element ) {
var columnCount = 0;
// Iterate over the children of the tr
$( element ).children().each( $.proxy( function( cellIndex, element ) {
columnCount = this._refreshHeadCell( cellIndex, element, columnCount ) + 1;
columnCount = this._refreshHeaderCell( cellIndex, element, columnCount ) + 1;
}, this ) );
},
refresh: function() {
var table = this.element,
trs = table.find( "thead tr" );
// updating headers on refresh (fixes #5880)
this._setHeaders();
// Iterate over the trs
trs.each( $.proxy( this, "_refreshHeadRow" ) );
// Iterate over the header rows
this.headerRows.each( $.proxy( this, "_refreshHeaderRow" ) );
},
_destroy: function() {
@@ -45,7 +45,7 @@ return $.widget( "mobile.table", $.mobile.table, {
return this._superApply( arguments );
},
_refreshHeadCell: function( cellIndex, element, columnCount ) {
_refreshHeaderCell: function( cellIndex, element, columnCount ) {
element.setAttribute( "data-" + $.mobile.ns + "colstart", columnCount + 1 );
return this._superApply( arguments );
},

0 comments on commit 04f66f7

Please sign in to comment.