mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
Pull data-* attributes into .data(). Original code by Andrée Hasson and Paul Irish. Fixes #6921.
This commit is contained in:
18
src/data.js
18
src/data.js
@@ -1,6 +1,7 @@
|
||||
(function( jQuery ) {
|
||||
|
||||
var windowData = {};
|
||||
var windowData = {},
|
||||
rnum = /^-?[0-9.]$/;
|
||||
|
||||
jQuery.extend({
|
||||
cache: {},
|
||||
@@ -142,8 +143,23 @@ jQuery.fn.extend({
|
||||
if ( value === undefined ) {
|
||||
var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
|
||||
|
||||
// Try to fetch any internally stored data first
|
||||
if ( data === undefined && this.length ) {
|
||||
data = jQuery.data( this[0], key );
|
||||
|
||||
// If nothing was found internally, try to fetch any
|
||||
// data from the HTML5 data-* attribute
|
||||
if ( data === undefined && this[0].nodeType === 1 ) {
|
||||
data = this[0].getAttribute( "data-" + key );
|
||||
|
||||
if ( data != null ) {
|
||||
data = data === "true" ? true :
|
||||
data === "false" ? false :
|
||||
data === "null" ? null :
|
||||
rnum.test( data ) ? parseFloat( data ) :
|
||||
data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data === undefined && parts[1] ?
|
||||
|
||||
Reference in New Issue
Block a user