1 // Initialize a jQuery object
6 "../traversing/findFilter"
7 ], function( jQuery, document, rsingleTag ) {
9 // A central reference to the root jQuery(document)
12 // A simple way to check for HTML strings
13 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
14 // Strict HTML recognition (#11290: must start with <)
15 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
17 init = jQuery.fn.init = function( selector, context, root ) {
20 // HANDLE: $(""), $(null), $(undefined), $(false)
25 // Method init() accepts an alternate rootjQuery
26 // so migrate can support jQuery.sub (gh-2101)
27 root = root || rootjQuery;
29 // Handle HTML strings
30 if ( typeof selector === "string" ) {
31 if ( selector[ 0 ] === "<" &&
32 selector[ selector.length - 1 ] === ">" &&
33 selector.length >= 3 ) {
35 // Assume that strings that start and end with <> are HTML and skip the regex check
36 match = [ null, selector, null ];
39 match = rquickExpr.exec( selector );
42 // Match html or make sure no context is specified for #id
43 if ( match && ( match[ 1 ] || !context ) ) {
45 // HANDLE: $(html) -> $(array)
47 context = context instanceof jQuery ? context[ 0 ] : context;
49 // Option to run scripts is true for back-compat
50 // Intentionally let the error be thrown if parseHTML is not present
51 jQuery.merge( this, jQuery.parseHTML(
53 context && context.nodeType ? context.ownerDocument || context : document,
57 // HANDLE: $(html, props)
58 if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
59 for ( match in context ) {
61 // Properties of context are called as methods if possible
62 if ( jQuery.isFunction( this[ match ] ) ) {
63 this[ match ]( context[ match ] );
65 // ...and otherwise set as attributes
67 this.attr( match, context[ match ] );
76 elem = document.getElementById( match[ 2 ] );
78 // Support: Blackberry 4.6
79 // gEBID returns nodes no longer in the document (#6963)
80 if ( elem && elem.parentNode ) {
82 // Inject the element directly into the jQuery object
87 this.context = document;
88 this.selector = selector;
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.context = this[ 0 ] = selector;
108 // HANDLE: $(function)
109 // Shortcut for document ready
110 } else if ( jQuery.isFunction( selector ) ) {
111 return root.ready !== undefined ?
112 root.ready( selector ) :
114 // Execute immediately if ready is not present
118 if ( selector.selector !== undefined ) {
119 this.selector = selector.selector;
120 this.context = selector.context;
123 return jQuery.makeArray( selector, this );
126 // Give the init function the jQuery prototype for later instantiation
127 init.prototype = jQuery.fn;
129 // Initialize central reference
130 rootjQuery = jQuery( document );