mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Added caching to domManip. Fixes #4883.
This commit is contained in:
parent
fd2a2fed84
commit
8db967e9d5
@ -137,24 +137,55 @@ jQuery.fn.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
domManip: function( args, table, callback ) {
|
domManip: function( args, table, callback ) {
|
||||||
|
var fragment, scripts, cacheable, cached, cacheresults, first;
|
||||||
|
|
||||||
if ( this[0] ) {
|
if ( this[0] ) {
|
||||||
var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
|
if ( args.length === 1 && typeof args[0] === "string" ) {
|
||||||
scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
|
cacheable = true;
|
||||||
|
cacheresults = jQuery.fragments[ args[0] ];
|
||||||
|
if ( cacheresults ) {
|
||||||
|
if ( cacheresults !== 1 ) {
|
||||||
|
fragment = cacheresults;
|
||||||
|
}
|
||||||
|
cached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !fragment ) {
|
||||||
|
fragment = (this[0].ownerDocument || this[0]).createDocumentFragment();
|
||||||
|
scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment );
|
||||||
|
}
|
||||||
|
|
||||||
first = fragment.firstChild;
|
first = fragment.firstChild;
|
||||||
|
|
||||||
if ( first )
|
if ( first ) {
|
||||||
for ( var i = 0, l = this.length; i < l; i++ )
|
table = table && jQuery.nodeName( first, "tr" );
|
||||||
callback.call( root(this[i], first), this.length > 1 || i > 0 ?
|
|
||||||
fragment.cloneNode(true) : fragment );
|
|
||||||
|
|
||||||
if ( scripts )
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||||
|
callback.call(
|
||||||
|
table ?
|
||||||
|
root(this[i], first) :
|
||||||
|
this[i],
|
||||||
|
cacheable || this.length > 1 || i > 0 ?
|
||||||
|
fragment.cloneNode(true) :
|
||||||
|
fragment
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( scripts ) {
|
||||||
jQuery.each( scripts, evalScript );
|
jQuery.each( scripts, evalScript );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( cacheable ) {
|
||||||
|
jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
function root( elem, cur ) {
|
function root( elem, cur ) {
|
||||||
return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
|
return jQuery.nodeName(elem, "table") ?
|
||||||
(elem.getElementsByTagName("tbody")[0] ||
|
(elem.getElementsByTagName("tbody")[0] ||
|
||||||
elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
|
elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
|
||||||
elem;
|
elem;
|
||||||
@ -162,6 +193,8 @@ jQuery.fn.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jQuery.fragments = {};
|
||||||
|
|
||||||
jQuery.each({
|
jQuery.each({
|
||||||
appendTo: "append",
|
appendTo: "append",
|
||||||
prependTo: "prepend",
|
prependTo: "prepend",
|
||||||
|
Loading…
Reference in New Issue
Block a user