scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | // Initialize a jQuery object |
1 | // Initialize a jQuery object |
|
2 | define( [ |
2 | define([ |
|
3 | "../core", |
3 | "../core", |
|
4 | "../var/document", |
- | ||
5 | "./var/rsingleTag", |
4 | "./var/rsingleTag", |
|
6 | "../traversing/findFilter" |
5 | "../traversing/findFilter" |
|
7 | ], function( jQuery, document, rsingleTag ) { |
6 | ], function( jQuery, rsingleTag ) { |
|
8 | |
- | ||
9 | "use strict"; |
- | ||
Line 10... | Line 7... | |||
10 | |
7 | |
|
11 | // A central reference to the root jQuery(document) |
8 | // A central reference to the root jQuery(document) |
|
Line 12... | Line 9... | |||
12 | var rootjQuery, |
9 | var rootjQuery, |
|
13 | |
10 | |
|
14 | // A simple way to check for HTML strings |
11 | // A simple way to check for HTML strings |
|
15 | // Prioritize #id over <tag> to avoid XSS via location.hash (#9521) |
- | ||
16 | // Strict HTML recognition (#11290: must start with <) |
12 | // Prioritize #id over <tag> to avoid XSS via location.hash (#9521) |
|
Line 17... | Line 13... | |||
17 | // Shortcut simple #id case for speed |
13 | // Strict HTML recognition (#11290: must start with <) |
|
18 | rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,[\w\W]+> |
14 | rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,[\w\W]+> |
|
Line 19... | Line 15... | |||
19 | |
15 | |
|
20 | <[\w\W]+> init = jQuery.fn.init = function( selector, context, root ) {[\w\W]+> |
16 | <[\w\W]+> init = jQuery.fn.init = function( selector, context ) {[\w\W]+> |
|
21 | <[\w\W]+> var match, elem;[\w\W]+> |
17 | <[\w\W]+> var match, elem;[\w\W]+> |
|
22 | |
18 | |
|
Line 23... | Line -... | |||
23 | <[\w\W]+> // HANDLE: $(""), $(null), $(undefined), $(false)[\w\W]+> |
- | ||
24 | <[\w\W]+> if ( !selector ) {[\w\W]+> |
- | ||
25 | <[\w\W]+> return this;[\w\W]+> |
- | ||
26 | <[\w\W]+> }[\w\W]+> |
- | ||
27 | |
19 | <[\w\W]+> // HANDLE: $(""), $(null), $(undefined), $(false)[\w\W]+> |
|
28 | <[\w\W]+> // Method init() accepts an alternate rootjQuery[\w\W]+> |
20 | <[\w\W]+> if ( !selector ) {[\w\W]+> |
|
29 | <[\w\W]+> // so migrate can support jQuery.sub (gh-2101)[\w\W]+> |
- | ||
30 | <[\w\W]+> root = root || rootjQuery;[\w\W]+> |
21 | <[\w\W]+> return this;[\w\W]+> |
|
31 | |
- | ||
32 | <[\w\W]+> // Handle HTML strings[\w\W]+> |
- | ||
33 | <[\w\W]+> if ( typeof selector === "string" ) {[\w\W]+> |
22 | <[\w\W]+> }[\w\W]+> |
|
34 | <[\w\W]+> if ( selector[ 0 ] === "<" &&[\w\W]+> |
23 | |
|
Line 35... | Line 24... | |||
35 | <[\w\W]+> selector[ selector.length - 1 ] === ">" &&[\w\W]+> |
24 | <[\w\W]+> // Handle HTML strings[\w\W]+> |
|
36 | <[\w\W]+> selector.length >= 3 ) {[\w\W]+> |
25 | <[\w\W]+> if ( typeof selector === "string" ) {[\w\W]+> |
|
37 | |
26 | <[\w\W]+> if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {[\w\W]+> |
|
Line 38... | Line 27... | |||
38 | <[\w\W]+> // Assume that strings that start and end with <> are HTML and skip the regex check[\w\W]+> |
27 | <[\w\W]+> // Assume that strings that start and end with <> are HTML and skip the regex check[\w\W]+> |
|
39 | <[\w\W]+> match = [ null, selector, null ];[\w\W]+> |
28 | <[\w\W]+> match = [ null, selector, null ];[\w\W]+> |
|
Line 40... | Line 29... | |||
40 | |
29 | |
|
41 | <[\w\W]+> } else {[\w\W]+> |
30 | <[\w\W]+> } else {[\w\W]+> |
|
42 | <[\w\W]+> match = rquickExpr.exec( selector );[\w\W]+> |
31 | <[\w\W]+> match = rquickExpr.exec( selector );[\w\W]+> |
|
Line 43... | Line 32... | |||
43 | <[\w\W]+> }[\w\W]+> |
32 | <[\w\W]+> }[\w\W]+> |
|
44 | |
33 | |
|
45 | <[\w\W]+> // Match html or make sure no context is specified for #id[\w\W]+> |
34 | <[\w\W]+> // Match html or make sure no context is specified for #id[\w\W]+> |
|
46 | <[\w\W]+> if ( match && ( match[ 1 ] || !context ) ) {[\w\W]+> |
35 | <[\w\W]+> if ( match && (match[1] || !context) ) {[\w\W]+> |
|
47 | |
36 | |
|
48 | <[\w\W]+> // HANDLE: $(html) -> $(array)[\w\W]+> |
37 | <[\w\W]+> // HANDLE: $(html) -> $(array)[\w\W]+> |
|
49 | <[\w\W]+> if ( match[ 1 ] ) {[\w\W]+> |
38 | <[\w\W]+> if ( match[1] ) {[\w\W]+> |
|
Line 50... | Line 39... | |||
50 | <[\w\W]+> context = context instanceof jQuery ? context[ 0 ] : context;[\w\W]+> |
39 | <[\w\W]+> context = context instanceof jQuery ? context[0] : context;[\w\W]+> |
|
51 | |
40 | |
|
52 | <[\w\W]+> // Option to run scripts is true for back-compat[\w\W]+> |
41 | <[\w\W]+> // Option to run scripts is true for back-compat[\w\W]+> |
|
53 | <[\w\W]+> // Intentionally let the error be thrown if parseHTML is not present[\w\W]+> |
- | ||
54 | <[\w\W]+> jQuery.merge( this, jQuery.parseHTML([\w\W]+> |
42 | <[\w\W]+> // Intentionally let the error be thrown if parseHTML is not present[\w\W]+> |
|
55 | <[\w\W]+> match[ 1 ],[\w\W]+> |
43 | <[\w\W]+> jQuery.merge( this, jQuery.parseHTML([\w\W]+> |
|
56 | <[\w\W]+> context && context.nodeType ? context.ownerDocument || context : document,[\w\W]+> |
44 | <[\w\W]+> match[1],[\w\W]+> |
|
Line 57... | Line 45... | |||
57 | <[\w\W]+> true[\w\W]+> |
45 | <[\w\W]+> context && context.nodeType ? context.ownerDocument || context : document,[\w\W]+> |
|
Line 74... | Line 62... | |||
74 | |
62 | |
|
Line 75... | Line 63... | |||
75 | <[\w\W]+> return this;[\w\W]+> |
63 | <[\w\W]+> return this;[\w\W]+> |
|
76 | |
64 | |
|
77 | <[\w\W]+> // HANDLE: $(#id)[\w\W]+> |
65 | <[\w\W]+> // HANDLE: $(#id)[\w\W]+> |
|
78 | <[\w\W]+> } else {[\w\W]+> |
- | ||
79 | <[\w\W]+> elem = document.getElementById( match[ 2 ] );[\w\W]+> |
- | ||
Line -... | Line 66... | |||
- | 66 | <[\w\W]+> } else {[\w\W]+> |
||
- | 67 | <[\w\W]+> elem = document.getElementById( match[2] );[\w\W]+> |
||
- | 68 | |
||
80 | |
69 | <[\w\W]+> // Support: Blackberry 4.6[\w\W]+> |
|
81 | <[\w\W]+> if ( elem ) {[\w\W]+> |
- | ||
82 | |
70 | <[\w\W]+> // gEBID returns nodes no longer in the document (#6963)[\w\W]+> |
|
- | 71 | <[\w\W]+> if ( elem && elem.parentNode ) {[\w\W]+> |
||
83 | <[\w\W]+> // Inject the element directly into the jQuery object[\w\W]+> |
72 | <[\w\W]+> // Inject the element directly into the jQuery object[\w\W]+> |
|
- | 73 | <[\w\W]+> this.length = 1;[\w\W]+> |
||
- | 74 | <[\w\W]+> this[0] = elem;[\w\W]+> |
||
- | 75 | <[\w\W]+> }[\w\W]+> |
||
84 | <[\w\W]+> this[ 0 ] = elem;[\w\W]+> |
76 | |
|
85 | <[\w\W]+> this.length = 1;[\w\W]+> |
77 | <[\w\W]+> this.context = document;[\w\W]+> |
|
Line 86... | Line 78... | |||
86 | <[\w\W]+> }[\w\W]+> |
78 | <[\w\W]+> this.selector = selector;[\w\W]+> |
|
87 | <[\w\W]+> return this;[\w\W]+> |
79 | <[\w\W]+> return this;[\w\W]+> |
|
88 | <[\w\W]+> }[\w\W]+> |
80 | <[\w\W]+> }[\w\W]+> |
|
Line 89... | Line 81... | |||
89 | |
81 | |
|
90 | <[\w\W]+> // HANDLE: $(expr, $(...))[\w\W]+> |
82 | <[\w\W]+> // HANDLE: $(expr, $(...))[\w\W]+> |
|
91 | <[\w\W]+> } else if ( !context || context.jquery ) {[\w\W]+> |
83 | <[\w\W]+> } else if ( !context || context.jquery ) {[\w\W]+> |
|
92 | <[\w\W]+> return ( context || root ).find( selector );[\w\W]+> |
84 | <[\w\W]+> return ( context || rootjQuery ).find( selector );[\w\W]+> |
|
93 | |
85 | |
|
Line 94... | Line 86... | |||
94 | <[\w\W]+> // HANDLE: $(expr, context)[\w\W]+> |
86 | <[\w\W]+> // HANDLE: $(expr, context)[\w\W]+> |
|
95 | <[\w\W]+> // (which is just equivalent to: $(context).find(expr)[\w\W]+> |
87 | <[\w\W]+> // (which is just equivalent to: $(context).find(expr)[\w\W]+> |
|
96 | <[\w\W]+> } else {[\w\W]+> |
88 | <[\w\W]+> } else {[\w\W]+> |
|
97 | <[\w\W]+> return this.constructor( context ).find( selector );[\w\W]+> |
89 | <[\w\W]+> return this.constructor( context ).find( selector );[\w\W]+> |
|
98 | <[\w\W]+> }[\w\W]+> |
90 | <[\w\W]+> }[\w\W]+> |
|
Line 99... | Line 91... | |||
99 | |
91 | |
|
100 | <[\w\W]+> // HANDLE: $(DOMElement)[\w\W]+> |
92 | <[\w\W]+> // HANDLE: $(DOMElement)[\w\W]+> |
|
101 | <[\w\W]+> } else if ( selector.nodeType ) {[\w\W]+> |
93 | <[\w\W]+> } else if ( selector.nodeType ) {[\w\W]+> |
|
102 | <[\w\W]+> this[ 0 ] = selector;[\w\W]+> |
94 | <[\w\W]+> this.context = this[0] = selector;[\w\W]+> |
|
103 | <[\w\W]+> this.length = 1;[\w\W]+> |
95 | <[\w\W]+> this.length = 1;[\w\W]+> |
|
104 | <[\w\W]+> return this;[\w\W]+> |
- | ||
105 | |
96 | <[\w\W]+> return this;[\w\W]+> |
|
106 | <[\w\W]+> // HANDLE: $(function)[\w\W]+> |
97 | |
|
107 | <[\w\W]+> // Shortcut for document ready[\w\W]+> |
98 | <[\w\W]+> // HANDLE: $(function)[\w\W]+> |
|
Line -... | Line 99... | |||
- | 99 | <[\w\W]+> // Shortcut for document ready[\w\W]+> |
||
- | 100 | <[\w\W]+> } else if ( jQuery.isFunction( selector ) ) {[\w\W]+> |
||
- | 101 | <[\w\W]+> return typeof rootjQuery.ready !== "undefined" ?[\w\W]+> |
||
- | 102 | <[\w\W]+> rootjQuery.ready( selector ) :[\w\W]+> |
||
- | 103 | <[\w\W]+> // Execute immediately if ready is not present[\w\W]+> |
||
108 | <[\w\W]+> } else if ( jQuery.isFunction( selector ) ) {[\w\W]+> |
104 | <[\w\W]+> selector( jQuery );[\w\W]+> |
|
109 | <[\w\W]+> return root.ready !== undefined ?[\w\W]+> |
105 | <[\w\W]+> }[\w\W]+> |
|
Line 110... | Line 106... | |||
110 | <[\w\W]+> root.ready( selector ) :[\w\W]+> |
106 | |
|
111 | |
107 | <[\w\W]+> if ( selector.selector !== undefined ) {[\w\W]+> |
|
Line 122... | Line 118... | |||
122 | <[\w\W]+>// Initialize central reference[\w\W]+> |
118 | <[\w\W]+>// Initialize central reference[\w\W]+> |
|
123 | <[\w\W]+>rootjQuery = jQuery( document );[\w\W]+> |
119 | <[\w\W]+>rootjQuery = jQuery( document );[\w\W]+> |
|
Line 124... | Line 120... | |||
124 | |
120 | |
|
Line 125... | Line 121... | |||
125 | <[\w\W]+>return init;[\w\W]+> |
121 | <[\w\W]+>return init;[\w\W]+> |