Commit e8891340 authored by Richard Gibson's avatar Richard Gibson

Fix #11795, #10470: keep scripts in DOM; execute only on first insertion. Close gh-864.

parent 90f9f496
...@@ -16,6 +16,7 @@ var ...@@ -16,6 +16,7 @@ var
_$ = window.$, _$ = window.$,
// Save a reference to some core methods // Save a reference to some core methods
core_concat = Array.prototype.concat,
core_push = Array.prototype.push, core_push = Array.prototype.push,
core_slice = Array.prototype.slice, core_slice = Array.prototype.slice,
core_indexOf = Array.prototype.indexOf, core_indexOf = Array.prototype.indexOf,
...@@ -472,26 +473,31 @@ jQuery.extend({ ...@@ -472,26 +473,31 @@ jQuery.extend({
// data: string of html // data: string of html
// context (optional): If specified, the fragment will be created in this context, defaults to document // 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 // keepScripts (optional): If true, will include scripts passed in the html string
parseHTML: function( data, context, scripts ) { parseHTML: function( data, context, keepScripts ) {
var parsed;
if ( !data || typeof data !== "string" ) { if ( !data || typeof data !== "string" ) {
return null; return null;
} }
if ( typeof context === "boolean" ) { if ( typeof context === "boolean" ) {
scripts = context; keepScripts = context;
context = 0; context = false;
} }
context = context || document; context = context || document;
var parsed = rsingleTag.exec( data ),
scripts = !keepScripts && [];
// Single tag // Single tag
if ( (parsed = rsingleTag.exec( data )) ) { if ( parsed ) {
return [ context.createElement( parsed[1] ) ]; return [ context.createElement( parsed[1] ) ];
} }
parsed = jQuery.buildFragment( [ data ], context, scripts ? null : [] ); parsed = jQuery.buildFragment( [ data ], context, scripts );
if ( scripts ) {
jQuery( scripts ).remove();
}
return jQuery.merge( [], return jQuery.merge( [],
(parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment).childNodes ); ( parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment ).childNodes );
}, },
parseJSON: function( data ) { parseJSON: function( data ) {
...@@ -744,7 +750,7 @@ jQuery.extend({ ...@@ -744,7 +750,7 @@ jQuery.extend({
} }
// Flatten any nested arrays // Flatten any nested arrays
return ret.concat.apply( [], ret ); return core_concat.apply( [], ret );
}, },
// A global GUID counter for objects // A global GUID counter for objects
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment