Blame view
app/bower_components/jquery/src/core/init.js
3.24 KB
|
f986e111b
|
1 |
// Initialize a jQuery object |
|
87c93a029
|
2 |
define( [ |
|
f986e111b
|
3 |
"../core", |
|
87c93a029
|
4 |
"../var/document", |
|
f986e111b
|
5 6 |
"./var/rsingleTag", "../traversing/findFilter" |
|
87c93a029
|
7 8 9 |
], function( jQuery, document, rsingleTag ) {
"use strict";
|
|
f986e111b
|
10 11 12 |
// A central reference to the root jQuery(document) var rootjQuery, |
|
f986e111b
|
13 14 15 |
// A simple way to check for HTML strings // Prioritize #id over <tag> to avoid XSS via location.hash (#9521) // Strict HTML recognition (#11290: must start with <) |
|
87c93a029
|
16 17 |
// Shortcut simple #id case for speed rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/, |
|
f986e111b
|
18 |
|
|
87c93a029
|
19 |
init = jQuery.fn.init = function( selector, context, root ) {
|
|
f986e111b
|
20 21 22 23 24 25 |
var match, elem;
// HANDLE: $(""), $(null), $(undefined), $(false)
if ( !selector ) {
return this;
}
|
|
87c93a029
|
26 27 28 |
// Method init() accepts an alternate rootjQuery // so migrate can support jQuery.sub (gh-2101) root = root || rootjQuery; |
|
f986e111b
|
29 30 |
// Handle HTML strings
if ( typeof selector === "string" ) {
|
|
87c93a029
|
31 32 33 |
if ( selector[ 0 ] === "<" &&
selector[ selector.length - 1 ] === ">" &&
selector.length >= 3 ) {
|
|
f986e111b
|
34 35 36 37 38 39 40 41 |
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];
} else {
match = rquickExpr.exec( selector );
}
// Match html or make sure no context is specified for #id
|
|
87c93a029
|
42 |
if ( match && ( match[ 1 ] || !context ) ) {
|
|
f986e111b
|
43 44 |
// HANDLE: $(html) -> $(array) |
|
87c93a029
|
45 46 |
if ( match[ 1 ] ) {
context = context instanceof jQuery ? context[ 0 ] : context;
|
|
f986e111b
|
47 |
|
|
87c93a029
|
48 |
// Option to run scripts is true for back-compat |
|
f986e111b
|
49 50 |
// Intentionally let the error be thrown if parseHTML is not present jQuery.merge( this, jQuery.parseHTML( |
|
87c93a029
|
51 |
match[ 1 ], |
|
f986e111b
|
52 53 54 55 56 |
context && context.nodeType ? context.ownerDocument || context : document, true ) ); // HANDLE: $(html, props) |
|
87c93a029
|
57 |
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
|
|
f986e111b
|
58 |
for ( match in context ) {
|
|
87c93a029
|
59 |
|
|
f986e111b
|
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
// Properties of context are called as methods if possible
if ( jQuery.isFunction( this[ match ] ) ) {
this[ match ]( context[ match ] );
// ...and otherwise set as attributes
} else {
this.attr( match, context[ match ] );
}
}
}
return this;
// HANDLE: $(#id)
} else {
|
|
87c93a029
|
75 |
elem = document.getElementById( match[ 2 ] ); |
|
f986e111b
|
76 |
|
|
87c93a029
|
77 78 79 80 |
if ( elem ) {
// Inject the element directly into the jQuery object
this[ 0 ] = elem;
|
|
f986e111b
|
81 |
this.length = 1; |
|
f986e111b
|
82 |
} |
|
f986e111b
|
83 84 85 86 87 |
return this;
}
// HANDLE: $(expr, $(...))
} else if ( !context || context.jquery ) {
|
|
87c93a029
|
88 |
return ( context || root ).find( selector ); |
|
f986e111b
|
89 90 91 92 93 94 95 96 97 |
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
return this.constructor( context ).find( selector );
}
// HANDLE: $(DOMElement)
} else if ( selector.nodeType ) {
|
|
87c93a029
|
98 |
this[ 0 ] = selector; |
|
f986e111b
|
99 100 101 102 103 104 |
this.length = 1;
return this;
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
|
|
87c93a029
|
105 106 |
return root.ready !== undefined ? root.ready( selector ) : |
|
f986e111b
|
107 108 109 |
// Execute immediately if ready is not present selector( jQuery ); } |
|
f986e111b
|
110 111 112 113 114 115 116 117 118 119 |
return jQuery.makeArray( selector, this ); }; // Give the init function the jQuery prototype for later instantiation init.prototype = jQuery.fn; // Initialize central reference rootjQuery = jQuery( document ); return init; |
|
87c93a029
|
120 |
} ); |