aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-01-29 00:22:20 -0500
committerjeresig <jeresig@gmail.com>2010-01-29 00:22:20 -0500
commit4f2e209b85b56351ed17ac0b5de60db85666209f (patch)
treef0d9ad9fffa9aa4b466485d4d8c3ec7717f96007 /src/manipulation.js
parent388a00fe918c2ec759bd33c34bfc13aabfe413d0 (diff)
downloadjquery-4f2e209b85b56351ed17ac0b5de60db85666209f.tar.gz
jquery-4f2e209b85b56351ed17ac0b5de60db85666209f.zip
Make sure fragment caching is only happening on nodes in the main document. Fixes #5978.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 93950de0f..88da6de52 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -384,10 +384,15 @@ function cloneCopyEvent(orig, ret) {
}
function buildFragment( args, nodes, scripts ) {
- var fragment, cacheable, cacheresults, doc;
+ var fragment, cacheable, cacheresults,
+ doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
+
+ // Only cache "small" (1/2 KB) strings that are associated with the main document
+ // Cloning options loses the selected state, so don't cache them
+ // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
+ if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
+ args[0].indexOf("<option") < 0 && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
- // webkit does not clone 'checked' attribute of radio inputs on cloneNode, so don't cache if string has a checked
- if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
cacheable = true;
cacheresults = jQuery.fragments[ args[0] ];
if ( cacheresults ) {
@@ -398,7 +403,6 @@ function buildFragment( args, nodes, scripts ) {
}
if ( !fragment ) {
- doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
fragment = doc.createDocumentFragment();
jQuery.clean( args, doc, fragment, scripts );
}