Commit ad2b3bc9 authored by timmywil's avatar timmywil

Found a problem removing the style attribute in IE

- Style is now a special case in IE6/7 to set cssText.  My goal is to avoid calling attr again for the performance benefit, and at this point it would also cause an infinite loop for the boolean attributes hooks such as selected & checked.  Nevertheless, style seems to be the only one requiring a special call.
parent 2a8a2b61
...@@ -276,7 +276,8 @@ jQuery.extend({ ...@@ -276,7 +276,8 @@ jQuery.extend({
attrFix: { attrFix: {
// Always normalize to ensure hook usage // Always normalize to ensure hook usage
tabindex: "tabIndex" tabindex: "tabIndex",
readonly: "readOnly"
}, },
attr: function( elem, name, value, pass ) { attr: function( elem, name, value, pass ) {
...@@ -339,12 +340,16 @@ jQuery.extend({ ...@@ -339,12 +340,16 @@ jQuery.extend({
if ( jQuery.support.getSetAttribute ) { if ( jQuery.support.getSetAttribute ) {
elem.removeAttribute( name ); elem.removeAttribute( name );
} else { } else {
// Set to default empty string (No longer need to use attr for this) // Only style is a special case.
if ( name === "style" ) {
elem.style.cssText = "";
} else {
elem.setAttribute( name, "" ); elem.setAttribute( name, "" );
// Attempt to remove completely with DOM level 1 // Attempt to remove completely with DOM level 1
elem.removeAttributeNode( elem.getAttributeNode( name ) ); elem.removeAttributeNode( elem.getAttributeNode( name ) );
} }
} }
}
}, },
attrHooks: { attrHooks: {
...@@ -415,7 +420,6 @@ if ( !jQuery.support.getSetAttribute ) { ...@@ -415,7 +420,6 @@ if ( !jQuery.support.getSetAttribute ) {
jQuery.attrFix = jQuery.extend( jQuery.attrFix, { jQuery.attrFix = jQuery.extend( jQuery.attrFix, {
"for": "htmlFor", "for": "htmlFor",
"class": "className", "class": "className",
readonly: "readOnly",
maxlength: "maxLength", maxlength: "maxLength",
cellspacing: "cellSpacing", cellspacing: "cellSpacing",
rowspan: "rowSpan", rowspan: "rowSpan",
...@@ -447,12 +451,10 @@ if ( !jQuery.support.getSetAttribute ) { ...@@ -447,12 +451,10 @@ if ( !jQuery.support.getSetAttribute ) {
} }
// Remove certain attrs if set to false // Remove certain attrs if set to false
jQuery.each([ "selected", "checked", "readonly", "disabled" ], function( i, name ) { jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name ) {
name = jQuery.attrFix[ name ] || name;
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
set: function( elem, value ) { set: function( elem, value ) {
if ( !value ) { // '', undefined, false, null will remove attr if ( !value ) {
jQuery.removeAttr( elem, name ); jQuery.removeAttr( elem, name );
return false; return false;
} }
...@@ -472,9 +474,10 @@ if ( !jQuery.support.hrefNormalized ) { ...@@ -472,9 +474,10 @@ if ( !jQuery.support.hrefNormalized ) {
} }
if ( !jQuery.support.style ) { if ( !jQuery.support.style ) {
jQuery.propHooks.style = jQuery.attrHooks.style = { jQuery.attrHooks.style = {
get: function( elem ) { get: function( elem ) {
return elem.style.cssText; // Return undefined in the case of empty string
return elem.style.cssText || undefined;
}, },
set: function( elem, value ) { set: function( elem, value ) {
return (elem.style.cssText = "" + value); return (elem.style.cssText = "" + value);
......
...@@ -15,9 +15,9 @@ test("jQuery.attrFix integrity test", function() { ...@@ -15,9 +15,9 @@ test("jQuery.attrFix integrity test", function() {
if ( !jQuery.support.getSetAttribute ) { if ( !jQuery.support.getSetAttribute ) {
propsShouldBe = { propsShouldBe = {
tabindex: "tabIndex", tabindex: "tabIndex",
readonly: "readOnly",
"for": "htmlFor", "for": "htmlFor",
"class": "className", "class": "className",
readonly: "readOnly",
maxlength: "maxLength", maxlength: "maxLength",
cellspacing: "cellSpacing", cellspacing: "cellSpacing",
rowspan: "rowSpan", rowspan: "rowSpan",
...@@ -27,7 +27,8 @@ test("jQuery.attrFix integrity test", function() { ...@@ -27,7 +27,8 @@ test("jQuery.attrFix integrity test", function() {
}; };
} else { } else {
propsShouldBe = { propsShouldBe = {
tabindex: "tabIndex" tabindex: "tabIndex",
readonly: "readOnly"
}; };
} }
...@@ -172,7 +173,7 @@ test("attr(Hash)", function() { ...@@ -172,7 +173,7 @@ test("attr(Hash)", function() {
}); });
test("attr(String, Object)", function() { test("attr(String, Object)", function() {
expect(29); expect(30);
var div = jQuery("div").attr("foo", "bar"), var div = jQuery("div").attr("foo", "bar"),
fail = false; fail = false;
...@@ -195,6 +196,8 @@ test("attr(String, Object)", function() { ...@@ -195,6 +196,8 @@ test("attr(String, Object)", function() {
equals( jQuery("#name").attr('name'), undefined, 'Remove name attribute' ); equals( jQuery("#name").attr('name'), undefined, 'Remove name attribute' );
jQuery("#check2").attr('checked', true); jQuery("#check2").attr('checked', true);
equals( document.getElementById('check2').checked, true, 'Set checked attribute' ); equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
jQuery("#check2").attr('checked', '');
equals( document.getElementById('check2').checked, false, 'Setting checked to empty string removes it' );
jQuery("#check2").attr('checked', false); jQuery("#check2").attr('checked', false);
equals( document.getElementById('check2').checked, false, 'Set checked attribute' ); equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
jQuery("#text1").attr('readonly', true); jQuery("#text1").attr('readonly', true);
...@@ -397,9 +400,11 @@ test("attr('tabindex', value)", function() { ...@@ -397,9 +400,11 @@ test("attr('tabindex', value)", function() {
}); });
test("removeAttr(String)", function() { test("removeAttr(String)", function() {
expect(2); expect(4);
equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" ); equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
equals( jQuery('#form').removeAttr('id').attr('id'), undefined, 'Remove id' ); equals( jQuery('#form').removeAttr('id').attr('id'), undefined, 'Remove id' );
equals( jQuery('#foo').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute' );
equals( jQuery('#form').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute on a form' );
}); });
test("removeProp(String)", function() { test("removeProp(String)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment