]> source.dussan.org Git - jquery.git/commitdiff
Style edits according to comments from John and rwaldron.
authortimmywil <tim.willison@thisismedium.com>
Mon, 14 Mar 2011 01:27:45 +0000 (21:27 -0400)
committertimmywil <tim.willison@thisismedium.com>
Sun, 3 Apr 2011 23:13:39 +0000 (19:13 -0400)
src/attributes.js
test/unit/attributes.js

index 37a6c1e590fc2a76305551bdb44ef1652c9f8b85..d045ca67ee97e8fc961b36a7c298cb4be35595e3 100644 (file)
@@ -320,7 +320,9 @@ jQuery.extend({
                                var attr = elem.getAttribute( name );
 
                                // Non-existent attributes return null, we normalize to undefined
-                               return attr === null || attr === "undefined" || attr === "null" ? undefined : attr;
+                               return attr === null || attr === "undefined" || attr === "null" ?
+                                       undefined :
+                                       attr;
                        }
                }
        },
@@ -328,10 +330,17 @@ jQuery.extend({
        removeAttr: function( elem, name ) {
                name = jQuery.attrFix[ name ] || name;
                
-               jQuery.support.getSetAttribute ? elem.removeAttribute( name ) :
+               if ( jQuery.support.getSetAttribute ) {
+                       elem.removeAttribute( name )
+               } else {
                        // set property to null if getSetAttribute not supported (IE6-7)
                        // setting className to null makes the class "null"
-                       name === "className" ? elem.className = "" : elem.setAttribute( name, null );
+                       if ( name === "className" ) {
+                               elem.className = ""
+                       } else {
+                               elem.setAttribute( name, null );
+                       }
+               }
        },
 
        attrHooks: {
@@ -345,10 +354,7 @@ jQuery.extend({
                }
        },
        
-       // TODO: Check to see if we really need any here.
-       propFix: {
-               
-       },
+       propFix: {},
        
        prop: function( elem, name, value ) {
                
@@ -403,10 +409,14 @@ if ( !jQuery.support.getSetAttribute ) {
        // Action attribute in ie6/7 returns form objects
        jQuery.attrHooks.action = {
                get: function( elem ) {
-                       return elem.nodeName === "FORM" ? elem.getAttributeNode("action").nodeValue : elem.getAttribute("action");
+                       return elem.nodeName === "FORM" ?
+                               elem.getAttributeNode("action").nodeValue :
+                               elem.getAttribute("action");
                },
                set: function( elem, value ) {
-                       elem.nodeName === "FORM" ? elem.getAttributeNode("action").nodeValue = value : elem.setAttribute("action", value);
+                       elem.nodeName === "FORM" ?
+                               elem.getAttributeNode("action").nodeValue = value :
+                               elem.setAttribute("action", value);
                        return value;
                }
        };
index d3293545587ca56abf41d48a4fcb35a492c5c3b6..8b483dccb475fd7ac14492e5385ae6bf14ab65c0 100644 (file)
@@ -3,6 +3,31 @@ module("attributes", { teardown: moduleTeardown });
 var bareObj = function(value) { return value; };
 var functionReturningObj = function(value) { return (function() { return value; }); };
 
+if ( !jQuery.support.getSetAttribute ) {
+       test("jQuery.attrFix integrity test", function() {
+               expect(1);
+
+               //  This must be maintained and equal jQuery.attrFix when appropriate
+               //  Ensure that accidental or erroneous property
+               //  overwrites don't occur
+               //  This is simply for better code coverage and future proofing.
+               var propsShouldBe = {
+                       "for": "htmlFor",
+                       "class": "className",
+                       readonly: "readOnly",
+                       maxlength: "maxLength",
+                       cellspacing: "cellSpacing",
+                       rowspan: "rowSpan",
+                       colspan: "colSpan",
+                       tabindex: "tabIndex",
+                       usemap: "useMap",
+                       frameborder: "frameBorder"
+               };
+
+               same(propsShouldBe, jQuery.attrFix, "jQuery.attrFix passes integrity check");
+       });
+}
+
 test("prop", function() {
        equals( jQuery('#text1').prop('value'), "Test", 'Check for value attribute' );
        equals( jQuery('#text1').prop('value', "Test2").prop('defaultValue'), "Test", 'Check for defaultValue attribute' );