1 // Initialize a jQuery object
5 "../traversing/findFilter"
6 ], function( jQuery, rsingleTag ) {
8 // A central reference to the root jQuery(document)
11 // A simple way to check for HTML strings
12 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
13 // Strict HTML recognition (#11290: must start with <)
14 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
16 init = jQuery.fn.init = function( selector, context ) {
19 // HANDLE: $(""), $(null), $(undefined), $(false)
24 // Handle HTML strings
25 if ( typeof selector === "string" ) {
26 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
27 // Assume that strings that start and end with <> are HTML and skip the regex check
28 match = [ null, selector, null ];
31 match = rquickExpr.exec( selector );
34 // Match html or make sure no context is specified for #id
35 if ( match && (match[1] || !context) ) {
37 // HANDLE: $(html) -> $(array)
39 context = context instanceof jQuery ? context[0] : context;
41 // Option to run scripts is true for back-compat
42 // Intentionally let the error be thrown if parseHTML is not present
43 jQuery.merge( this, jQuery.parseHTML(
45 context && context.nodeType ? context.ownerDocument || context : document,
49 // HANDLE: $(html, props)
50 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
51 for ( match in context ) {
52 // Properties of context are called as methods if possible
53 if ( jQuery.isFunction( this[ match ] ) ) {
54 this[ match ]( context[ match ] );
56 // ...and otherwise set as attributes
58 this.attr( match, context[ match ] );
67 elem = document.getElementById( match[2] );
69 // Support: Blackberry 4.6
70 // gEBID returns nodes no longer in the document (#6963)
71 if ( elem && elem.parentNode ) {
72 // Inject the element directly into the jQuery object
77 this.context = document;
78 this.selector = selector;
82 // HANDLE: $(expr, $(...))
83 } else if ( !context || context.jquery ) {
84 return ( context || rootjQuery ).find( selector );
86 // HANDLE: $(expr, context)
87 // (which is just equivalent to: $(context).find(expr)
89 return this.constructor( context ).find( selector );
92 // HANDLE: $(DOMElement)
93 } else if ( selector.nodeType ) {
94 this.context = this[0] = selector;
98 // HANDLE: $(function)
99 // Shortcut for document ready
100 } else if ( jQuery.isFunction( selector ) ) {
101 return typeof rootjQuery.ready !== "undefined" ?
102 rootjQuery.ready( selector ) :
103 // Execute immediately if ready is not present
107 if ( selector.selector !== undefined ) {
108 this.selector = selector.selector;
109 this.context = selector.context;
112 return jQuery.makeArray( selector, this );
115 // Give the init function the jQuery prototype for later instantiation
116 init.prototype = jQuery.fn;
118 // Initialize central reference
119 rootjQuery = jQuery( document );