mirror of
https://github.com/jquery/jquery.git
synced 2024-10-05 11:34:18 +00:00
Bug in rmultidash. Fixes #10194
This commit is contained in:
parent
4bc691a1c3
commit
8e8fa6dc1a
@ -1,7 +1,7 @@
|
|||||||
(function( jQuery ) {
|
(function( jQuery ) {
|
||||||
|
|
||||||
var rbrace = /^(?:\{.*\}|\[.*\])$/,
|
var rbrace = /^(?:\{.*\}|\[.*\])$/,
|
||||||
rmultiDash = /([a-z])([A-Z])/g;
|
rmultiDash = /([A-Z])/g;
|
||||||
|
|
||||||
jQuery.extend({
|
jQuery.extend({
|
||||||
cache: {},
|
cache: {},
|
||||||
@ -316,7 +316,8 @@ 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 ) {
|
||||||
var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
|
|
||||||
|
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
|
||||||
|
|
||||||
data = elem.getAttribute( name );
|
data = elem.getAttribute( name );
|
||||||
|
|
||||||
|
@ -488,23 +488,26 @@ if (window.JSON && window.JSON.stringify) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("jQuery.data should follow html5 specification regarding camel casing", function() {
|
test("jQuery.data should follow html5 specification regarding camel casing", function() {
|
||||||
expect(8);
|
expect(10);
|
||||||
|
|
||||||
var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
|
var div = jQuery("<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
|
||||||
.prependTo("body");
|
.prependTo("body");
|
||||||
|
|
||||||
equals(div.data().foo, "a", "Verify single word data-* key");
|
equal( div.data().wTF, "ftw", "Verify single letter data-* key" );
|
||||||
equals(div.data().fooBar, "b", "Verify multiple word data-* key");
|
equal( div.data().bigALittleA, "bouncing-b", "Verify single letter mixed data-* key" );
|
||||||
equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key");
|
|
||||||
|
|
||||||
equals(div.data("foo"), "a", "Verify single word data-* key");
|
equal( div.data().foo, "a", "Verify single word data-* key" );
|
||||||
equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
|
equal( div.data().fooBar, "b", "Verify multiple word data-* key" );
|
||||||
equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");
|
equal( div.data().fooBarBaz, "c", "Verify multiple word data-* key" );
|
||||||
|
|
||||||
|
equal( div.data("foo"), "a", "Verify single word data-* key" );
|
||||||
|
equal( div.data("fooBar"), "b", "Verify multiple word data-* key" );
|
||||||
|
equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" );
|
||||||
|
|
||||||
div.data("foo-bar", "d");
|
div.data("foo-bar", "d");
|
||||||
|
|
||||||
equals(div.data("fooBar"), "d", "Verify updated data-* key");
|
equal( div.data("fooBar"), "d", "Verify updated data-* key" );
|
||||||
equals(div.data("foo-bar"), "d", "Verify updated data-* key");
|
equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
|
||||||
|
|
||||||
div.remove();
|
div.remove();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user