aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.js
diff options
context:
space:
mode:
authorAlexis Abril <alexis.abril@gmail.com>2011-04-10 15:17:00 -0400
committerDave Methvin <dave.methvin@gmail.com>2011-04-10 15:17:00 -0400
commit8c318bf41412d493604beed1879c4a273ff05a57 (patch)
treebb5fa94183bc580309749911b8a5dae516ccc825 /src/data.js
parent8c40c00fac2f30fa0804ae8097642636f9718ddd (diff)
downloadjquery-8c318bf41412d493604beed1879c4a273ff05a57.tar.gz
jquery-8c318bf41412d493604beed1879c4a273ff05a57.zip
Fixes #7328. When getting data- attributes, after-cap any embedded dashes per the W3C HTML5 spec.
Diffstat (limited to 'src/data.js')
-rw-r--r--src/data.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/data.js b/src/data.js
index 2d53a7104..c2fd558f0 100644
--- a/src/data.js
+++ b/src/data.js
@@ -1,6 +1,7 @@
(function( jQuery ) {
-var rbrace = /^(?:\{.*\}|\[.*\])$/;
+var rbrace = /^(?:\{.*\}|\[.*\])$/,
+ rmultiDash = /([a-z])([A-Z])/g;
jQuery.extend({
cache: {},
@@ -223,12 +224,13 @@ jQuery.fn.extend({
data = jQuery.data( this[0] );
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++ ) {
name = attr[i].name;
if ( name.indexOf( "data-" ) === 0 ) {
- name = name.substr( 5 );
+ name = jQuery.camelCase( name.substring(5) );
+
dataAttr( this[0], name, data[ name ] );
}
}
@@ -282,7 +284,9 @@ function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
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" ) {
try {