1 // Initialize a jQuery object
8 "../traversing/findFilter"
9 ], function( jQuery, document, isFunction, rsingleTag ) {
13 // A central reference to the root jQuery(document)
16 // A simple way to check for HTML strings
17 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
18 // Strict HTML recognition (#11290: must start with <)
19 // Shortcut simple #id case for speed
20 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
22 init = jQuery.fn.init = function( selector, context, root ) {
25 // HANDLE: $(""), $(null), $(undefined), $(false)
30 // Method init() accepts an alternate rootjQuery
31 // so migrate can support jQuery.sub (gh-2101)
32 root = root || rootjQuery;
34 // Handle HTML strings
35 if ( typeof selector === "string" ) {
36 if ( selector[ 0 ] === "<" &&
37 selector[ selector.length - 1 ] === ">" &&
38 selector.length >= 3 ) {
40 // Assume that strings that start and end with <> are HTML and skip the regex check
41 match = [ null, selector, null ];
44 match = rquickExpr.exec( selector );
47 // Match html or make sure no context is specified for #id
48 if ( match && ( match[ 1 ] || !context ) ) {
50 // HANDLE: $(html) -> $(array)
52 context = context instanceof jQuery ? context[ 0 ] : context;
54 // Option to run scripts is true for back-compat
55 // Intentionally let the error be thrown if parseHTML is not present
56 jQuery.merge( this, jQuery.parseHTML(
58 context && context.nodeType ? context.ownerDocument || context : document,
62 // HANDLE: $(html, props)
63 if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
64 for ( match in context ) {
66 // Properties of context are called as methods if possible
67 if ( isFunction( this[ match ] ) ) {
68 this[ match ]( context[ match ] );
70 // ...and otherwise set as attributes
72 this.attr( match, context[ match ] );
81 elem = document.getElementById( match[ 2 ] );
85 // Inject the element directly into the jQuery object
92 // HANDLE: $(expr, $(...))
93 } else if ( !context || context.jquery ) {
94 return ( context || root ).find( selector );
96 // HANDLE: $(expr, context)
97 // (which is just equivalent to: $(context).find(expr)
99 return this.constructor( context ).find( selector );
102 // HANDLE: $(DOMElement)
103 } else if ( selector.nodeType ) {
104 this[ 0 ] = selector;
108 // HANDLE: $(function)
109 // Shortcut for document ready
110 } else if ( isFunction( selector ) ) {
111 return root.ready !== undefined ?
112 root.ready( selector ) :
114 // Execute immediately if ready is not present
118 return jQuery.makeArray( selector, this );
121 // Give the init function the jQuery prototype for later instantiation
122 init.prototype = jQuery.fn;
124 // Initialize central reference
125 rootjQuery = jQuery( document );