Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 78a21fd

Browse files
author
Gabriel Schulhof
committed
Table: Reflow: Convert to proper extension.
1 parent 2151fc1 commit 78a21fd

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

js/widgets/table.reflow.js

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,53 @@ define( [ "jquery", "./table" ], function( jQuery ) {
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, undefined ) {
1111

12-
$.mobile.table.prototype.options.mode = "reflow";
13-
14-
$.mobile.table.prototype.options.classes = $.extend(
15-
$.mobile.table.prototype.options.classes,
16-
{
17-
reflowTable: "ui-table-reflow",
18-
cellLabels: "ui-table-cell-label"
19-
}
20-
);
21-
22-
$.mobile.document.delegate( ":jqmData(role='table')", "tablecreate", function() {
23-
24-
var $table = $( this ),
25-
self = $table.data( "mobile-table" ),
26-
o = self.options;
27-
28-
// If it's not reflow mode, return here.
29-
if( o.mode !== "reflow" ){
30-
return;
31-
}
32-
33-
self.element.addClass( o.classes.reflowTable );
34-
35-
// get headers in reverse order so that top-level headers are appended last
36-
var reverseHeaders = $( self.allHeaders.get().reverse() );
37-
38-
// create the hide/show toggles
39-
reverseHeaders.each(function(i){
40-
var $cells = $( this ).jqmData( "cells" ),
41-
colstart = $( this ).jqmData( "colstart" ),
42-
hierarchyClass = $cells.not( this ).filter( "thead th" ).length && " ui-table-cell-label-top",
43-
text = $(this).text();
44-
45-
if( text !== "" ){
46-
47-
if( hierarchyClass ){
48-
var iteration = parseInt( $( this ).attr( "colspan" ), 10 ),
49-
filter = "";
50-
51-
if( iteration ){
52-
filter = "td:nth-child("+ iteration +"n + " + ( colstart ) +")";
12+
$.widget( "mobile.table", $.mobile.table, {
13+
options: {
14+
mode: "reflow",
15+
classes: $.extend( $.mobile.table.prototype.options.classes, {
16+
reflowTable: "ui-table-reflow",
17+
cellLabels: "ui-table-cell-label"
18+
})
19+
},
20+
21+
_create: function() {
22+
var o = this.options;
23+
24+
this._super();
25+
26+
// If it's not reflow mode, return here.
27+
if( o.mode !== "reflow" ) {
28+
return;
29+
}
30+
31+
this.element.addClass( o.classes.reflowTable );
32+
33+
// get headers in reverse order so that top-level headers are appended last
34+
$( this.allHeaders.get().reverse() ).each( function( i ) {
35+
// create the hide/show toggles
36+
var $cells = $( this ).jqmData( "cells" ),
37+
colstart = $( this ).jqmData( "colstart" ),
38+
hierarchyClass = $cells.not( this ).filter( "thead th" ).length && " ui-table-cell-label-top",
39+
text = $(this).text();
40+
41+
if( text !== "" ) {
42+
43+
if( hierarchyClass ) {
44+
var iteration = parseInt( $( this ).attr( "colspan" ), 10 ),
45+
filter = "";
46+
47+
if( iteration ){
48+
filter = "td:nth-child("+ iteration +"n + " + ( colstart ) +")";
49+
}
50+
$cells.filter( filter ).prepend( "<b class='" + o.classes.cellLabels + hierarchyClass + "'>" + text + "</b>" );
51+
}
52+
else {
53+
$cells.prepend( "<b class='" + o.classes.cellLabels + "'>" + text + "</b>" );
5354
}
54-
$cells.filter( filter ).prepend( "<b class='" + o.classes.cellLabels + hierarchyClass + "'>" + text + "</b>" );
55-
}
56-
else {
57-
$cells.prepend( "<b class='" + o.classes.cellLabels + "'>" + text + "</b>" );
58-
}
59-
60-
}
61-
});
6255

56+
}
57+
});
58+
}
6359
});
6460

6561
})( jQuery );

0 commit comments

Comments
 (0)