Permalink
Browse files

Fix #11795: keep scripts in DOM; execute only on first insertion

  • Loading branch information...
gibson042 committed Jun 20, 2012
1 parent bea5ecb commit b748a8f7b112e3ab26109470640229ab92cf1099
Showing with 245 additions and 143 deletions.
  1. +12 −7 src/core.js
  2. +153 −116 src/manipulation.js
  3. +80 −20 test/unit/manipulation.js
View
@@ -17,6 +17,7 @@ var
_$ = window.$,
// Save a reference to some core methods
+ core_concat = Array.prototype.concat,
core_push = Array.prototype.push,
core_slice = Array.prototype.slice,
core_indexOf = Array.prototype.indexOf,
@@ -460,15 +461,15 @@ jQuery.extend({
// data: string of html
// context (optional): If specified, the fragment will be created in this context, defaults to document
- // scripts (optional): If true, will include scripts passed in the html string
- parseHTML: function( data, context, scripts ) {
- var parsed;
+ // keepScripts (optional): If true, will include scripts passed in the html string
+ parseHTML: function( data, context, keepScripts ) {
+ var parsed, scripts;
if ( !data || typeof data !== "string" ) {
return null;
}
if ( typeof context === "boolean" ) {
- scripts = context;
- context = 0;
+ keepScripts = context;
+ context = false;
}
context = context || document;
@@ -477,7 +478,11 @@ jQuery.extend({
return [ context.createElement( parsed[1] ) ];
}
- parsed = jQuery.buildFragment( [ data ], context, scripts ? null : [] );
+ scripts = !keepScripts && [];
+ parsed = jQuery.buildFragment( [ data ], context, scripts );
+ if ( scripts ) {
+ jQuery( scripts ).remove();
+ }
return jQuery.merge( [],
(parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment).childNodes );
},
@@ -732,7 +737,7 @@ jQuery.extend({
}
// Flatten any nested arrays
- return ret.concat.apply( [], ret );
+ return core_concat.apply( [], ret );
},
// A global GUID counter for objects
Oops, something went wrong.

0 comments on commit b748a8f

Please sign in to comment.