Add tests data- and aria- attributes and the autofocus boolean attribute and some style updates in jQuery.attr
This commit is contained in:
parent
83e9ce95d7
commit
5165033883
2 changed files with 17 additions and 6 deletions
|
@ -6,7 +6,7 @@ var rclass = /[\n\t\r]/g,
|
||||||
rtype = /^(?:button|input)$/i,
|
rtype = /^(?:button|input)$/i,
|
||||||
rfocusable = /^(?:button|input|object|select|textarea)$/i,
|
rfocusable = /^(?:button|input|object|select|textarea)$/i,
|
||||||
rclickable = /^a(?:rea)?$/i,
|
rclickable = /^a(?:rea)?$/i,
|
||||||
special = /^(?:data-|aria-)/,
|
rspecial = /^(?:data-|aria-)/,
|
||||||
formHook;
|
formHook;
|
||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
|
@ -312,7 +312,7 @@ jQuery.extend({
|
||||||
|
|
||||||
if ( value !== undefined ) {
|
if ( value !== undefined ) {
|
||||||
|
|
||||||
if ( value === null || (value === false && !special.test( name )) ) {
|
if ( value === null || (value === false && !rspecial.test( name )) ) {
|
||||||
jQuery.removeAttr( elem, name );
|
jQuery.removeAttr( elem, name );
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
|
@ -320,9 +320,12 @@ jQuery.extend({
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if( value === true && !special.test( name ) ){
|
|
||||||
|
// Set boolean attributes to the same name
|
||||||
|
if ( value === true && !rspecial.test( name ) ) {
|
||||||
value = name;
|
value = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.setAttribute( name, "" + value );
|
elem.setAttribute( name, "" + value );
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ test("attr(Hash)", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("attr(String, Object)", function() {
|
test("attr(String, Object)", function() {
|
||||||
expect(30);
|
expect(35);
|
||||||
|
|
||||||
var div = jQuery("div").attr("foo", "bar"),
|
var div = jQuery("div").attr("foo", "bar"),
|
||||||
fail = false;
|
fail = false;
|
||||||
|
@ -189,7 +189,7 @@ test("attr(String, Object)", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
|
equals( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
|
||||||
|
|
||||||
// Fails on IE since recent changes to .attr()
|
// Fails on IE since recent changes to .attr()
|
||||||
// ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
|
// ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
|
||||||
|
@ -214,6 +214,14 @@ test("attr(String, Object)", function() {
|
||||||
equals( $p.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500).");
|
equals( $p.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500).");
|
||||||
$p.removeAttr("nonexisting");
|
$p.removeAttr("nonexisting");
|
||||||
|
|
||||||
|
var $text = jQuery("#text1").attr("autofocus", true);
|
||||||
|
equals( $text.attr("autofocus"), "autofocus", "Set boolean attributes to the same name");
|
||||||
|
equals( $text.attr("autofocus", false).attr("autofocus"), undefined, "Setting autofocus attribute to false removes it");
|
||||||
|
equals( $text.attr("data-something", true).data("something"), true, "Setting data attributes are not affected by boolean settings");
|
||||||
|
equals( $text.attr("data-another", false).data("another"), false, "Setting data attributes are not affected by boolean settings" );
|
||||||
|
equals( $text.attr("aria-disabled", false).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings");
|
||||||
|
$text.removeData("something").removeData("another").removeAttr("aria-disabled");
|
||||||
|
|
||||||
var attributeNode = document.createAttribute("irrelevant"),
|
var attributeNode = document.createAttribute("irrelevant"),
|
||||||
commentNode = document.createComment("some comment"),
|
commentNode = document.createComment("some comment"),
|
||||||
textNode = document.createTextNode("some text");
|
textNode = document.createTextNode("some text");
|
||||||
|
|
Loading…
Add table
Reference in a new issue