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
5eecb13f
Commit
5eecb13f
authored
Mar 10, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now passes in IE8, changed around $.hasAttr and switched the attrHook for selected to be a propHook
parent
de79e8c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
40 deletions
+33
-40
attributes.js
src/attributes.js
+28
-11
attributes.js
test/unit/attributes.js
+5
-29
No files found.
src/attributes.js
View file @
5eecb13f
...
@@ -278,6 +278,7 @@ jQuery.extend({
...
@@ -278,6 +278,7 @@ jQuery.extend({
// TODO: Check to see if any of these are needed anymore?
// TODO: Check to see if any of these are needed anymore?
// If not, it may be good to standardize on all-lowercase names instead
// If not, it may be good to standardize on all-lowercase names instead
attrFix
:
{
attrFix
:
{
},
},
attr
:
function
(
elem
,
name
,
value
,
pass
)
{
attr
:
function
(
elem
,
name
,
value
,
pass
)
{
...
@@ -295,9 +296,6 @@ jQuery.extend({
...
@@ -295,9 +296,6 @@ jQuery.extend({
notxml
=
elem
.
nodeType
!==
1
||
!
jQuery
.
isXMLDoc
(
elem
),
notxml
=
elem
.
nodeType
!==
1
||
!
jQuery
.
isXMLDoc
(
elem
),
hooks
;
hooks
;
// Try to normalize/fix the name
name
=
notxml
&&
jQuery
.
attrFix
[
name
]
||
name
;
hooks
=
jQuery
.
attrHooks
[
name
];
hooks
=
jQuery
.
attrHooks
[
name
];
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
...
@@ -312,9 +310,7 @@ jQuery.extend({
...
@@ -312,9 +310,7 @@ jQuery.extend({
}
else
{
}
else
{
// convert the value to a string (all browsers do this but IE) see #1070
// convert the value to a string (all browsers do this but IE) see #1070
value
=
""
+
value
;
value
=
""
+
value
;
elem
.
setAttribute
(
name
,
value
);
elem
.
setAttribute
(
name
,
value
);
return
value
;
return
value
;
}
}
...
@@ -332,14 +328,24 @@ jQuery.extend({
...
@@ -332,14 +328,24 @@ jQuery.extend({
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
?
undefined
:
attr
;
return
attr
===
null
||
attr
===
"undefined"
?
undefined
:
attr
;
}
}
}
}
},
},
hasAttr
:
function
(
elem
,
name
)
{
hasAttr
:
function
(
elem
,
name
)
{
// Blackberry 4.7 returns "" from getAttribute #6938
var
inAttrs
,
attrs
=
elem
.
attributes
;
return
elem
&&
elem
.
attributes
[
name
]
||
(
elem
.
hasAttribute
&&
elem
.
hasAttribute
(
name
));
if
(
elem
.
hasAttribute
)
{
return
elem
.
hasAttribute
(
name
);
}
else
{
// Browsers do not understand the associative indexes, look for the name in elem.attributes.name
for
(
var
i
=
0
,
l
=
attrs
.
length
;
i
<
l
;
i
++
)
{
if
(
attrs
[
i
][
"name"
]
===
name
)
{
return
true
;
}
}
}
},
},
attrHooks
:
{
attrHooks
:
{
...
@@ -369,9 +375,16 @@ jQuery.extend({
...
@@ -369,9 +375,16 @@ jQuery.extend({
// TODO: Check to see if we really need any here.
// TODO: Check to see if we really need any here.
propFix
:
{
propFix
:
{
},
},
prop
:
function
(
elem
,
name
,
value
)
{
prop
:
function
(
elem
,
name
,
value
)
{
// don't get/set properties on text, comment and attribute nodes
if
(
!
elem
||
elem
.
nodeType
===
3
||
elem
.
nodeType
===
8
||
elem
.
nodeType
===
2
)
{
return
undefined
;
}
var
ret
,
hooks
,
notxml
=
elem
.
nodeType
!==
1
||
!
jQuery
.
isXMLDoc
(
elem
);
var
ret
,
hooks
,
notxml
=
elem
.
nodeType
!==
1
||
!
jQuery
.
isXMLDoc
(
elem
);
// Try to normalize/fix the name
// Try to normalize/fix the name
...
@@ -440,13 +453,17 @@ if ( !jQuery.support.style ) {
...
@@ -440,13 +453,17 @@ if ( !jQuery.support.style ) {
// Safari mis-reports the default selected property of an option
// Safari mis-reports the default selected property of an option
// Accessing the parent's selectedIndex property fixes it
// Accessing the parent's selectedIndex property fixes it
if
(
!
jQuery
.
support
.
optSelected
)
{
if
(
!
jQuery
.
support
.
optSelected
)
{
jQuery
.
attrHooks
.
selected
=
{
jQuery
.
propHooks
.
selected
=
{
get
:
function
(
elem
)
{
get
:
function
(
elem
)
{
var
parent
=
elem
.
parentNode
;
var
parent
=
elem
.
parentNode
;
if
(
parent
)
{
if
(
parent
)
{
parent
.
selectedIndex
;
parent
.
selectedIndex
;
// TODO: We may need an attrHook for selected that simply defers to prop?
// The attr is undefined if the option is created with createElement and not on the DOM
// Make sure that it also works with optgroups, see #5701
// Make sure that it also works with optgroups, see #5701
if
(
parent
.
parentNode
)
{
if
(
parent
.
parentNode
)
{
parent
.
parentNode
.
selectedIndex
;
parent
.
parentNode
.
selectedIndex
;
...
...
test/unit/attributes.js
View file @
5eecb13f
...
@@ -3,31 +3,6 @@ module("attributes", { teardown: moduleTeardown });
...
@@ -3,31 +3,6 @@ module("attributes", { teardown: moduleTeardown });
var
bareObj
=
function
(
value
)
{
return
value
;
};
var
bareObj
=
function
(
value
)
{
return
value
;
};
var
functionReturningObj
=
function
(
value
)
{
return
(
function
()
{
return
value
;
});
};
var
functionReturningObj
=
function
(
value
)
{
return
(
function
()
{
return
value
;
});
};
// test("jQuery.props: integrity test", function() {
//
// expect(1);
//
// // This must be maintained and equal jQuery.props
// // Ensure that accidental or erroneous property
// // overwrites don't occur
// // This is simply for better code coverage and future proofing.
// var propsShouldBe = {
// "for": "htmlFor",
// "class": "className",
// readonly: "readOnly",
// maxlength: "maxLength",
// cellspacing: "cellSpacing",
// rowspan: "rowSpan",
// colspan: "colSpan",
// tabindex: "tabIndex",
// usemap: "useMap",
// frameborder: "frameBorder"
// };
//
// same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check");
//
// });
test
(
"prop"
,
function
()
{
test
(
"prop"
,
function
()
{
equals
(
jQuery
(
'#text1'
).
prop
(
'value'
),
"Test"
,
'Check for value attribute'
);
equals
(
jQuery
(
'#text1'
).
prop
(
'value'
),
"Test"
,
'Check for value attribute'
);
equals
(
jQuery
(
'#text1'
).
prop
(
'value'
,
"Test2"
).
prop
(
'defaultValue'
),
"Test"
,
'Check for defaultValue attribute'
);
equals
(
jQuery
(
'#text1'
).
prop
(
'value'
,
"Test2"
).
prop
(
'defaultValue'
),
"Test"
,
'Check for defaultValue attribute'
);
...
@@ -41,11 +16,12 @@ test("prop", function() {
...
@@ -41,11 +16,12 @@ test("prop", function() {
body
.
foo
=
'bar'
;
body
.
foo
=
'bar'
;
equals
(
$body
.
prop
(
'foo'
),
'bar'
,
'Make sure the expando is preferred over the dom attribute'
);
equals
(
$body
.
prop
(
'foo'
),
'bar'
,
'Make sure the expando is preferred over the dom attribute'
);
body
.
foo
=
undefined
;
body
.
foo
=
undefined
;
ok
(
$body
.
attr
(
'foo'
)
===
undefined
,
'Make sure the expando is preferred over the dom attribute, even if undefined'
);
ok
(
$body
.
prop
(
'foo'
)
===
undefined
,
'Make sure the expando is preferred over the dom attribute, even if undefined'
);
var
select
=
document
.
createElement
(
"select"
),
optgroup
=
document
.
createElement
(
"optgroup"
),
option
=
document
.
createElement
(
"option"
);
var
select
=
document
.
createElement
(
"select"
),
optgroup
=
document
.
createElement
(
"optgroup"
),
option
=
document
.
createElement
(
"option"
);
optgroup
.
appendChild
(
option
);
optgroup
.
appendChild
(
option
);
select
.
appendChild
(
optgroup
);
select
.
appendChild
(
optgroup
);
equals
(
jQuery
(
option
).
prop
(
"selected"
),
true
,
"Make sure that a single option is selected, even when in an optgroup."
);
equals
(
jQuery
(
option
).
prop
(
"selected"
),
true
,
"Make sure that a single option is selected, even when in an optgroup."
);
equals
(
jQuery
(
document
).
prop
(
"nodeName"
),
"#document"
,
"prop works correctly on document nodes (bug #7451)."
);
equals
(
jQuery
(
document
).
prop
(
"nodeName"
),
"#document"
,
"prop works correctly on document nodes (bug #7451)."
);
...
@@ -85,7 +61,7 @@ test("attr(String)", function() {
...
@@ -85,7 +61,7 @@ test("attr(String)", function() {
// Related to [5574] and [5683]
// Related to [5574] and [5683]
var
body
=
document
.
body
,
$body
=
jQuery
(
body
);
var
body
=
document
.
body
,
$body
=
jQuery
(
body
);
ok
(
$body
.
attr
(
'foo'
)
===
undefined
,
'Make sure that a non existent attribute returns undefined'
);
strictEqual
(
$body
.
attr
(
'foo'
),
undefined
,
'Make sure that a non existent attribute returns undefined'
);
body
.
setAttribute
(
'foo'
,
'baz'
);
body
.
setAttribute
(
'foo'
,
'baz'
);
equals
(
$body
.
attr
(
'foo'
),
'baz'
,
'Make sure the dom attribute is retrieved when no expando is found'
);
equals
(
$body
.
attr
(
'foo'
),
'baz'
,
'Make sure the dom attribute is retrieved when no expando is found'
);
...
@@ -118,8 +94,8 @@ if ( !isLocal ) {
...
@@ -118,8 +94,8 @@ if ( !isLocal ) {
test
(
"attr(String, Function)"
,
function
()
{
test
(
"attr(String, Function)"
,
function
()
{
expect
(
2
);
expect
(
2
);
equals
(
jQuery
(
'#text1'
).
attr
(
'value'
,
function
()
{
return
this
.
id
;
})[
0
].
value
,
"text1"
,
"Set value from id"
);
equals
(
jQuery
(
'#text1'
).
attr
(
'value'
,
function
()
{
return
this
.
id
;
})[
0
].
value
,
"text1"
,
"Set value from id"
);
equals
(
jQuery
(
'#text1'
).
attr
(
'title'
,
function
(
i
)
{
return
i
}).
attr
(
'title'
),
"0"
,
"Set value with an index"
);
equals
(
jQuery
(
'#text1'
).
attr
(
'title'
,
function
(
i
)
{
return
i
;
}).
attr
(
'title'
),
"0"
,
"Set value with an index"
);
});
});
test
(
"attr(Hash)"
,
function
()
{
test
(
"attr(Hash)"
,
function
()
{
...
...
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