Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Separate jQuery.fn.init into its own module (for lighter core depende…
…ncies across all modules)
- Loading branch information
Showing
18 changed files
with
250 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
define([ | ||
"../core", | ||
"./support" | ||
"./support", | ||
"../core/init" | ||
], function( jQuery, support ) { | ||
|
||
var rreturn = /\r/g; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Initialize a jQuery object | ||
define([ | ||
"../core", | ||
"./var/rsingleTag", | ||
"../traversing/findFilter" | ||
], function( jQuery, rsingleTag ) { | ||
|
||
// A central reference to the root jQuery(document) | ||
var rootjQuery, | ||
|
||
// 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 <) | ||
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, | ||
|
||
init = jQuery.fn.init = function( selector, context ) { | ||
var match, elem; | ||
|
||
// HANDLE: $(""), $(null), $(undefined), $(false) | ||
if ( !selector ) { | ||
return this; | ||
} | ||
|
||
// Handle HTML strings | ||
if ( typeof selector === "string" ) { | ||
if ( selector.charAt(0) === "<" && selector.charAt( 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 ]; | ||
|
||
} else { | ||
match = rquickExpr.exec( selector ); | ||
} | ||
|
||
// Match html or make sure no context is specified for #id | ||
if ( match && (match[1] || !context) ) { | ||
|
||
// HANDLE: $(html) -> $(array) | ||
if ( match[1] ) { | ||
context = context instanceof jQuery ? context[0] : context; | ||
|
||
// scripts is true for back-compat | ||
// Intentionally let the error be thrown if parseHTML is not present | ||
jQuery.merge( this, jQuery.parseHTML( | ||
match[1], | ||
context && context.nodeType ? context.ownerDocument || context : document, | ||
true | ||
) ); | ||
|
||
// HANDLE: $(html, props) | ||
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 ] ); | ||
|
||
// ...and otherwise set as attributes | ||
} else { | ||
this.attr( match, context[ match ] ); | ||
} | ||
} | ||
} | ||
|
||
return this; | ||
|
||
// HANDLE: $(#id) | ||
} else { | ||
elem = document.getElementById( match[2] ); | ||
|
||
// Check parentNode to catch when Blackberry 4.6 returns | ||
// nodes that are no longer in the document #6963 | ||
if ( elem && elem.parentNode ) { | ||
// Inject the element directly into the jQuery object | ||
this.length = 1; | ||
this[0] = elem; | ||
} | ||
|
||
this.context = document; | ||
this.selector = selector; | ||
return this; | ||
} | ||
|
||
// HANDLE: $(expr, $(...)) | ||
} else if ( !context || context.jquery ) { | ||
return ( context || rootjQuery ).find( selector ); | ||
|
||
// HANDLE: $(expr, context) | ||
// (which is just equivalent to: $(context).find(expr) | ||
} else { | ||
return this.constructor( context ).find( selector ); | ||
} | ||
|
||
// HANDLE: $(DOMElement) | ||
} else if ( selector.nodeType ) { | ||
this.context = this[0] = selector; | ||
this.length = 1; | ||
return this; | ||
|
||
// HANDLE: $(function) | ||
// Shortcut for document ready | ||
} else if ( jQuery.isFunction( 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 ); | ||
}; | ||
|
||
// Give the init function the jQuery prototype for later instantiation | ||
init.prototype = jQuery.fn; | ||
|
||
// Initialize central reference | ||
rootjQuery = jQuery( document ); | ||
|
||
return init; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
define([ | ||
"../core", | ||
"../core/init", | ||
"../deferred" | ||
], function( jQuery ) { | ||
|
||
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.