From: Dave Methvin Date: Tue, 19 Dec 2006 04:31:33 +0000 (+0000) Subject: jQuery.merge speedup, bug#444 X-Git-Tag: 1.1a~96 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0e540ec1b170c11cab11045b4965a927cb44ee34;p=jquery.git jQuery.merge speedup, bug#444 duplicated, bug#418 (jQuery.clean & domManip) query for id in context ignores context, bug#267 --- diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index be39a87d9..25fd4dd82 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -331,11 +331,15 @@ test("expressions - element", function() { }); test("expressions - id", function() { - expect(5); + expect(8); t( "ID Selector", "#body", ["body"] ); t( "ID Selector w/ Element", "body#body", ["body"] ); t( "ID Selector w/ Element", "ul#first", [] ); + t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267 + t( "ID Selector, not an ancestor ID", "#form #first", [] ); + t( "ID Selector, not a child ID", "#form > #option1a", [] ); + t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] ); t( "All Children of ID with no children", "#firstUL/*", [] ); }); diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index e48f721a0..d3ed8c6ee 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -988,33 +988,27 @@ jQuery.fn = jQuery.prototype = { * @private * @name domManip * @param Array args - * @param Boolean table - * @param Number dir + * @param Boolean table Insert TBODY in TABLEs if one is not found. + * @param Number dir If dir<0, process args in reverse order. * @param Function fn The function doing the DOM manipulation. * @type jQuery * @cat Core */ domManip: function(args, table, dir, fn){ - var clone = this.size() > 1; + var clone = this.length > 1; var a = jQuery.clean(args); + if ( dir < 0 ) + a.reverse(); return this.each(function(){ var obj = this; - if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) { - var tbody = this.getElementsByTagName("tbody"); + if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" ) + obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); - if ( !tbody.length ) { - obj = document.createElement("tbody"); - this.appendChild( obj ); - } else - obj = tbody[0]; - } + for ( var i=0; i < a.length; i++ ) + fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] ); - for ( var i = ( dir < 0 ? a.length - 1 : 0 ); - i != ( dir < 0 ? dir : a.length ); i += dir ) { - fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] ); - } }); }, @@ -1337,26 +1331,44 @@ jQuery.extend({ return ret; }, - clean: function(a) { + clean: function(a) { var r = []; for ( var i = 0; i < a.length; i++ ) { var arg = a[i]; if ( typeof arg == "string" ) { // Convert html string into DOM nodes // Trim whitespace, otherwise indexOf won't work as expected - var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""]; + var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6), + div = document.createElement("div"), wrap = [0,"",""]; - if ( !s.indexOf("", ""]; - else if ( !s.indexOf("", ""]; - else if ( !s.indexOf("", ""]; // tbody auto-inserted - else if ( !s.indexOf("", ""]; + else if ( s3 == " matched above wrap = [3, "", "
"]; // Go to html and back, then peel off extra wrappers div.innerHTML = wrap[1] + s + wrap[2]; while ( wrap[0]-- ) div = div.firstChild; + + // Remove IE's autoinserted from table fragments + if ( jQuery.browser.msie ) { + var tb = null; + // String was a , *may* have spurious + if ( s6 == " or + else if ( wrap[1] == "
" && s.indexOf("= 0 ; --n ) + if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length ) + tb[n].parentNode.removeChild(tb[n]); + } + } + arg = div.childNodes; } @@ -1373,7 +1385,7 @@ jQuery.extend({ expr: { "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()", - "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]", + "#": "a.getAttribute('id')==m[2]", ":": { // Position Checks lt: "i