aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-09-09 19:13:01 -0500
committerTimmy Willison <timmywillisn@gmail.com>2013-09-09 22:51:11 -0500
commit2f627494f28c08e5bba3c32d6c9d9167503322fc (patch)
treef05e01ccebcf4d8c9db7475083d1d99359cc0402 /src/core
parent6c573391121c61b6e3797005c0fa932ae94ef4d1 (diff)
downloadjquery-2f627494f28c08e5bba3c32d6c9d9167503322fc.tar.gz
jquery-2f627494f28c08e5bba3c32d6c9d9167503322fc.zip
Separate jQuery.fn.init into its own module (for lighter core dependencies across all modules). Restore proper support property for effects.
Conflicts: src/attributes/classes.js src/core.js src/manipulation.js src/traversing.js
Diffstat (limited to 'src/core')
-rw-r--r--src/core/init.js132
-rw-r--r--src/core/parseHTML.js2
-rw-r--r--src/core/ready.js1
-rw-r--r--src/core/var/rsingleTag.js4
4 files changed, 138 insertions, 1 deletions
diff --git a/src/core/init.js b/src/core/init.js
new file mode 100644
index 000000000..f2db547a9
--- /dev/null
+++ b/src/core/init.js
@@ -0,0 +1,132 @@
+// Initialize a jQuery object
+define([
+ "../core",
+ "./var/rsingleTag",
+ "../traversing/findFilter"
+], function( jQuery, rsingleTag ) {
+
+// A central reference to the root jQuery(document)
+var rootjQuery,
+
+ // Use the correct document accordingly with window argument (sandbox)
+ document = window.document,
+
+ // 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 ) {
+ // Handle the case where IE and Opera return items
+ // by name instead of ID
+ if ( elem.id !== match[2] ) {
+ return rootjQuery.find( selector );
+ }
+
+ // Otherwise, we 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;
+
+});
diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js
index 15e3e512f..64cf2a18a 100644
--- a/src/core/parseHTML.js
+++ b/src/core/parseHTML.js
@@ -1,6 +1,6 @@
define([
"../core",
- "../var/rsingleTag",
+ "./var/rsingleTag",
"../manipulation" // buildFragment
], function( jQuery, rsingleTag ) {
diff --git a/src/core/ready.js b/src/core/ready.js
index 8e01c260d..87be24155 100644
--- a/src/core/ready.js
+++ b/src/core/ready.js
@@ -1,5 +1,6 @@
define([
"../core",
+ "../core/init",
"../deferred"
], function( jQuery ) {
diff --git a/src/core/var/rsingleTag.js b/src/core/var/rsingleTag.js
new file mode 100644
index 000000000..7e7090b77
--- /dev/null
+++ b/src/core/var/rsingleTag.js
@@ -0,0 +1,4 @@
+define(function() {
+ // Match a standalone tag
+ return (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
+});