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

Commit 14d2343

Browse files
author
Gabriel Schulhof
committed
Table: Copy entire contents of reflow headers into reflow bold tags
(cherry picked from commit a9472ce) Closes gh-7437 Fixes gh-7415
1 parent 7b27520 commit 14d2343

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

js/widgets/table.reflow.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ $.widget( "mobile.table", $.mobile.table, {
5656
var cells = $( this ).jqmData( "cells" ),
5757
colstart = $.mobile.getAttribute( this, "colstart" ),
5858
hierarchyClass = cells.not( this ).filter( "thead th" ).length && " ui-table-cell-label-top",
59-
text = $( this ).text(),
59+
contents = $( this ).clone().contents(),
6060
iteration, filter;
6161

62-
if ( text !== "" ) {
62+
if ( contents.length > 0 ) {
6363

6464
if ( hierarchyClass ) {
6565
iteration = parseInt( this.getAttribute( "colspan" ), 10 );
@@ -69,18 +69,21 @@ $.widget( "mobile.table", $.mobile.table, {
6969
filter = "td:nth-child("+ iteration +"n + " + ( colstart ) +")";
7070
}
7171

72-
table._addLabels( cells.filter( filter ), opts.classes.cellLabels + hierarchyClass, text );
72+
table._addLabels( cells.filter( filter ),
73+
opts.classes.cellLabels + hierarchyClass, contents );
7374
} else {
74-
table._addLabels( cells, opts.classes.cellLabels, text );
75+
table._addLabels( cells, opts.classes.cellLabels, contents );
7576
}
7677

7778
}
7879
});
7980
},
8081

81-
_addLabels: function( cells, label, text ) {
82+
_addLabels: function( cells, label, contents ) {
8283
// .not fixes #6006
83-
cells.not( ":has(b." + label + ")" ).prepend( "<b class='" + label + "'>" + text + "</b>" );
84+
cells
85+
.not( ":has(b." + label + ")" )
86+
.prepend( $( "<b class='" + label + "'></b>" ).append( contents ) );
8487
}
8588
});
8689

tests/unit/table/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
3434
<link rel="stylesheet" href="../../jqm-tests.css"/>
3535

36+
<style>
37+
.make-it-red {
38+
color: red;
39+
}
40+
</style>
3641
<script src="../../swarminject.js"></script>
3742
<script type="text/javascript">
3843
// basic
@@ -108,7 +113,7 @@ <h1>Basic Table</h1>
108113
<thead>
109114
<tr>
110115
<th data-priority="1">Rank</th>
111-
<th data-priority="persist">Movie Title</th>
116+
<th data-priority="persist">Movie <span class="make-it-red">Title</span></th>
112117
<th data-priority="2">Year</th>
113118
<th data-priority="3"><abbr title="Rotten Tomato Rating">Rating</abbr></th>
114119
<th data-priority="4">Reviews</th>

tests/unit/table/table_core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
asyncTest( "The page should be enhanced correctly" , function(){
9393
setTimeout(function() {
9494
ok($('#reflow-table-test .ui-table-reflow').length, ".ui-table-reflow class added to table element");
95+
deepEqual(
96+
$( "#reflow-table-test .ui-table-reflow > tbody span.make-it-red" ).length, 1,
97+
"span was copied from table header" );
9598
start();
9699
}, 800);
97100
});

0 commit comments

Comments
 (0)