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
daeb6650
Commit
daeb6650
authored
Sep 14, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for property support in the boolHook before falling back to attribute node. Fixes #10278.
parent
b7ebbb91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
attributes.js
src/attributes.js
+3
-2
attributes.js
test/unit/attributes.js
+12
-8
No files found.
src/attributes.js
View file @
daeb6650
...
@@ -492,8 +492,9 @@ boolHook = {
...
@@ -492,8 +492,9 @@ boolHook = {
get
:
function
(
elem
,
name
)
{
get
:
function
(
elem
,
name
)
{
// Align boolean attributes with corresponding properties
// Align boolean attributes with corresponding properties
// Fall back to attribute presence where some booleans are not supported
// Fall back to attribute presence where some booleans are not supported
var
attrNode
;
var
attrNode
,
return
jQuery
.
prop
(
elem
,
name
)
===
true
||
(
attrNode
=
elem
.
getAttributeNode
(
name
)
)
&&
attrNode
.
nodeValue
!==
false
?
property
=
jQuery
.
prop
(
elem
,
name
);
return
property
===
true
||
typeof
property
!==
"boolean"
&&
(
attrNode
=
elem
.
getAttributeNode
(
name
)
)
&&
attrNode
.
nodeValue
!==
false
?
name
.
toLowerCase
()
:
name
.
toLowerCase
()
:
undefined
;
undefined
;
},
},
...
...
test/unit/attributes.js
View file @
daeb6650
...
@@ -153,11 +153,10 @@ test("attr(Hash)", function() {
...
@@ -153,11 +153,10 @@ test("attr(Hash)", function() {
ok
(
pass
,
"Set Multiple Attributes"
);
ok
(
pass
,
"Set Multiple Attributes"
);
equals
(
jQuery
(
"#text1"
).
attr
({
value
:
function
()
{
return
this
.
id
;
}})[
0
].
value
,
"text1"
,
"Set attribute to computed value #1"
);
equals
(
jQuery
(
"#text1"
).
attr
({
value
:
function
()
{
return
this
.
id
;
}})[
0
].
value
,
"text1"
,
"Set attribute to computed value #1"
);
equals
(
jQuery
(
"#text1"
).
attr
({
title
:
function
(
i
)
{
return
i
;
}}).
attr
(
"title"
),
"0"
,
"Set attribute to computed value #2"
);
equals
(
jQuery
(
"#text1"
).
attr
({
title
:
function
(
i
)
{
return
i
;
}}).
attr
(
"title"
),
"0"
,
"Set attribute to computed value #2"
);
});
});
test
(
"attr(String, Object)"
,
function
()
{
test
(
"attr(String, Object)"
,
function
()
{
expect
(
7
6
);
expect
(
7
7
);
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
fail
=
false
;
fail
=
false
;
...
@@ -212,6 +211,13 @@ test("attr(String, Object)", function() {
...
@@ -212,6 +211,13 @@ test("attr(String, Object)", function() {
equal
(
jQuery
(
"#check2"
).
prop
(
"checked"
),
true
,
"Set checked attribute"
);
equal
(
jQuery
(
"#check2"
).
prop
(
"checked"
),
true
,
"Set checked attribute"
);
equal
(
jQuery
(
"#check2"
).
attr
(
"checked"
),
"checked"
,
"Set checked attribute"
);
equal
(
jQuery
(
"#check2"
).
attr
(
"checked"
),
"checked"
,
"Set checked attribute"
);
QUnit
.
reset
();
var
$radios
=
jQuery
(
"#checkedtest"
).
find
(
"input[type='radio']"
);
$radios
.
eq
(
1
).
click
();
equal
(
$radios
.
eq
(
1
).
prop
(
"checked"
),
true
,
"Second radio was checked when clicked"
);
equal
(
$radios
.
attr
(
"checked"
),
$radios
[
0
].
checked
?
"checked"
:
undefined
,
"Known booleans do not fall back to attribute presence (#10278)"
);
jQuery
(
"#text1"
).
prop
(
"readOnly"
,
true
);
jQuery
(
"#text1"
).
prop
(
"readOnly"
,
true
);
equals
(
document
.
getElementById
(
"text1"
).
readOnly
,
true
,
"Set readonly attribute"
);
equals
(
document
.
getElementById
(
"text1"
).
readOnly
,
true
,
"Set readonly attribute"
);
equals
(
jQuery
(
"#text1"
).
prop
(
"readOnly"
),
true
,
"Set readonly attribute"
);
equals
(
jQuery
(
"#text1"
).
prop
(
"readOnly"
),
true
,
"Set readonly attribute"
);
...
@@ -295,8 +301,6 @@ test("attr(String, Object)", function() {
...
@@ -295,8 +301,6 @@ test("attr(String, Object)", function() {
equals
(
j
.
attr
(
"name"
),
"attrvalue"
,
"Check node,textnode,comment for attr"
);
equals
(
j
.
attr
(
"name"
),
"attrvalue"
,
"Check node,textnode,comment for attr"
);
j
.
removeAttr
(
"name"
);
j
.
removeAttr
(
"name"
);
QUnit
.
reset
();
// Type
// Type
var
type
=
jQuery
(
"#check2"
).
attr
(
"type"
);
var
type
=
jQuery
(
"#check2"
).
attr
(
"type"
);
var
thrown
=
false
;
var
thrown
=
false
;
...
@@ -309,7 +313,7 @@ test("attr(String, Object)", function() {
...
@@ -309,7 +313,7 @@ test("attr(String, Object)", function() {
equals
(
type
,
jQuery
(
"#check2"
).
attr
(
"type"
),
"Verify that you can't change the type of an input element"
);
equals
(
type
,
jQuery
(
"#check2"
).
attr
(
"type"
),
"Verify that you can't change the type of an input element"
);
var
check
=
document
.
createElement
(
"input"
);
var
check
=
document
.
createElement
(
"input"
);
var
thrown
=
true
;
thrown
=
true
;
try
{
try
{
jQuery
(
check
).
attr
(
"type"
,
"checkbox"
);
jQuery
(
check
).
attr
(
"type"
,
"checkbox"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -318,8 +322,8 @@ test("attr(String, Object)", function() {
...
@@ -318,8 +322,8 @@ test("attr(String, Object)", function() {
ok
(
thrown
,
"Exception thrown when trying to change type property"
);
ok
(
thrown
,
"Exception thrown when trying to change type property"
);
equals
(
"checkbox"
,
jQuery
(
check
).
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
equals
(
"checkbox"
,
jQuery
(
check
).
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
var
check
=
jQuery
(
"<input />"
);
check
=
jQuery
(
"<input />"
);
var
thrown
=
true
;
thrown
=
true
;
try
{
try
{
check
.
attr
(
"type"
,
"checkbox"
);
check
.
attr
(
"type"
,
"checkbox"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -329,7 +333,7 @@ test("attr(String, Object)", function() {
...
@@ -329,7 +333,7 @@ test("attr(String, Object)", function() {
equals
(
"checkbox"
,
check
.
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
equals
(
"checkbox"
,
check
.
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
var
button
=
jQuery
(
"#button"
);
var
button
=
jQuery
(
"#button"
);
var
thrown
=
false
;
thrown
=
false
;
try
{
try
{
button
.
attr
(
"type"
,
"submit"
);
button
.
attr
(
"type"
,
"submit"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
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