Got context functions back in, added noteworthy stuff, replaced js linebreak replacer...
[jquery.git] / src / jquery / jquery.js
index 9e62fe3..177d86b 100644 (file)
@@ -22,7 +22,7 @@ window.undefined = window.undefined;
  */\r
 var jQuery = function(a,c) {\r
 \r
-       // Shortcut for document ready (because $(document).each() is silly)\r
+       // Shortcut for document ready\r
        if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function\r
                return jQuery(document).ready(a);\r
 \r
@@ -55,6 +55,13 @@ var jQuery = function(a,c) {
                // Find the matching elements and save them for later\r
                jQuery.find( a, c ) );\r
 \r
+       // See if an extra function was provided\r
+       var fn = arguments[ arguments.length - 1 ];\r
+\r
+       // If so, execute it in context\r
+       if ( fn && typeof fn == "function" )\r
+               this.each(fn);\r
+\r
        return this;\r
 };\r
 \r
@@ -789,7 +796,7 @@ jQuery.fn = jQuery.prototype = {
        find: function(t) {\r
                return this.pushStack( jQuery.map( this, function(a){\r
                        return jQuery.find(t,a);\r
-               }));\r
+               }), arguments );\r
        },\r
 \r
        /**\r
@@ -810,7 +817,7 @@ jQuery.fn = jQuery.prototype = {
        clone: function(deep) {\r
                return this.pushStack( jQuery.map( this, function(a){\r
                        return a.cloneNode( deep != undefined ? deep : true );\r
-               }));\r
+               }), arguments );\r
        },\r
 \r
        /**\r
@@ -865,7 +872,7 @@ jQuery.fn = jQuery.prototype = {
                        typeof t == "function" &&\r
                        jQuery.grep( this, t ) ||\r
 \r
-                       jQuery.filter(t,this).r );\r
+                       jQuery.filter(t,this).r, arguments );\r
        },\r
 \r
        /**\r
@@ -899,7 +906,7 @@ jQuery.fn = jQuery.prototype = {
        not: function(t) {\r
                return this.pushStack( typeof t == "string" ?\r
                        jQuery.filter(t,this,false).r :\r
-                       jQuery.grep(this,function(a){ return a != t; }) );\r
+                       jQuery.grep(this,function(a){ return a != t; }), arguments );\r
        },\r
 \r
        /**\r
@@ -945,7 +952,7 @@ jQuery.fn = jQuery.prototype = {
         */\r
        add: function(t) {\r
                return this.pushStack( jQuery.merge( this, typeof t == "string" ?\r
-                       jQuery.find(t) : t.constructor == Array ? t : [t] ) );\r
+                       jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );\r
        },\r
 \r
        /**\r
@@ -1021,11 +1028,28 @@ jQuery.fn = jQuery.prototype = {
         * @type jQuery\r
         * @cat Core\r
         */\r
-       pushStack: function(a) {\r
-               if ( !this.stack )\r
-                       this.stack = [];\r
-               this.stack.push( this.get() );\r
-               return this.set( a );\r
+       pushStack: function(a,args) {\r
+               var fn = args && args[args.length-1];\r
+               var fn2 = args && args[args.length-2];\r
+               \r
+               if ( fn && fn.constructor != Function ) fn = null;\r
+               if ( fn2 && fn2.constructor != Function ) fn2 = null;\r
+\r
+               if ( !fn ) {\r
+                       if ( !this.stack ) this.stack = [];\r
+                       this.stack.push( this.get() );\r
+                       this.set( a );\r
+               } else {\r
+                       var old = this.get();\r
+                       this.set( a );\r
+\r
+                       if ( fn2 && a.length || !fn2 )\r
+                               this.each( fn2 || fn ).set( old );\r
+                       else\r
+                               this.set( old ).each( fn );\r
+               }\r
+\r
+               return this;\r
        }\r
 };\r
 \r
@@ -1992,6 +2016,11 @@ jQuery.extend({
  * This property is available before the DOM is ready, therefore you can\r
  * use it to add ready events only for certain browsers.\r
  *\r
+ * There are situations where object detections is not reliable enough, in that\r
+ * cases it makes sense to use browser detection. Simply try to avoid both!\r
+ *\r
+ * A combination of browser and object detection yields quite reliable results.\r
+ *\r
  * @example $.browser.msie\r
  * @desc Returns true if the current useragent is some version of microsoft's internet explorer\r
  *\r