Continuing IE7 testing, conditional attr fixes and hooks with feature testing. Will figure out a way to shorten after the test suite passes.
This commit is contained in:
parent
ebb8e8e300
commit
8cd30c62d8
|
@ -16,7 +16,7 @@ jQuery.fn.extend({
|
||||||
removeAttr: function( name ) {
|
removeAttr: function( name ) {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
if ( this.nodeType === 1 ) {
|
if ( this.nodeType === 1 ) {
|
||||||
this.removeAttribute( name );
|
jQuery.removeAttr( this, name );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -287,68 +287,52 @@ jQuery.extend({
|
||||||
if ( pass && name in jQuery.attrFn ) {
|
if ( pass && name in jQuery.attrFn ) {
|
||||||
return jQuery(elem)[name](value);
|
return jQuery(elem)[name](value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret,
|
var ret,
|
||||||
notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ),
|
notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ),
|
||||||
hooks;
|
hooks;
|
||||||
|
|
||||||
// Normalize the name if needed
|
// Normalize the name if needed
|
||||||
name = notxml && jQuery.attrFix[ name ] || name;
|
name = notxml && jQuery.attrFix[ name ] || name;
|
||||||
|
|
||||||
hooks = jQuery.attrHooks[ name ];
|
hooks = jQuery.attrHooks[ name ];
|
||||||
|
|
||||||
if ( value !== undefined ) {
|
if ( value !== undefined ) {
|
||||||
|
|
||||||
if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value )) !== undefined ) {
|
if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value )) !== undefined ) {
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else if ( value === null ) {
|
} else if ( value === null ) {
|
||||||
elem.removeAttribute( name );
|
jQuery.removeAttr( elem, name );
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// convert the value to a string (all browsers do this but IE) see #1070
|
|
||||||
value = "" + value;
|
|
||||||
elem.setAttribute( name, value );
|
elem.setAttribute( name, value );
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem )) !== undefined ) {
|
if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem )) !== undefined ) {
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ( !jQuery.hasAttr( elem, name ) ) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
var attr = elem.getAttribute( name );
|
var attr = elem.getAttribute( name );
|
||||||
|
|
||||||
// Non-existent attributes return null, we normalize to undefined
|
// Non-existent attributes return null, we normalize to undefined
|
||||||
return attr === null || attr === "undefined" ? undefined : attr;
|
return attr === null || attr === "undefined" || attr === "null" ? undefined : attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hasAttr: function( elem, name ) {
|
// removeAttribute returns boolean in IE6/7
|
||||||
|
// set property to null in that case
|
||||||
return elem.hasAttribute ?
|
removeAttr: function( elem, name ) {
|
||||||
elem.hasAttribute( name ) :
|
if ( typeof elem.removeAttribute( name ) === "boolean" ) {
|
||||||
(function() {
|
elem.setAttribute( name, null );
|
||||||
// Some browsers do not understand the associative indexes
|
}
|
||||||
// Look for the name in elem.attributes.name
|
|
||||||
var attrs = elem.attributes, i = 0, len = attrs.length;
|
|
||||||
for ( ; i < len; i++ ) {
|
|
||||||
if ( attrs[i].name === name ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
attrHooks: {
|
attrHooks: {
|
||||||
type: {
|
type: {
|
||||||
set: function( elem, value ) {
|
set: function( elem, value ) {
|
||||||
|
@ -357,20 +341,6 @@ jQuery.extend({
|
||||||
jQuery.error( "type property can't be changed" );
|
jQuery.error( "type property can't be changed" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
|
||||||
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
|
||||||
tabindex: {
|
|
||||||
get: function( elem ) {
|
|
||||||
var attributeNode = elem.getAttributeNode( "tabIndex" );
|
|
||||||
|
|
||||||
return attributeNode && attributeNode.specified ?
|
|
||||||
attributeNode.value :
|
|
||||||
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
|
|
||||||
0 :
|
|
||||||
undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -414,20 +384,64 @@ jQuery.extend({
|
||||||
propHooks: {}
|
propHooks: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
||||||
|
if ( !jQuery.support.getSetAttribute ) {
|
||||||
|
jQuery.attrFix = jQuery.extend( jQuery.attrFix, {
|
||||||
|
"for": "htmlFor",
|
||||||
|
"class": "className",
|
||||||
|
readonly: "readOnly",
|
||||||
|
maxlength: "maxLength",
|
||||||
|
cellspacing: "cellSpacing",
|
||||||
|
rowspan: "rowSpan",
|
||||||
|
colspan: "colSpan",
|
||||||
|
tabindex: "tabIndex",
|
||||||
|
usemap: "useMap",
|
||||||
|
frameborder: "frameBorder"
|
||||||
|
});
|
||||||
|
|
||||||
|
// Action attribute in ie6/7 returns form object
|
||||||
|
jQuery.attrHooks.action = jQuery.extend( jQuery.attrHooks.action, {
|
||||||
|
get: function( elem ) {
|
||||||
|
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);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 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 ) { // '', undefined, false, null will remove attr
|
||||||
elem.removeAttribute( name );
|
jQuery.removeAttr( elem, name );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.setAttribute( name, value );
|
elem.setAttribute( name, value );
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
||||||
|
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
||||||
|
jQuery.attrHooks[ jQuery.attrFix.tabindex || "tabindex" ] = {
|
||||||
|
get: function( elem ) {
|
||||||
|
var attributeNode = elem.getAttributeNode("tabIndex");
|
||||||
|
|
||||||
|
return attributeNode && attributeNode.specified ?
|
||||||
|
parseInt( attributeNode.value, 10 ) :
|
||||||
|
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
|
||||||
|
0 :
|
||||||
|
undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Some attributes require a special call on IE
|
// Some attributes require a special call on IE
|
||||||
if ( !jQuery.support.hrefNormalized ) {
|
if ( !jQuery.support.hrefNormalized ) {
|
||||||
jQuery.each([ "href", "src", "style" ], function( i, name ) {
|
jQuery.each([ "href", "src", "style" ], function( i, name ) {
|
||||||
|
@ -474,20 +488,4 @@ if ( !jQuery.support.optSelected ) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
|
||||||
if ( jQuery.support.attrFix ) {
|
|
||||||
jQuery.extend( jQuery.attrFix, {
|
|
||||||
"for": "htmlFor",
|
|
||||||
"class": "className",
|
|
||||||
readonly: "readOnly",
|
|
||||||
maxlength: "maxLength",
|
|
||||||
cellspacing: "cellSpacing",
|
|
||||||
rowspan: "rowSpan",
|
|
||||||
colspan: "colSpan",
|
|
||||||
tabindex: "tabIndex",
|
|
||||||
usemap: "useMap",
|
|
||||||
frameborder: "frameBorder"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
|
@ -894,4 +894,4 @@ function doScrollCheck() {
|
||||||
// Expose jQuery to the global object
|
// Expose jQuery to the global object
|
||||||
return jQuery;
|
return jQuery;
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -59,7 +59,7 @@
|
||||||
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
|
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
|
||||||
optSelected: opt.selected,
|
optSelected: opt.selected,
|
||||||
|
|
||||||
attrFix: div.className === "t",
|
getSetAttribute: div.className !== "t",
|
||||||
|
|
||||||
// Will be defined later
|
// Will be defined later
|
||||||
deleteExpando: true,
|
deleteExpando: true,
|
||||||
|
|
|
@ -824,4 +824,4 @@ test("addClass, removeClass, hasClass", function() {
|
||||||
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
|
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
|
||||||
jq.removeClass("class4");
|
jq.removeClass("class4");
|
||||||
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
|
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
|
||||||
});
|
});
|
Loading…
Reference in a new issue