Blame view
app/bower_components/jquery/src/core/parseHTML.js
1.57 KB
87c93a029
|
1 |
define( [ |
f986e111b
|
2 |
"../core", |
87c93a029
|
3 |
"../var/document", |
f986e111b
|
4 |
"./var/rsingleTag", |
87c93a029
|
5 |
"../manipulation/buildFragment", |
f986e111b
|
6 |
|
87c93a029
|
7 8 9 10 11 12 13 14 15 |
// This is the only module that needs core/support "./support" ], function( jQuery, document, rsingleTag, buildFragment, support ) { "use strict"; // Argument "data" should be string of html // context (optional): If specified, the fragment will be created in this context, // defaults to document |
f986e111b
|
16 17 |
// keepScripts (optional): If true, will include scripts passed in the html string jQuery.parseHTML = function( data, context, keepScripts ) { |
87c93a029
|
18 19 |
if ( typeof data !== "string" ) { return []; |
f986e111b
|
20 21 22 23 24 |
} if ( typeof context === "boolean" ) { keepScripts = context; context = false; } |
f986e111b
|
25 |
|
87c93a029
|
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
var base, parsed, scripts; if ( !context ) { // Stop scripts or inline event handlers from being executed immediately // by using document.implementation if ( support.createHTMLDocument ) { context = document.implementation.createHTMLDocument( "" ); // Set the base href for the created document // so any parsed elements with URLs // are based on the document's URL (gh-2965) base = context.createElement( "base" ); base.href = document.location.href; context.head.appendChild( base ); } else { context = document; } } parsed = rsingleTag.exec( data ); scripts = !keepScripts && []; |
f986e111b
|
48 49 50 |
// Single tag if ( parsed ) { |
87c93a029
|
51 |
return [ context.createElement( parsed[ 1 ] ) ]; |
f986e111b
|
52 |
} |
87c93a029
|
53 |
parsed = buildFragment( [ data ], context, scripts ); |
f986e111b
|
54 55 56 57 58 59 60 61 62 |
if ( scripts && scripts.length ) { jQuery( scripts ).remove(); } return jQuery.merge( [], parsed.childNodes ); }; return jQuery.parseHTML; |
87c93a029
|
63 |
} ); |