nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / core / init.js
1 // Initialize a jQuery object
2 define( [
3         "../core",
4         "../var/document",
5         "./var/rsingleTag",
6         "../traversing/findFilter"
7 ], function( jQuery, document, rsingleTag ) {
8
9 // A central reference to the root jQuery(document)
10 var rootjQuery,
11
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-]*))$/,
16
17         init = jQuery.fn.init = function( selector, context, root ) {
18                 var match, elem;
19
20                 // HANDLE: $(""), $(null), $(undefined), $(false)
21                 if ( !selector ) {
22                         return this;
23                 }
24
25                 // Method init() accepts an alternate rootjQuery
26                 // so migrate can support jQuery.sub (gh-2101)
27                 root = root || rootjQuery;
28
29                 // Handle HTML strings
30                 if ( typeof selector === "string" ) {
31                         if ( selector[ 0 ] === "<" &&
32                                 selector[ selector.length - 1 ] === ">" &&
33                                 selector.length >= 3 ) {
34
35                                 // Assume that strings that start and end with <> are HTML and skip the regex check
36                                 match = [ null, selector, null ];
37
38                         } else {
39                                 match = rquickExpr.exec( selector );
40                         }
41
42                         // Match html or make sure no context is specified for #id
43                         if ( match && ( match[ 1 ] || !context ) ) {
44
45                                 // HANDLE: $(html) -> $(array)
46                                 if ( match[ 1 ] ) {
47                                         context = context instanceof jQuery ? context[ 0 ] : context;
48
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(
52                                                 match[ 1 ],
53                                                 context && context.nodeType ? context.ownerDocument || context : document,
54                                                 true
55                                         ) );
56
57                                         // HANDLE: $(html, props)
58                                         if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
59                                                 for ( match in context ) {
60
61                                                         // Properties of context are called as methods if possible
62                                                         if ( jQuery.isFunction( this[ match ] ) ) {
63                                                                 this[ match ]( context[ match ] );
64
65                                                         // ...and otherwise set as attributes
66                                                         } else {
67                                                                 this.attr( match, context[ match ] );
68                                                         }
69                                                 }
70                                         }
71
72                                         return this;
73
74                                 // HANDLE: $(#id)
75                                 } else {
76                                         elem = document.getElementById( match[ 2 ] );
77
78                                         // Support: Blackberry 4.6
79                                         // gEBID returns nodes no longer in the document (#6963)
80                                         if ( elem && elem.parentNode ) {
81
82                                                 // Inject the element directly into the jQuery object
83                                                 this.length = 1;
84                                                 this[ 0 ] = elem;
85                                         }
86
87                                         this.context = document;
88                                         this.selector = selector;
89                                         return this;
90                                 }
91
92                         // HANDLE: $(expr, $(...))
93                         } else if ( !context || context.jquery ) {
94                                 return ( context || root ).find( selector );
95
96                         // HANDLE: $(expr, context)
97                         // (which is just equivalent to: $(context).find(expr)
98                         } else {
99                                 return this.constructor( context ).find( selector );
100                         }
101
102                 // HANDLE: $(DOMElement)
103                 } else if ( selector.nodeType ) {
104                         this.context = this[ 0 ] = selector;
105                         this.length = 1;
106                         return this;
107
108                 // HANDLE: $(function)
109                 // Shortcut for document ready
110                 } else if ( jQuery.isFunction( selector ) ) {
111                         return root.ready !== undefined ?
112                                 root.ready( selector ) :
113
114                                 // Execute immediately if ready is not present
115                                 selector( jQuery );
116                 }
117
118                 if ( selector.selector !== undefined ) {
119                         this.selector = selector.selector;
120                         this.context = selector.context;
121                 }
122
123                 return jQuery.makeArray( selector, this );
124         };
125
126 // Give the init function the jQuery prototype for later instantiation
127 init.prototype = jQuery.fn;
128
129 // Initialize central reference
130 rootjQuery = jQuery( document );
131
132 return init;
133
134 } );