1 // Initialize a jQuery object
7 "../traversing/findFilter"
8 ], function( jQuery, document, rsingleTag ) {
12 // A central reference to the root jQuery(document)
15 // A simple way to check for HTML strings
16 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
17 // Strict HTML recognition (#11290: must start with <)
18 // Shortcut simple #id case for speed
19 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
21 init = jQuery.fn.init = function( selector, context, root ) {
24 // HANDLE: $(""), $(null), $(undefined), $(false)
29 // Method init() accepts an alternate rootjQuery
30 // so migrate can support jQuery.sub (gh-2101)
31 root = root || rootjQuery;
33 // Handle HTML strings
34 if ( typeof selector === "string" ) {
35 if ( selector[ 0 ] === "<" &&
36 selector[ selector.length - 1 ] === ">" &&
37 selector.length >= 3 ) {
39 // Assume that strings that start and end with <> are HTML and skip the regex check
40 match = [ null, selector, null ];
43 match = rquickExpr.exec( selector );
46 // Match html or make sure no context is specified for #id
47 if ( match && ( match[ 1 ] || !context ) ) {
49 // HANDLE: $(html) -> $(array)
51 context = context instanceof jQuery ? context[ 0 ] : context;
53 // Option to run scripts is true for back-compat
54 // Intentionally let the error be thrown if parseHTML is not present
55 jQuery.merge( this, jQuery.parseHTML(
57 context && context.nodeType ? context.ownerDocument || context : document,
61 // HANDLE: $(html, props)
62 if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
63 for ( match in context ) {
65 // Properties of context are called as methods if possible
66 if ( jQuery.isFunction( this[ match ] ) ) {
67 this[ match ]( context[ match ] );
69 // ...and otherwise set as attributes
71 this.attr( match, context[ match ] );
80 elem = document.getElementById( match[ 2 ] );
84 // Inject the element directly into the jQuery object
91 // HANDLE: $(expr, $(...))
92 } else if ( !context || context.jquery ) {
93 return ( context || root ).find( selector );
95 // HANDLE: $(expr, context)
96 // (which is just equivalent to: $(context).find(expr)
98 return this.constructor( context ).find( selector );
101 // HANDLE: $(DOMElement)
102 } else if ( selector.nodeType ) {
103 this[ 0 ] = selector;
107 // HANDLE: $(function)
108 // Shortcut for document ready
109 } else if ( jQuery.isFunction( selector ) ) {
110 return root.ready !== undefined ?
111 root.ready( selector ) :
113 // Execute immediately if ready is not present
117 return jQuery.makeArray( selector, this );
120 // Give the init function the jQuery prototype for later instantiation
121 init.prototype = jQuery.fn;
123 // Initialize central reference
124 rootjQuery = jQuery( document );