Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / assets / lib / jquery / src / core / init.js
1 // Initialize a jQuery object
2 define( [
3         "../core",
4         "../var/document",
5         "./var/rsingleTag",
6
7         "../traversing/findFilter"
8 ], function( jQuery, document, rsingleTag ) {
9
10 "use strict";
11
12 // A central reference to the root jQuery(document)
13 var rootjQuery,
14
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-]+))$/,
20
21         init = jQuery.fn.init = function( selector, context, root ) {
22                 var match, elem;
23
24                 // HANDLE: $(""), $(null), $(undefined), $(false)
25                 if ( !selector ) {
26                         return this;
27                 }
28
29                 // Method init() accepts an alternate rootjQuery
30                 // so migrate can support jQuery.sub (gh-2101)
31                 root = root || rootjQuery;
32
33                 // Handle HTML strings
34                 if ( typeof selector === "string" ) {
35                         if ( selector[ 0 ] === "<" &&
36                                 selector[ selector.length - 1 ] === ">" &&
37                                 selector.length >= 3 ) {
38
39                                 // Assume that strings that start and end with <> are HTML and skip the regex check
40                                 match = [ null, selector, null ];
41
42                         } else {
43                                 match = rquickExpr.exec( selector );
44                         }
45
46                         // Match html or make sure no context is specified for #id
47                         if ( match && ( match[ 1 ] || !context ) ) {
48
49                                 // HANDLE: $(html) -> $(array)
50                                 if ( match[ 1 ] ) {
51                                         context = context instanceof jQuery ? context[ 0 ] : context;
52
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(
56                                                 match[ 1 ],
57                                                 context && context.nodeType ? context.ownerDocument || context : document,
58                                                 true
59                                         ) );
60
61                                         // HANDLE: $(html, props)
62                                         if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
63                                                 for ( match in context ) {
64
65                                                         // Properties of context are called as methods if possible
66                                                         if ( jQuery.isFunction( this[ match ] ) ) {
67                                                                 this[ match ]( context[ match ] );
68
69                                                         // ...and otherwise set as attributes
70                                                         } else {
71                                                                 this.attr( match, context[ match ] );
72                                                         }
73                                                 }
74                                         }
75
76                                         return this;
77
78                                 // HANDLE: $(#id)
79                                 } else {
80                                         elem = document.getElementById( match[ 2 ] );
81
82                                         if ( elem ) {
83
84                                                 // Inject the element directly into the jQuery object
85                                                 this[ 0 ] = elem;
86                                                 this.length = 1;
87                                         }
88                                         return this;
89                                 }
90
91                         // HANDLE: $(expr, $(...))
92                         } else if ( !context || context.jquery ) {
93                                 return ( context || root ).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[ 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 root.ready !== undefined ?
111                                 root.ready( selector ) :
112
113                                 // Execute immediately if ready is not present
114                                 selector( jQuery );
115                 }
116
117                 return jQuery.makeArray( selector, this );
118         };
119
120 // Give the init function the jQuery prototype for later instantiation
121 init.prototype = jQuery.fn;
122
123 // Initialize central reference
124 rootjQuery = jQuery( document );
125
126 return init;
127
128 } );