Skip to content

Commit b744a50

Browse files
committed
Manipulation: simplify html wrappers
Take advantage of html serialization for html wrappers - saves 26 bytes Plus add additional test for "col" element (cherry-picked from 0ea342a) Closes gh-2031 Fixes gh-2002
1 parent 3e87120 commit b744a50

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/manipulation.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,20 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|" +
5252
param: [ 1, "<object>", "</object>" ],
5353

5454
thead: [ 1, "<table>", "</table>" ],
55-
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
56-
col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
57-
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
55+
56+
// Some of the following wrappers are not fully defined, because
57+
// their parent elements (except for "table" element) could be omitted
58+
// since browser parsers are smart enough to auto-insert them
59+
60+
// Support: Android 2.3
61+
// Android browser doesn't auto-insert colgroup
62+
col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
63+
64+
// Auto-insert "tbody" element
65+
tr: [ 2, "<table>", "</table>" ],
66+
67+
// Auto-insert "tbody" and "tr" elements
68+
td: [ 3, "<table>", "</table>" ],
5869

5970
// IE8 can't serialize link, script, style, or any html5 (NoScope) tags,
6071
// unless wrapped in a div with non-breaking characters in front of it.

test/unit/manipulation.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,18 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1,
24852485
equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
24862486
});
24872487

2488+
test( "Make sure col element is appended correctly", function() {
2489+
expect( 1 );
2490+
2491+
var table = jQuery( "<table cellpadding='0'><tr><td style='padding:0'>test</td></tr></table>" );
2492+
2493+
jQuery( table ).appendTo( "#qunit-fixture" );
2494+
2495+
jQuery( "<col width='150'/>" ).prependTo( table );
2496+
2497+
strictEqual( table.find( "td" ).width(), 150 );
2498+
});
2499+
24882500
asyncTest( "Insert script with data-URI (gh-1887)", 1, function() {
24892501
Globals.register( "testFoo" );
24902502
Globals.register( "testSrcFoo" );
@@ -2509,4 +2521,3 @@ asyncTest( "Insert script with data-URI (gh-1887)", 1, function() {
25092521
start();
25102522
}, 100 );
25112523
});
2512-

0 commit comments

Comments
 (0)