Quick bug fix, formatted pack better.
[jquery.git] / src / jquery / jquery.js
index e3929f0..3dd9b5c 100644 (file)
@@ -265,12 +265,10 @@ jQuery.fn = jQuery.prototype = {
         * @before <img/>
         * @result <img src="test.jpg" alt="Test Image"/>
         *
-        * @test var div = $("div");
-        * div.attr({foo: 'baz', zoo: 'ping'});
-        * var pass = true;
-        * for ( var i = 0; i < div.size(); i++ ) {
-        *   if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
-        * }
+        * @test var pass = true;
+        * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
+        *   if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
+        * });
         * ok( pass, "Set Multiple Attributes" );
         *
         * @name attr
@@ -290,7 +288,7 @@ jQuery.fn = jQuery.prototype = {
         * div.attr("foo", "bar");
         * var pass = true;
         * for ( var i = 0; i < div.size(); i++ ) {
-        *   if ( div.get(i).foo != "bar" ) pass = false;
+        *   if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
         * }
         * ok( pass, "Set Attribute" );
         *
@@ -937,7 +935,7 @@ jQuery.extend({
                                        oHeight = e.offsetHeight;
                                        oWidth = e.offsetWidth;
                                } else
-                                       jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
+                                       jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "block" },
                                                function(){
                                                        oHeight = e.clientHeight;
                                                        oWidth = e.clientWidth;
@@ -951,21 +949,35 @@ jQuery.extend({
                return jQuery.curCSS( e, p );
        },
 
-       curCSS: function(e,p,force) {
-               var r;
+       curCSS: function(elem, prop, force) {
+               var ret;
        
-               if (!force && e.style[p])
-                       r = e.style[p];
-               else if (e.currentStyle) {
-                       p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
-                       r = e.currentStyle[p];
+               if (!force && elem.style[prop]) {
+
+                       ret = elem.style[prop];
+
+               } else if (elem.currentStyle) {
+
+                       var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
+                       ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
+
                } else if (document.defaultView && document.defaultView.getComputedStyle) {
-                       p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
-                       var s = document.defaultView.getComputedStyle(e,"");
-                       r = s ? s.getPropertyValue(p) : null;
+
+                       prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
+                       var cur = document.defaultView.getComputedStyle(elem, null);
+
+                       if ( cur )
+                               ret = cur.getPropertyValue(prop);
+                       else if ( prop == 'display' )
+                               ret = 'none';
+                       else
+                               jQuery.swap(elem, { display: 'block' }, function() {
+                                       ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
+                               });
+
                }
                
-               return r;
+               return ret;
        },
        
        clean: function(a) {
@@ -1255,28 +1267,26 @@ jQuery.extend({
                return r;
        },
        
-       attr: function(o,a,v){
-               if ( a && a.constructor == String ) {
-                       var fix = {
-                               "for": "htmlFor",
-                               "class": "className",
-                               "float": "cssFloat"
-                       };
-                       
-                       a = (fix[a] && fix[a].replace && fix[a] || a)
-                               .replace(/-([a-z])/ig,function(z,b){
-                                       return b.toUpperCase();
-                               });
-                       
-                       if ( v != undefined ) {
-                               o[a] = v;
-                               if ( o.setAttribute && a != "disabled" )
-                                       o.setAttribute(a,v);
-                       }
-                       
-                       return o[a] || o.getAttribute && o.getAttribute(a) || "";
-               } else
-                       return "";
+       attr: function(elem, name, value){
+               var fix = {
+                       "for": "htmlFor",
+                       "class": "className",
+                       "float": "cssFloat",
+                       innerHTML: "innerHTML",
+                       className: "className"
+               };
+
+               if ( fix[name] ) {
+                       if ( value != undefined ) elem[fix[name]] = value;
+                       return elem[fix[name]];
+               } else if ( elem.getAttribute ) {
+                       if ( value != undefined ) elem.setAttribute( name, value );
+                       return elem.getAttribute( name, 2 );
+               } else {
+                       name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
+                       if ( value != undefined ) elem[name] = value;
+                       return elem[name];
+               }
        },
 
        // The regular expressions that power the parsing engine
@@ -1405,7 +1415,7 @@ jQuery.extend({
 
                return jQuery.extend( elems, {
                        last: elems.n == elems.length - 1,
-                       cur: n == "even" && elems.n % 2 == 0 || n == "odd" && elems.n % 2 || elems[pos] == a,
+                       cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
                        prev: elems[elems.n - 1],
                        next: elems[elems.n + 1]
                });
@@ -1426,7 +1436,7 @@ jQuery.extend({
                // Move b over to the new array (this helps to avoid
                // StaticNodeList instances)
                for ( var k = 0; k < first.length; k++ )
-                       result[k] = second[k];
+                       result[k] = first[k];
        
                // Now check for duplicates between a and b and only
                // add the unique items