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