Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
1886d744
Commit
1886d744
authored
Jul 09, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check the attribute node value for false for HTML5 booleans when not supported. Fixes #9504.
parent
e6f89519
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
attributes.js
src/attributes.js
+3
-1
attributes.js
test/unit/attributes.js
+15
-8
No files found.
src/attributes.js
View file @
1886d744
...
@@ -496,7 +496,9 @@ jQuery.extend({
...
@@ -496,7 +496,9 @@ jQuery.extend({
boolHook
=
{
boolHook
=
{
get
:
function
(
elem
,
name
)
{
get
:
function
(
elem
,
name
)
{
// Align boolean attributes with corresponding properties
// Align boolean attributes with corresponding properties
return
jQuery
.
prop
(
elem
,
name
)
?
// Fall back to attribute presence where some booleans are not supported
var
attrNode
;
return
jQuery
.
prop
(
elem
,
name
)
===
true
||
(
attrNode
=
elem
.
getAttributeNode
(
name
)
)
&&
attrNode
.
nodeValue
!==
false
?
name
.
toLowerCase
()
:
name
.
toLowerCase
()
:
undefined
;
undefined
;
},
},
...
...
test/unit/attributes.js
View file @
1886d744
...
@@ -162,7 +162,7 @@ test("attr(Hash)", function() {
...
@@ -162,7 +162,7 @@ test("attr(Hash)", function() {
});
});
test
(
"attr(String, Object)"
,
function
()
{
test
(
"attr(String, Object)"
,
function
()
{
expect
(
69
);
expect
(
73
);
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
fail
=
false
;
fail
=
false
;
...
@@ -230,13 +230,20 @@ test("attr(String, Object)", function() {
...
@@ -230,13 +230,20 @@ test("attr(String, Object)", function() {
jQuery
(
"#name"
).
attr
(
"maxLength"
,
"10"
);
jQuery
(
"#name"
).
attr
(
"maxLength"
,
"10"
);
equals
(
document
.
getElementById
(
"name"
).
maxLength
,
10
,
"Set maxlength attribute"
);
equals
(
document
.
getElementById
(
"name"
).
maxLength
,
10
,
"Set maxlength attribute"
);
var
$text
=
jQuery
(
"#text1"
).
attr
(
"autofocus"
,
true
);
// HTML5 boolean attributes
if
(
"autofocus"
in
$text
[
0
]
)
{
var
$text
=
jQuery
(
"#text1"
).
attr
({
equals
(
$text
.
attr
(
"autofocus"
),
"autofocus"
,
"Set boolean attributes to the same name"
);
"autofocus"
:
true
,
}
else
{
"required"
:
true
equals
(
$text
.
attr
(
"autofocus"
),
undefined
,
"autofocus stays undefined in browsers that do not support it(F<4)"
);
});
}
equal
(
$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"
);
equal
(
$text
.
attr
(
"autofocus"
,
false
).
attr
(
"autofocus"
),
undefined
,
"Setting autofocus attribute to false removes it"
);
equal
(
$text
.
attr
(
"required"
),
"required"
,
"Set boolean attributes to the same name"
);
equal
(
$text
.
attr
(
"required"
,
false
).
attr
(
"required"
),
undefined
,
"Setting required attribute to false removes it"
);
var
$details
=
jQuery
(
"<details open></details>"
).
appendTo
(
"#qunit-fixture"
);
equal
(
$details
.
attr
(
"open"
),
"open"
,
"open attribute presense indicates true"
);
equal
(
$details
.
attr
(
"open"
,
false
).
attr
(
"open"
),
undefined
,
"Setting open 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-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
(
"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"
);
equals
(
$text
.
attr
(
"aria-disabled"
,
false
).
attr
(
"aria-disabled"
),
"false"
,
"Setting aria attributes are not affected by boolean settings"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment