diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2006-12-12 20:33:10 +0000 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2006-12-12 20:33:10 +0000 |
commit | 6ac46e6a5a6cac509626267865980f4dfbeebc2d (patch) | |
tree | e044a3e3610901340e7328f3a3b101b9305efdd7 /src | |
parent | fb11b33d68f64ea446f2f8c6d3ef2aed3652349f (diff) | |
download | jquery-6ac46e6a5a6cac509626267865980f4dfbeebc2d.tar.gz jquery-6ac46e6a5a6cac509626267865980f4dfbeebc2d.zip |
Got context functions back in, added noteworthy stuff, replaced js linebreak replacer with xstl
Diffstat (limited to 'src')
-rw-r--r-- | src/jquery/jquery.js | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 9e62fe3cb..177d86bf7 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -22,7 +22,7 @@ window.undefined = window.undefined; */
var jQuery = function(a,c) {
- // Shortcut for document ready (because $(document).each() is silly)
+ // Shortcut for document ready
if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
return jQuery(document).ready(a);
@@ -55,6 +55,13 @@ var jQuery = function(a,c) { // Find the matching elements and save them for later
jQuery.find( a, c ) );
+ // See if an extra function was provided
+ var fn = arguments[ arguments.length - 1 ];
+
+ // If so, execute it in context
+ if ( fn && typeof fn == "function" )
+ this.each(fn);
+
return this;
};
@@ -789,7 +796,7 @@ jQuery.fn = jQuery.prototype = { find: function(t) {
return this.pushStack( jQuery.map( this, function(a){
return jQuery.find(t,a);
- }));
+ }), arguments );
},
/**
@@ -810,7 +817,7 @@ jQuery.fn = jQuery.prototype = { clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){
return a.cloneNode( deep != undefined ? deep : true );
- }));
+ }), arguments );
},
/**
@@ -865,7 +872,7 @@ jQuery.fn = jQuery.prototype = { typeof t == "function" &&
jQuery.grep( this, t ) ||
- jQuery.filter(t,this).r );
+ jQuery.filter(t,this).r, arguments );
},
/**
@@ -899,7 +906,7 @@ jQuery.fn = jQuery.prototype = { not: function(t) {
return this.pushStack( typeof t == "string" ?
jQuery.filter(t,this,false).r :
- jQuery.grep(this,function(a){ return a != t; }) );
+ jQuery.grep(this,function(a){ return a != t; }), arguments );
},
/**
@@ -945,7 +952,7 @@ jQuery.fn = jQuery.prototype = { */
add: function(t) {
return this.pushStack( jQuery.merge( this, typeof t == "string" ?
- jQuery.find(t) : t.constructor == Array ? t : [t] ) );
+ jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
},
/**
@@ -1021,11 +1028,28 @@ jQuery.fn = jQuery.prototype = { * @type jQuery
* @cat Core
*/
- pushStack: function(a) {
- if ( !this.stack )
- this.stack = [];
- this.stack.push( this.get() );
- return this.set( a );
+ pushStack: function(a,args) {
+ var fn = args && args[args.length-1];
+ var fn2 = args && args[args.length-2];
+
+ if ( fn && fn.constructor != Function ) fn = null;
+ if ( fn2 && fn2.constructor != Function ) fn2 = null;
+
+ if ( !fn ) {
+ if ( !this.stack ) this.stack = [];
+ this.stack.push( this.get() );
+ this.set( a );
+ } else {
+ var old = this.get();
+ this.set( a );
+
+ if ( fn2 && a.length || !fn2 )
+ this.each( fn2 || fn ).set( old );
+ else
+ this.set( old ).each( fn );
+ }
+
+ return this;
}
};
@@ -1992,6 +2016,11 @@ jQuery.extend({ * This property is available before the DOM is ready, therefore you can
* use it to add ready events only for certain browsers.
*
+ * There are situations where object detections is not reliable enough, in that
+ * cases it makes sense to use browser detection. Simply try to avoid both!
+ *
+ * A combination of browser and object detection yields quite reliable results.
+ *
* @example $.browser.msie
* @desc Returns true if the current useragent is some version of microsoft's internet explorer
*
|