Fix for #812
[jquery.git] / src / jquery / jquery.js
index 108e9a3..0b0972e 100644 (file)
@@ -122,11 +122,6 @@ var $ = jQuery;
  * This function also accepts XML Documents and Window objects
  * as valid arguments (even though they are not DOM Elements).
  *
- * @example $(document).find("div > p")
- * @before <p>one</p> <div><p>two</p></div> <p>three</p>
- * @result [ <p>two</p> ]
- * @desc Same as $("div > p") because the document
- *
  * @example $(document.body).background( "black" );
  * @desc Sets the background color of the page to black.
  *
@@ -416,10 +411,16 @@ jQuery.fn = jQuery.prototype = {
         * @result <img src="test.jpg" title="test.jpg" />
         * @desc Sets title attribute from src attribute.
         *
+        * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
+        * @before <img title="pic" /><img title="pic" /><img title="pic" />
+        * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
+        * @desc Enumerate title attribute.
+        *
         * @name attr
         * @type jQuery
         * @param String key The name of the property to set.
         * @param Function value A function returning the value to set.
+        *                Scope: Current element, argument: Index of current element
         * @cat DOM/Attributes
         */
        attr: function( key, value, type ) {
@@ -435,12 +436,12 @@ jQuery.fn = jQuery.prototype = {
                        }
                
                // Check to see if we're setting style values
-               return this.each(function(){
+               return this.each(function(index){
                        // Set all the styles
                        for ( var prop in obj )
                                jQuery.attr(
                                        type ? this.style : this,
-                                       prop, jQuery.prop(this, obj[prop], type)
+                                       prop, jQuery.prop(this, obj[prop], type, index, prop)
                                );
                });
        },
@@ -1261,13 +1262,16 @@ jQuery.extend({
                return obj;
        },
        
-       prop: function(elem, value, type){
+       prop: function(elem, value, type, index, prop){
                        // Handle executable functions
                        if ( jQuery.isFunction( value ) )
-                               return value.call( elem );
+                               return value.call( elem, [index] );
+                               
+                       // exclude the following css properties to add px
+                       var exclude = /z-?index|font-?weight|opacity/i;
 
                        // Handle passing in a number to a CSS property
-                       if ( value.constructor == Number && type == "curCSS" )
+                       if ( value.constructor == Number && type == "curCSS" && !exclude.test(prop) )
                                return value + "px";
 
                        return value;