Skip to content

Commit e619e8c

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 Closes gh-2031 Fixes gh-2002
1 parent 0cb1e14 commit e619e8c

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/manipulation.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,20 @@ var
3333
option: [ 1, "<select multiple='multiple'>", "</select>" ],
3434

3535
thead: [ 1, "<table>", "</table>" ],
36+
37+
// Some of the following wrappers are not fully defined, because
38+
// their parent elements (except for "table" element) could be omitted
39+
// since browser parsers are smart enough to auto-insert them
40+
41+
// Support: Android 2.3
42+
// Android browser doesn't auto-insert colgroup
3643
col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
37-
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
38-
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
44+
45+
// Auto-insert "tbody" element
46+
tr: [ 2, "<table>", "</table>" ],
47+
48+
// Auto-insert "tbody" and "tr" elements
49+
td: [ 3, "<table>", "</table>" ],
3950

4051
_default: [ 0, "", "" ]
4152
};

test/unit/manipulation.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,3 +2447,41 @@ test( "Validate creation of multiple quantities of certain elements (#13818)", 4
24472447
});
24482448
});
24492449
});
2450+
2451+
test( "Make sure col element is appended correctly", function() {
2452+
expect( 1 );
2453+
2454+
var table = jQuery( "<table cellpadding='0'><tr><td>test</td></tr></table>" );
2455+
2456+
jQuery( table ).appendTo( "#qunit-fixture" );
2457+
2458+
jQuery( "<col width='150'/>" ).prependTo( table );
2459+
2460+
strictEqual( table.find( "td" ).width(), 150 );
2461+
});
2462+
2463+
asyncTest( "Insert script with data-URI (gh-1887)", 1, function() {
2464+
Globals.register( "testFoo" );
2465+
Globals.register( "testSrcFoo" );
2466+
2467+
var script = document.createElement( "script" ),
2468+
fixture = document.getElementById( "qunit-fixture" );
2469+
2470+
script.src = "data:text/javascript,testSrcFoo = 'foo';";
2471+
2472+
fixture.appendChild( script );
2473+
2474+
jQuery( fixture ).append( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" );
2475+
2476+
setTimeout(function() {
2477+
if ( window[ "testSrcFoo" ] === "foo" ) {
2478+
strictEqual( window[ "testFoo" ], window[ "testSrcFoo" ], "data-URI script executed" );
2479+
2480+
} else {
2481+
ok( true, "data-URI script is not supported by this environment" );
2482+
}
2483+
2484+
start();
2485+
}, 100 );
2486+
});
2487+
>>>>>>> 0ea342a... Manipulation: simplify html wrappers

0 commit comments

Comments
 (0)