aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrandon Aaron <brandon.aaron@gmail.com>2007-05-01 21:03:44 +0000
committerBrandon Aaron <brandon.aaron@gmail.com>2007-05-01 21:03:44 +0000
commit67c640bb206d0c8b16042c0981fb25540ee47bdf (patch)
treec70b0203c1a836eeb7f21623e67625e389554b78 /src
parent13d2ef9282db6be4a0030ce1319948410f0bd2b6 (diff)
downloadjquery-67c640bb206d0c8b16042c0981fb25540ee47bdf.tar.gz
jquery-67c640bb206d0c8b16042c0981fb25540ee47bdf.zip
Moving constructor code to jQuery.prototype.init for more flexibility
Diffstat (limited to 'src')
-rw-r--r--src/jquery/jquery.js77
1 files changed, 47 insertions, 30 deletions
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index c22c12c61..76ef152a2 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -26,37 +26,8 @@ var jQuery = function(a,c) {
// If the context is global, return a new object
if ( window == this )
return new jQuery(a,c);
-
- // Make sure that a selection was provided
- a = a || document;
-
- // HANDLE: $(function)
- // Shortcut for document ready
- if ( jQuery.isFunction(a) )
- return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
-
- // Handle HTML strings
- if ( typeof a == "string" ) {
- // HANDLE: $(html) -> $(array)
- var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
- if ( m )
- a = jQuery.clean( [ m[1] ] );
-
- // HANDLE: $(expr)
- else
- return new jQuery( c ).find( a );
- }
- return this.setArray(
- // HANDLE: $(array)
- a.constructor == Array && a ||
-
- // HANDLE: $(arraylike)
- // Watch for when an array-like object is passed as the selector
- (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
-
- // HANDLE: $(*)
- [ a ] );
+ return this.init(a,c);
};
// Map over the $ in case of overwrite
@@ -170,6 +141,52 @@ var $ = jQuery;
jQuery.fn = jQuery.prototype = {
/**
+ * Initialize a new jQuery object
+ *
+ * @private
+ * @name init
+ * @param String|Function|Element|Array<Element>|jQuery a selector
+ * @param jQuery|Element|Array<Element> c context
+ * @cat Core
+ */
+ init: function(a,c) {
+ // Make sure that a selection was provided
+ a = a || document;
+
+ // HANDLE: $(function)
+ // Shortcut for document ready
+ if ( jQuery.isFunction(a) )
+ return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
+
+ // Handle HTML strings
+ if ( typeof a == "string" ) {
+ // HANDLE: $(html) -> $(array)
+ var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
+ if ( m )
+ a = jQuery.clean( [ m[1] ] );
+
+ // HANDLE: $(expr)
+ else {
+ var r = new jQuery( c ).find( a );
+ r.selector = a;
+ r.context = c;
+ return r;
+ }
+ }
+
+ return this.setArray(
+ // HANDLE: $(array)
+ a.constructor == Array && a ||
+
+ // HANDLE: $(arraylike)
+ // Watch for when an array-like object is passed as the selector
+ (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
+
+ // HANDLE: $(*)
+ [ a ] );
+ },
+
+ /**
* The current version of jQuery.
*
* @private