From b744a50d472664a4d5aaa35d58e2215d48f70d3b Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Tue, 10 Feb 2015 23:49:44 +0300 Subject: [PATCH] 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 0ea342a6a6dce793c1b0f14f051c2573f40f4e44) Closes gh-2031 Fixes gh-2002 --- src/manipulation.js | 17 ++++++++++++++--- test/unit/manipulation.js | 13 ++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 1d4716a18..49426dbe6 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -52,9 +52,20 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|" + param: [ 1, "", "" ], thead: [ 1, "", "
" ], - tr: [ 2, "", "
" ], - col: [ 2, "", "
" ], - td: [ 3, "", "
" ], + + // Some of the following wrappers are not fully defined, because + // their parent elements (except for "table" element) could be omitted + // since browser parsers are smart enough to auto-insert them + + // Support: Android 2.3 + // Android browser doesn't auto-insert colgroup + col: [ 2, "", "
" ], + + // Auto-insert "tbody" element + tr: [ 2, "", "
" ], + + // Auto-insert "tbody" and "tr" elements + td: [ 3, "", "
" ], // IE8 can't serialize link, script, style, or any html5 (NoScope) tags, // unless wrapped in a div with non-breaking characters in front of it. diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 4e1bdd298..9ea53b8ab 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2485,6 +2485,18 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1, equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" ); }); +test( "Make sure col element is appended correctly", function() { + expect( 1 ); + + var table = jQuery( "
test
" ); + + jQuery( table ).appendTo( "#qunit-fixture" ); + + jQuery( "" ).prependTo( table ); + + strictEqual( table.find( "td" ).width(), 150 ); +}); + asyncTest( "Insert script with data-URI (gh-1887)", 1, function() { Globals.register( "testFoo" ); Globals.register( "testSrcFoo" ); @@ -2509,4 +2521,3 @@ asyncTest( "Insert script with data-URI (gh-1887)", 1, function() { start(); }, 100 ); }); - -- 2.39.5