| 20 | rmultiDash = /([A-Z])/g; |
| 21 | |
| 22 | function dataAttr( elem, key, data ) { |
| 23 | var name; |
| 24 | |
| 25 | // If nothing was found internally, try to fetch any |
| 26 | // data from the HTML5 data-* attribute |
| 27 | if ( data === undefined && elem.nodeType === 1 ) { |
| 28 | name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); |
| 29 | data = elem.getAttribute( name ); |
| 30 | |
| 31 | if ( typeof data === "string" ) { |
| 32 | try { |
| 33 | data = data === "true" ? true : |
| 34 | data === "false" ? false : |
| 35 | data === "null" ? null : |
| 36 | // Only convert to a number if it doesn't change the string |
| 37 | +data + "" === data ? +data : |
| 38 | rbrace.test( data ) ? jQuery.parseJSON( data ) : |
| 39 | data; |
| 40 | } catch( e ) {} |
| 41 | |
| 42 | // Make sure we set the data so it isn't changed later |
| 43 | data_user.set( elem, key, data ); |
| 44 | } else { |
| 45 | data = undefined; |
| 46 | } |
| 47 | } |
| 48 | return data; |
| 49 | } |
| 50 | |
| 51 | jQuery.extend({ |
| 52 | hasData: function( elem ) { |