]> source.dussan.org Git - jquery.git/commitdiff
Landing pull request 490. 1.7 HTML5 Support for innerHTML, clone & style. Fixes ...
authorRick Waldron <waldron.rick@gmail.com>
Mon, 19 Sep 2011 20:42:36 +0000 (16:42 -0400)
committertimmywil <timmywillisn@gmail.com>
Mon, 19 Sep 2011 20:42:36 +0000 (16:42 -0400)
More Details:
 - https://github.com/jquery/jquery/pull/490
 - http://bugs.jquery.com/ticket/6485

src/manipulation.js
src/support.js
test/index.html
test/unit/manipulation.js

index 35c9544ffa003b2df2222b60e88e84a0b9ca7c80..bc2af18dc9bfd9fd3456f85b55f61e227040bfbd 100644 (file)
@@ -20,7 +20,23 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
                col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
                area: [ 1, "<map>", "</map>" ],
                _default: [ 0, "", "" ]
-       };
+       },
+       safeFragment = (function() {
+               var nodeNames = (
+                       "abbr article aside audio canvas datalist details figcaption figure footer " +
+                       "header hgroup mark meter nav output progress section summary time video"
+               ).split( " " ),
+               safeFrag = document.createDocumentFragment();
+
+               if ( safeFrag.createElement ) {
+                       while ( nodeNames.length ) {
+                               safeFrag.createElement(
+                                       nodeNames.pop()
+                               );
+                       }
+               }
+               return safeFrag;
+       })();
 
 wrapMap.optgroup = wrapMap.option;
 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
@@ -625,6 +641,9 @@ jQuery.extend({
                                                depth = wrap[0],
                                                div = context.createElement("div");
 
+                                       // Append wrapper element to unknown element safe doc fragment
+                                       safeFragment.appendChild( div );
+
                                        // Go to html and back, then peel off extra wrappers
                                        div.innerHTML = wrap[1] + elem + wrap[2];
 
index 6608d9125443f7488b7809b30bdf45301670621a..ad1bd9a57dbec9e7405b15d6582bfd4cd0a7067a 100644 (file)
@@ -24,7 +24,7 @@ jQuery.support = (function() {
 
        // Preliminary tests
        div.setAttribute("className", "t");
-       div.innerHTML = "   <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
+       div.innerHTML = "   <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/><nav></nav>";
 
 
        all = div.getElementsByTagName( "*" );
@@ -69,6 +69,9 @@ jQuery.support = (function() {
                // (IE uses styleFloat instead of cssFloat)
                cssFloat: !!a.style.cssFloat,
 
+               // Make sure unknown elements (like HTML5 elems) are handled appropriately
+               unknownElems: !!div.getElementsByTagName( "nav" ).length,
+
                // Make sure that if no value is specified for a checkbox
                // that it defaults to "on".
                // (WebKit defaults to "" instead)
index 17baa4894fae8f51a52dca6845d2b4f80769f779..294e0431677644a1042b41ebd9adf2c5a42f82b7 100644 (file)
        <script src="unit/effects.js"></script>
        <script src="unit/offset.js"></script>
        <script src="unit/dimensions.js"></script>
+
+       <script>
+       // html5shiv, enabling HTML5 elements to be used with jQuery
+               ( "abbr article aside audio canvas details figcaption figure footer header hgroup " +
+                       "mark meter nav output progress section subline summary time video"
+               ).replace(/\w+/g, function(n) {
+                       document.createElement(n);
+               });
+       </script>
 </head>
 
 <body id="body">
index 4017cf196ed87f761bf301ea808f3906085e28fc..3de3fa0b905bfe180146c82d2e847d95a6704dce 100644 (file)
@@ -465,6 +465,38 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
        jQuery("#listWithTabIndex li.test6997").eq(1).click();
 });
 
+test("append HTML5 sectioning elements (Bug #6485)", function () {
+       expect(2);
+
+       jQuery("#qunit-fixture").append("<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>");
+
+       var article = jQuery("article"),
+       aside = jQuery("aside");
+
+       equal( article.css("fontSize"), "10px", 'HTML5 elements are styleable');
+       equal( aside.length, 1, 'HTML5 elements do not collapse their children')
+});
+
+test("clone() (#6485)", function () {
+       expect(1);
+
+       jQuery("<article><section><aside>HTML5 elements</aside></section></article>").appendTo("#qunit-fixture");
+
+       var clone = jQuery("article").clone();
+
+       jQuery("#qunit-fixture").append( clone );
+
+       equal( jQuery("aside").length, 2, "clone()ing HTML5 elems does not collapse them" );
+});
+
+test("html(String) with HTML5 (Bug #6485)", function() {
+       expect(2);
+
+       jQuery("#qunit-fixture").html("<article><section><aside>HTML5 elements</aside></section></article>");
+       equal( jQuery("#qunit-fixture").children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" );
+       equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
+});
+
 test("append(xml)", function() {
        expect( 1 );