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
8c318bf4
Commit
8c318bf4
authored
Apr 10, 2011
by
Alexis Abril
Committed by
Dave Methvin
Apr 10, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #7328. When getting data- attributes, after-cap any embedded dashes per the W3C HTML5 spec.
parent
8c40c00f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
data.js
src/data.js
+8
-4
data.js
test/unit/data.js
+18
-1
No files found.
src/data.js
View file @
8c318bf4
(
function
(
jQuery
)
{
(
function
(
jQuery
)
{
var
rbrace
=
/^
(?:\{
.*
\}
|
\[
.*
\])
$/
;
var
rbrace
=
/^
(?:\{
.*
\}
|
\[
.*
\])
$/
,
rmultiDash
=
/
([
a-z
])([
A-Z
])
/g
;
jQuery
.
extend
({
jQuery
.
extend
({
cache
:
{},
cache
:
{},
...
@@ -223,12 +224,13 @@ jQuery.fn.extend({
...
@@ -223,12 +224,13 @@ jQuery.fn.extend({
data
=
jQuery
.
data
(
this
[
0
]
);
data
=
jQuery
.
data
(
this
[
0
]
);
if
(
this
[
0
].
nodeType
===
1
)
{
if
(
this
[
0
].
nodeType
===
1
)
{
var
attr
=
this
[
0
].
attributes
,
name
;
var
attr
=
this
[
0
].
attributes
,
name
;
for
(
var
i
=
0
,
l
=
attr
.
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
attr
.
length
;
i
<
l
;
i
++
)
{
name
=
attr
[
i
].
name
;
name
=
attr
[
i
].
name
;
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
name
=
name
.
substr
(
5
);
name
=
jQuery
.
camelCase
(
name
.
substring
(
5
)
);
dataAttr
(
this
[
0
],
name
,
data
[
name
]
);
dataAttr
(
this
[
0
],
name
,
data
[
name
]
);
}
}
}
}
...
@@ -282,7 +284,9 @@ function dataAttr( elem, key, data ) {
...
@@ -282,7 +284,9 @@ function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
// data from the HTML5 data-* attribute
if
(
data
===
undefined
&&
elem
.
nodeType
===
1
)
{
if
(
data
===
undefined
&&
elem
.
nodeType
===
1
)
{
data
=
elem
.
getAttribute
(
"data-"
+
key
);
name
=
"data-"
+
key
.
replace
(
rmultiDash
,
"$1-$2"
).
toLowerCase
();
data
=
elem
.
getAttribute
(
name
);
if
(
typeof
data
===
"string"
)
{
if
(
typeof
data
===
"string"
)
{
try
{
try
{
...
...
test/unit/data.js
View file @
8c318bf4
...
@@ -485,4 +485,21 @@ if (window.JSON && window.JSON.stringify) {
...
@@ -485,4 +485,21 @@ if (window.JSON && window.JSON.stringify) {
equals
(
JSON
.
stringify
(
obj
),
'{"foo":"bar"}'
,
"Expando is hidden from JSON.stringify"
);
equals
(
JSON
.
stringify
(
obj
),
'{"foo":"bar"}'
,
"Expando is hidden from JSON.stringify"
);
});
});
}
}
\ No newline at end of file
test
(
"jQuery.data should follow html5 specification regarding camel casing"
,
function
()
{
expect
(
6
);
var
div
=
jQuery
(
"<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>"
)
.
prependTo
(
"body"
);
equals
(
div
.
data
().
foo
,
"a"
,
"Verify single word data-* key"
);
equals
(
div
.
data
().
fooBar
,
"b"
,
"Verify multiple word data-* key"
);
equals
(
div
.
data
().
fooBarBaz
,
"c"
,
"Verify multiple word data-* key"
);
equals
(
div
.
data
(
"foo"
),
"a"
,
"Verify single word data-* key"
);
equals
(
div
.
data
(
"fooBar"
),
"b"
,
"Verify multiple word data-* key"
);
equals
(
div
.
data
(
"fooBarBaz"
),
"c"
,
"Verify multiple word data-* key"
);
div
.
remove
();
});
\ No newline at end of file
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