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
96bb57d4
Commit
96bb57d4
authored
Feb 10, 2012
by
Sindre Sorhus
Committed by
Dave Methvin
Feb 10, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #11309. Recognize hexadecimal in data attributes.
parent
974e4afb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
data.js
src/data.js
+1
-1
data.js
test/unit/data.js
+3
-1
No files found.
src/data.js
View file @
96bb57d4
...
...
@@ -333,7 +333,7 @@ function dataAttr( elem, key, data ) {
data
=
data
===
"true"
?
true
:
data
===
"false"
?
false
:
data
===
"null"
?
null
:
jQuery
.
isNumeric
(
data
)
?
parseFloat
(
data
)
:
jQuery
.
isNumeric
(
data
)
?
+
data
:
rbrace
.
test
(
data
)
?
jQuery
.
parseJSON
(
data
)
:
data
;
}
catch
(
e
)
{}
...
...
test/unit/data.js
View file @
96bb57d4
...
...
@@ -298,7 +298,7 @@ test(".data(String) and .data(String, Object)", function() {
});
test
(
"data-* attributes"
,
function
()
{
expect
(
3
7
);
expect
(
3
8
);
var
div
=
jQuery
(
"<div>"
),
child
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
),
dummy
=
jQuery
(
"<div data-myobj='old data' data-ignored=
\"
DOM
\"
data-other='test'></div>"
);
...
...
@@ -356,6 +356,7 @@ test("data-* attributes", function() {
.
attr
(
"data-five"
,
"5"
)
.
attr
(
"data-point"
,
"5.5"
)
.
attr
(
"data-pointe"
,
"5.5E3"
)
.
attr
(
"data-hexadecimal"
,
"0x42"
)
.
attr
(
"data-pointbad"
,
"5..5"
)
.
attr
(
"data-pointbad2"
,
"-."
)
.
attr
(
"data-badjson"
,
"{123}"
)
...
...
@@ -370,6 +371,7 @@ test("data-* attributes", function() {
strictEqual
(
child
.
data
(
"five"
),
5
,
"Primitive number read from attribute"
);
strictEqual
(
child
.
data
(
"point"
),
5.5
,
"Primitive number read from attribute"
);
strictEqual
(
child
.
data
(
"pointe"
),
5500
,
"Primitive number read from attribute"
);
strictEqual
(
child
.
data
(
"hexadecimal"
),
66
,
"Hexadecimal number read from attribute"
);
strictEqual
(
child
.
data
(
"pointbad"
),
"5..5"
,
"Bad number read from attribute"
);
strictEqual
(
child
.
data
(
"pointbad2"
),
"-."
,
"Bad number read from attribute"
);
strictEqual
(
child
.
data
(
"badjson"
),
"{123}"
,
"Bad number read from 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