root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / core / init.js @ 0aee3c58
1 |
// Initialize a jQuery object
|
---|---|
2 |
define([ |
3 |
"../core",
|
4 |
"./var/rsingleTag",
|
5 |
"../traversing/findFilter"
|
6 |
], function( jQuery, rsingleTag ) {
|
7 |
|
8 |
// A central reference to the root jQuery(document)
|
9 |
var rootjQuery,
|
10 |
|
11 |
// Use the correct document accordingly with window argument (sandbox)
|
12 |
document = window.document, |
13 |
|
14 |
// 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 <)
|
17 |
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
|
18 |
|
19 |
init = jQuery.fn.init = function( selector, context ) { |
20 |
var match, elem;
|
21 |
|
22 |
// HANDLE: $(""), $(null), $(undefined), $(false)
|
23 |
if ( !selector ) {
|
24 |
return this; |
25 |
} |
26 |
|
27 |
// Handle HTML strings
|
28 |
if ( typeof selector === "string" ) { |
29 |
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { |
30 |
// Assume that strings that start and end with <> are HTML and skip the regex check
|
31 |
match = [ null, selector, null ]; |
32 |
|
33 |
} else {
|
34 |
match = rquickExpr.exec( selector ); |
35 |
} |
36 |
|
37 |
// Match html or make sure no context is specified for #id
|
38 |
if ( match && (match[1] || !context) ) { |
39 |
|
40 |
// HANDLE: $(html) -> $(array)
|
41 |
if ( match[1] ) { |
42 |
context = context instanceof jQuery ? context[0] : context; |
43 |
|
44 |
// scripts is true for back-compat
|
45 |
// Intentionally let the error be thrown if parseHTML is not present
|
46 |
jQuery.merge( this, jQuery.parseHTML(
|
47 |
match[1],
|
48 |
context && context.nodeType ? context.ownerDocument || context : document, |
49 |
true
|
50 |
) ); |
51 |
|
52 |
// HANDLE: $(html, props)
|
53 |
if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { |
54 |
for ( match in context ) { |
55 |
// Properties of context are called as methods if possible
|
56 |
if ( jQuery.isFunction( this[ match ] ) ) { |
57 |
this[ match ]( context[ match ] );
|
58 |
|
59 |
// ...and otherwise set as attributes
|
60 |
} else {
|
61 |
this.attr( match, context[ match ] );
|
62 |
} |
63 |
} |
64 |
} |
65 |
|
66 |
return this; |
67 |
|
68 |
// HANDLE: $(#id)
|
69 |
} else {
|
70 |
elem = document.getElementById( match[2] );
|
71 |
|
72 |
// Check parentNode to catch when Blackberry 4.6 returns
|
73 |
// nodes that are no longer in the document #6963
|
74 |
if ( elem && elem.parentNode ) {
|
75 |
// Handle the case where IE and Opera return items
|
76 |
// by name instead of ID
|
77 |
if ( elem.id !== match[2] ) { |
78 |
return rootjQuery.find( selector );
|
79 |
} |
80 |
|
81 |
// Otherwise, we inject the element directly into the jQuery object
|
82 |
this.length = 1; |
83 |
this[0] = elem; |
84 |
} |
85 |
|
86 |
this.context = document;
|
87 |
this.selector = selector;
|
88 |
return this; |
89 |
} |
90 |
|
91 |
// HANDLE: $(expr, $(...))
|
92 |
} else if ( !context || context.jquery ) { |
93 |
return ( context || rootjQuery ).find( selector );
|
94 |
|
95 |
// HANDLE: $(expr, context)
|
96 |
// (which is just equivalent to: $(context).find(expr)
|
97 |
} else {
|
98 |
return this.constructor( context ).find( selector ); |
99 |
} |
100 |
|
101 |
// HANDLE: $(DOMElement)
|
102 |
} else if ( selector.nodeType ) { |
103 |
this.context = this[0] = selector; |
104 |
this.length = 1; |
105 |
return this; |
106 |
|
107 |
// HANDLE: $(function)
|
108 |
// Shortcut for document ready
|
109 |
} else if ( jQuery.isFunction( selector ) ) { |
110 |
return typeof rootjQuery.ready !== "undefined" ? |
111 |
rootjQuery.ready( selector ) : |
112 |
// Execute immediately if ready is not present
|
113 |
selector( jQuery ); |
114 |
} |
115 |
|
116 |
if ( selector.selector !== undefined ) { |
117 |
this.selector = selector.selector;
|
118 |
this.context = selector.context;
|
119 |
} |
120 |
|
121 |
return jQuery.makeArray( selector, this ); |
122 |
}; |
123 |
|
124 |
// Give the init function the jQuery prototype for later instantiation
|
125 |
init.prototype = jQuery.fn; |
126 |
|
127 |
// Initialize central reference
|
128 |
rootjQuery = jQuery( document ); |
129 |
|
130 |
return init;
|
131 |
|
132 |
}); |