diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 19:13:01 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 19:13:01 -0500 |
commit | 825ac3773694e0cd23ee74895fd5aeb535b27da4 (patch) | |
tree | b389bf60adbfd0cb06a92f91ca5fc5509f66f197 /src/core.js | |
parent | d788010aa724f58090560e83c224d3d140814b51 (diff) | |
download | jquery-825ac3773694e0cd23ee74895fd5aeb535b27da4.tar.gz jquery-825ac3773694e0cd23ee74895fd5aeb535b27da4.zip |
Separate jQuery.fn.init into its own module (for lighter core dependencies across all modules)
Diffstat (limited to 'src/core.js')
-rw-r--r-- | src/core.js | 117 |
1 files changed, 2 insertions, 115 deletions
diff --git a/src/core.js b/src/core.js index 3cdcc63af..599caba64 100644 --- a/src/core.js +++ b/src/core.js @@ -10,12 +10,8 @@ var toString = require( "./var/toString" ), hasOwn = require( "./var/hasOwn" ), trim = require( "./var/trim" ), - rsingleTag = require( "./var/rsingleTag" ), support = require( "./var/support" ), - // A central reference to the root jQuery(document) - rootjQuery, - // Use the correct document accordingly with window argument (sandbox) document = window.document, @@ -30,14 +26,10 @@ var // Define a local copy of jQuery jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' - return new jQuery.fn.init( selector, context, rootjQuery ); + // Need init if jQuery is called (just allow error to be thrown if not included) + return new jQuery.fn.init( selector, context ); }, - // 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-]*))$/, - // Matches dashed string for camelizing rmsPrefix = /^-ms-/, rdashAlpha = /-([\da-z])/gi, @@ -53,105 +45,6 @@ jQuery.fn = jQuery.prototype = { constructor: jQuery, - init: function( selector, context, rootjQuery ) { - 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 ); - }, - // Start with an empty selector selector: "", @@ -231,9 +124,6 @@ jQuery.fn = jQuery.prototype = { splice: arr.splice }; -// Give the init function the jQuery prototype for later instantiation -jQuery.fn.init.prototype = jQuery.fn; - jQuery.extend = jQuery.fn.extend = function() { var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, @@ -621,8 +511,5 @@ function isArraylike( obj ) { typeof length === "number" && length > 0 && ( length - 1 ) in obj ); } -// All jQuery objects should point back to these -rootjQuery = jQuery( document ); - return jQuery; }); |