data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
- !isNaN( data ) ? parseFloat( data ) :
+ /\d/.test( data ) && !isNaN( data ) ? parseFloat( data ) :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}
});
test("data-* attributes", function() {
- expect(25);
+ expect(27);
var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>");
.attr("data-pointbad2", "-.")
.attr("data-badjson", "{123}")
.attr("data-badjson2", "[abc]")
+ .attr("data-empty", "")
+ .attr("data-space", " ")
.attr("data-null", "null")
.attr("data-string", "test");
strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute");
strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute");
strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute");
+ strictEqual( child.data('empty'), "", "Empty string read from attribute");
+ strictEqual( child.data('space'), " ", "Empty string read from attribute");
strictEqual( child.data('null'), null, "Primitive null read from attribute");
strictEqual( child.data('string'), "test", "Typical string read from attribute");