aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2010-09-21 00:51:45 -0400
committerJohn Resig <jeresig@gmail.com>2010-09-21 00:51:45 -0400
commite7c2d3b45bf0e8fbe9d7c9316b6c5adb2c019ea3 (patch)
tree048df322e73af570f47d1e16a0477b66d3cffc37 /src/data.js
parentae9df1412c41b1ae676d3808c323b0f01e0b0600 (diff)
downloadjquery-e7c2d3b45bf0e8fbe9d7c9316b6c5adb2c019ea3.tar.gz
jquery-e7c2d3b45bf0e8fbe9d7c9316b6c5adb2c019ea3.zip
Added in support for basic JSON object parsing of data- attributes.
Diffstat (limited to 'src/data.js')
-rw-r--r--src/data.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/data.js b/src/data.js
index dda1683a5..44ad0c49e 100644
--- a/src/data.js
+++ b/src/data.js
@@ -1,7 +1,8 @@
(function( jQuery ) {
var windowData = {},
- rnum = /^-?\d+(?:\.\d+)$/;
+ rnum = /^-?\d+(?:\.\d+)$/,
+ rbrace = /^{.*}$/;
jQuery.extend({
cache: {},
@@ -153,11 +154,14 @@ jQuery.fn.extend({
data = this[0].getAttribute( "data-" + key );
if ( typeof data === "string" ) {
- data = data === "true" ? true :
- data === "false" ? false :
- data === "null" ? null :
- rnum.test( data ) ? parseFloat( data ) :
- data;
+ try {
+ data = data === "true" ? true :
+ data === "false" ? false :
+ data === "null" ? null :
+ rnum.test( data ) ? parseFloat( data ) :
+ rbrace.test( data ) ? jQuery.parseJSON( data ) :
+ data;
+ } catch( e ) {}
} else {
data = undefined;