aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-01-28 16:30:37 -0500
committerjeresig <jeresig@gmail.com>2010-01-28 16:30:37 -0500
commit0db207da238e879dad20f68178e6248750d3b984 (patch)
tree4efb926fcd3a17b90c050f1be9f20f92b0b73366 /src
parent98c7248518f9a2082ccf50240b5ab44bf98d7b5e (diff)
downloadjquery-0db207da238e879dad20f68178e6248750d3b984.tar.gz
jquery-0db207da238e879dad20f68178e6248750d3b984.zip
Optimize for the case where a fragment-bound element is being injected into one other element.
Diffstat (limited to 'src')
-rw-r--r--src/core.js2
-rw-r--r--src/manipulation.js29
2 files changed, 20 insertions, 11 deletions
diff --git a/src/core.js b/src/core.js
index efdc4570f..81b48318c 100644
--- a/src/core.js
+++ b/src/core.js
@@ -100,6 +100,8 @@ jQuery.fn = jQuery.prototype = {
selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
}
+ return jQuery.merge( this, selector );
+
// HANDLE: $("#id")
} else {
elem = document.getElementById( match[2] );
diff --git a/src/manipulation.js b/src/manipulation.js
index ed049de7c..01c6b0ba7 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -415,13 +415,20 @@ jQuery.each({
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
var ret = [], insert = jQuery( selector );
-
- for ( var i = 0, l = insert.length; i < l; i++ ) {
- var elems = (i > 0 ? this.clone(true) : this).get();
- jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
- ret = ret.concat( elems );
+
+ if ( this.length === 1 && this[0].parentNode && this[0].parentNode.nodeType === 11 && insert.length === 1 ) {
+ insert[ original ]( this[0] );
+ return this;
+
+ } else {
+ for ( var i = 0, l = insert.length; i < l; i++ ) {
+ var elems = (i > 0 ? this.clone(true) : this).get();
+ jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
+ ret = ret.concat( elems );
+ }
+
+ return this.pushStack( ret, name, insert.selector );
}
- return this.pushStack( ret, name, insert.selector );
};
});
@@ -436,13 +443,13 @@ jQuery.extend({
var ret = [];
- jQuery.each(elems, function( i, elem ) {
+ for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
if ( typeof elem === "number" ) {
elem += "";
}
if ( !elem ) {
- return;
+ continue;
}
// Convert html string into DOM nodes
@@ -493,7 +500,7 @@ jQuery.extend({
div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
}
- elem = jQuery.makeArray( div.childNodes );
+ elem = div.childNodes;
}
if ( elem.nodeType ) {
@@ -501,13 +508,13 @@ jQuery.extend({
} else {
ret = jQuery.merge( ret, elem );
}
-
- });
+ }
if ( fragment ) {
for ( var i = 0; ret[i]; i++ ) {
if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
+
} else {
if ( ret[i].nodeType === 1 ) {
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );