Permalink
Browse files

Table: Cleanup.

  • Loading branch information...
1 parent 78a21fd commit 6e11fc8f9875d2d3ae01bafb7fceefbc07ad30ba @gabrielschulhof gabrielschulhof committed Mar 26, 2013
Showing with 33 additions and 35 deletions.
  1. +33 −35 js/widgets/table.js
View
@@ -10,59 +10,57 @@ define( [ "jquery", "../jquery.mobile.widget", "./page", "./page.sections" ], fu
(function( $, undefined ) {
$.widget( "mobile.table", $.mobile.widget, {
-
- options: {
- classes: {
- table: "ui-table"
- },
- initSelector: ":jqmData(role='table')"
+ options: {
+ classes: {
+ table: "ui-table"
},
+ initSelector: ":jqmData(role='table')"
+ },
- _create: function() {
+ _create: function() {
+ var $el = this.element,
+ trs = this.element.find( "thead tr" ),
+ headers = this.element.find( "tr:eq(0)" ).children(),
+ allHeaders = headers.add( trs.children() );
- var self = this,
- trs = this.element.find( "thead tr" );
+ this.element.addClass( this.options.classes.table );
- this.element.addClass( this.options.classes.table );
+ $.extend( this, {
// Expose headers and allHeaders properties on the widget
// headers references the THs within the first TR in the table
- self.headers = this.element.find( "tr:eq(0)" ).children();
+ headers: headers,
// allHeaders references headers, plus all THs in the thead, which may include several rows, or not
- self.allHeaders = self.headers.add( trs.children() );
-
- trs.each(function(){
+ allHeaders: allHeaders
+ });
- var coltally = 0;
+ trs.each( function() {
+ var coltally = 0,
+ $this = $( this );
- $( this ).children().each(function( i ){
+ $this.children().each( function( i ) {
+ var $this = $( this ),
+ span = parseInt( $this.attr( "colspan" ), 10 ),
+ sel = ":nth-child(" + ( coltally + 1 ) + ")";
- var span = parseInt( $( this ).attr( "colspan" ), 10 ),
- sel = ":nth-child(" + ( coltally + 1 ) + ")";
-
- $( this )
- .jqmData( "colstart", coltally + 1 );
+ $this.jqmData( "colstart", coltally + 1 );
- if( span ){
- for( var j = 0; j < span - 1; j++ ){
- coltally++;
- sel += ", :nth-child(" + ( coltally + 1 ) + ")";
- }
+ if( span ) {
+ for( var j = 0; j < span - 1; j++ ) {
+ coltally++;
+ sel += ", :nth-child(" + ( coltally + 1 ) + ")";
}
+ }
- // Store "cells" data on header as a reference to all cells in the same column as this TH
- $( this )
- .jqmData( "cells", self.element.find( "tr" ).not( trs.eq(0) ).not( this ).children( sel ) );
-
- coltally++;
-
- });
+ // Store "cells" data on header as a reference to all cells in the same column as this TH
+ $this
+ .jqmData( "cells", $el.find( "tr" ).not( trs.eq( 0 ) ).not( this ).children( sel ) );
+ coltally++;
});
-
+ });
}
-
});
//auto self-init widgets

0 comments on commit 6e11fc8

Please sign in to comment.