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
dbe3b7a9
Commit
dbe3b7a9
authored
Mar 14, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Style edits according to comments from John and rwaldron.
parent
f578e0f9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
9 deletions
+44
-9
attributes.js
src/attributes.js
+19
-9
attributes.js
test/unit/attributes.js
+25
-0
No files found.
src/attributes.js
View file @
dbe3b7a9
...
@@ -320,7 +320,9 @@ jQuery.extend({
...
@@ -320,7 +320,9 @@ 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
||
attr
===
"undefined"
||
attr
===
"null"
?
undefined
:
attr
;
return
attr
===
null
||
attr
===
"undefined"
||
attr
===
"null"
?
undefined
:
attr
;
}
}
}
}
},
},
...
@@ -328,10 +330,17 @@ jQuery.extend({
...
@@ -328,10 +330,17 @@ jQuery.extend({
removeAttr
:
function
(
elem
,
name
)
{
removeAttr
:
function
(
elem
,
name
)
{
name
=
jQuery
.
attrFix
[
name
]
||
name
;
name
=
jQuery
.
attrFix
[
name
]
||
name
;
jQuery
.
support
.
getSetAttribute
?
elem
.
removeAttribute
(
name
)
:
if
(
jQuery
.
support
.
getSetAttribute
)
{
elem
.
removeAttribute
(
name
)
}
else
{
// set property to null if getSetAttribute not supported (IE6-7)
// set property to null if getSetAttribute not supported (IE6-7)
// setting className to null makes the class "null"
// setting className to null makes the class "null"
name
===
"className"
?
elem
.
className
=
""
:
elem
.
setAttribute
(
name
,
null
);
if
(
name
===
"className"
)
{
elem
.
className
=
""
}
else
{
elem
.
setAttribute
(
name
,
null
);
}
}
},
},
attrHooks
:
{
attrHooks
:
{
...
@@ -345,10 +354,7 @@ jQuery.extend({
...
@@ -345,10 +354,7 @@ jQuery.extend({
}
}
},
},
// TODO: Check to see if we really need any here.
propFix
:
{},
propFix
:
{
},
prop
:
function
(
elem
,
name
,
value
)
{
prop
:
function
(
elem
,
name
,
value
)
{
...
@@ -403,10 +409,14 @@ if ( !jQuery.support.getSetAttribute ) {
...
@@ -403,10 +409,14 @@ if ( !jQuery.support.getSetAttribute ) {
// Action attribute in ie6/7 returns form objects
// Action attribute in ie6/7 returns form objects
jQuery
.
attrHooks
.
action
=
{
jQuery
.
attrHooks
.
action
=
{
get
:
function
(
elem
)
{
get
:
function
(
elem
)
{
return
elem
.
nodeName
===
"FORM"
?
elem
.
getAttributeNode
(
"action"
).
nodeValue
:
elem
.
getAttribute
(
"action"
);
return
elem
.
nodeName
===
"FORM"
?
elem
.
getAttributeNode
(
"action"
).
nodeValue
:
elem
.
getAttribute
(
"action"
);
},
},
set
:
function
(
elem
,
value
)
{
set
:
function
(
elem
,
value
)
{
elem
.
nodeName
===
"FORM"
?
elem
.
getAttributeNode
(
"action"
).
nodeValue
=
value
:
elem
.
setAttribute
(
"action"
,
value
);
elem
.
nodeName
===
"FORM"
?
elem
.
getAttributeNode
(
"action"
).
nodeValue
=
value
:
elem
.
setAttribute
(
"action"
,
value
);
return
value
;
return
value
;
}
}
};
};
...
...
test/unit/attributes.js
View file @
dbe3b7a9
...
@@ -3,6 +3,31 @@ module("attributes", { teardown: moduleTeardown });
...
@@ -3,6 +3,31 @@ 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
;
});
};
if
(
!
jQuery
.
support
.
getSetAttribute
)
{
test
(
"jQuery.attrFix integrity test"
,
function
()
{
expect
(
1
);
// This must be maintained and equal jQuery.attrFix when appropriate
// 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
.
attrFix
,
"jQuery.attrFix 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'
);
...
...
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