/bower_components/jquery/src/core/init.js |
@@ -1,13 +1,10 @@ |
// Initialize a jQuery object |
define( [ |
define([ |
"../core", |
"../var/document", |
"./var/rsingleTag", |
"../traversing/findFilter" |
], function( jQuery, document, rsingleTag ) { |
], function( jQuery, rsingleTag ) { |
|
"use strict"; |
|
// A central reference to the root jQuery(document) |
var rootjQuery, |
|
@@ -14,10 +11,9 @@ |
// 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 <) |
// Shortcut simple #id case for speed |
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/, |
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, |
|
init = jQuery.fn.init = function( selector, context, root ) { |
init = jQuery.fn.init = function( selector, context ) { |
var match, elem; |
|
// HANDLE: $(""), $(null), $(undefined), $(false) |
@@ -25,16 +21,9 @@ |
return this; |
} |
|
// Method init() accepts an alternate rootjQuery |
// so migrate can support jQuery.sub (gh-2101) |
root = root || rootjQuery; |
|
// Handle HTML strings |
if ( typeof selector === "string" ) { |
if ( selector[ 0 ] === "<" && |
selector[ selector.length - 1 ] === ">" && |
selector.length >= 3 ) { |
|
if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) { |
// Assume that strings that start and end with <> are HTML and skip the regex check |
match = [ null, selector, null ]; |
|
@@ -43,24 +32,23 @@ |
} |
|
// Match html or make sure no context is specified for #id |
if ( match && ( match[ 1 ] || !context ) ) { |
if ( match && (match[1] || !context) ) { |
|
// HANDLE: $(html) -> $(array) |
if ( match[ 1 ] ) { |
context = context instanceof jQuery ? context[ 0 ] : context; |
if ( match[1] ) { |
context = context instanceof jQuery ? context[0] : context; |
|
// Option to run scripts is true for back-compat |
// Intentionally let the error be thrown if parseHTML is not present |
jQuery.merge( this, jQuery.parseHTML( |
match[ 1 ], |
match[1], |
context && context.nodeType ? context.ownerDocument || context : document, |
true |
) ); |
|
// HANDLE: $(html, props) |
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) { |
if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { |
for ( match in context ) { |
|
// Properties of context are called as methods if possible |
if ( jQuery.isFunction( this[ match ] ) ) { |
this[ match ]( context[ match ] ); |
@@ -76,20 +64,24 @@ |
|
// HANDLE: $(#id) |
} else { |
elem = document.getElementById( match[ 2 ] ); |
elem = document.getElementById( match[2] ); |
|
if ( elem ) { |
|
// Support: Blackberry 4.6 |
// gEBID returns nodes no longer in the document (#6963) |
if ( elem && elem.parentNode ) { |
// Inject the element directly into the jQuery object |
this[ 0 ] = elem; |
this.length = 1; |
this[0] = elem; |
} |
|
this.context = document; |
this.selector = selector; |
return this; |
} |
|
// HANDLE: $(expr, $(...)) |
} else if ( !context || context.jquery ) { |
return ( context || root ).find( selector ); |
return ( context || rootjQuery ).find( selector ); |
|
// HANDLE: $(expr, context) |
// (which is just equivalent to: $(context).find(expr) |
@@ -99,7 +91,7 @@ |
|
// HANDLE: $(DOMElement) |
} else if ( selector.nodeType ) { |
this[ 0 ] = selector; |
this.context = this[0] = selector; |
this.length = 1; |
return this; |
|
@@ -106,13 +98,17 @@ |
// HANDLE: $(function) |
// Shortcut for document ready |
} else if ( jQuery.isFunction( selector ) ) { |
return root.ready !== undefined ? |
root.ready( selector ) : |
|
return typeof rootjQuery.ready !== "undefined" ? |
rootjQuery.ready( selector ) : |
// Execute immediately if ready is not present |
selector( jQuery ); |
} |
|
if ( selector.selector !== undefined ) { |
this.selector = selector.selector; |
this.context = selector.context; |
} |
|
return jQuery.makeArray( selector, this ); |
}; |
|
@@ -124,4 +120,4 @@ |
|
return init; |
|
} ); |
}); |