scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
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 ) { |
||
Line 6... | Line -... | |||
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; |
|
- | 17 | } |
||
Line 24... | Line -... | |||
24 | } |
- | ||
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 | } |
18 | context = context || document; |
|
45 | |
19 | |
|
Line 46... | Line 20... | |||
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 |
|
Line 50... | Line 24... | |||
50 | if ( parsed ) { |
24 | if ( parsed ) { |
|
Line 51... | Line 25... | |||
51 | return [ context.createElement( parsed[ 1 ] ) ]; |
25 | return [ context.createElement( parsed[1] ) ]; |
|
52 | } |
26 | } |
|
53 | |
27 | |