-var removeExpando = function( elem ) {
- delete elem[ expando ];
-};
-
-try {
- var div = document.createElement("div");
- div[ expando ] = true;
- delete div[ expando ];
-
-} catch( e ) {
- // IE has trouble directly removing the expando
- // but it's ok with using removeAttribute
- removeExpando = function( elem ) {
- if ( elem.removeAttribute ) {
- elem.removeAttribute( expando );
+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 );
+
+ if ( typeof data === "string" ) {
+ try {
+ data = data === "true" ? true :
+ data === "false" ? false :
+ data === "null" ? null :
+ !jQuery.isNaN( data ) ? parseFloat( data ) :
+ rbrace.test( data ) ? jQuery.parseJSON( data ) :
+ data;
+ } catch( e ) {}
+
+ // Make sure we set the data so it isn't changed later
+ jQuery.data( elem, key, data );
+
+ } else {
+ data = undefined;