scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 124  →  ?path2? @ 125
/bower_components/jquery/src/data.js
@@ -1,12 +1,11 @@
define( [
define([
"./core",
"./var/rnotwhite",
"./core/access",
"./data/var/dataPriv",
"./data/var/dataUser"
], function( jQuery, access, dataPriv, dataUser ) {
"./data/var/data_priv",
"./data/var/data_user"
], function( jQuery, rnotwhite, access, data_priv, data_user ) {
 
"use strict";
 
// Implementation Summary
//
// 1. Enforce API surface and semantic compatibility with 1.9.x branch
@@ -18,33 +17,8 @@
// 6. Provide a clear path for implementation upgrade to WeakMap in 2014
 
var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
rmultiDash = /[A-Z]/g;
rmultiDash = /([A-Z])/g;
 
function getData( data ) {
if ( data === "true" ) {
return true;
}
 
if ( data === "false" ) {
return false;
}
 
if ( data === "null" ) {
return null;
}
 
// Only convert to a number if it doesn't change the string
if ( data === +data + "" ) {
return +data;
}
 
if ( rbrace.test( data ) ) {
return JSON.parse( data );
}
 
return data;
}
 
function dataAttr( elem, key, data ) {
var name;
 
@@ -51,16 +25,22 @@
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
if ( data === undefined && elem.nodeType === 1 ) {
name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
data = elem.getAttribute( name );
 
if ( typeof data === "string" ) {
try {
data = getData( data );
} catch ( e ) {}
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
// Only convert to a number if it doesn't change the string
+data + "" === data ? +data :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}
 
// Make sure we set the data so it isn't changed later
dataUser.set( elem, key, data );
data_user.set( elem, key, data );
} else {
data = undefined;
}
@@ -68,31 +48,31 @@
return data;
}
 
jQuery.extend( {
jQuery.extend({
hasData: function( elem ) {
return dataUser.hasData( elem ) || dataPriv.hasData( elem );
return data_user.hasData( elem ) || data_priv.hasData( elem );
},
 
data: function( elem, name, data ) {
return dataUser.access( elem, name, data );
return data_user.access( elem, name, data );
},
 
removeData: function( elem, name ) {
dataUser.remove( elem, name );
data_user.remove( elem, name );
},
 
// TODO: Now that all calls to _data and _removeData have been replaced
// with direct calls to dataPriv methods, these can be deprecated.
// with direct calls to data_priv methods, these can be deprecated.
_data: function( elem, name, data ) {
return dataPriv.access( elem, name, data );
return data_priv.access( elem, name, data );
},
 
_removeData: function( elem, name ) {
dataPriv.remove( elem, name );
data_priv.remove( elem, name );
}
} );
});
 
jQuery.fn.extend( {
jQuery.fn.extend({
data: function( key, value ) {
var i, name, data,
elem = this[ 0 ],
@@ -101,23 +81,23 @@
// Gets all values
if ( key === undefined ) {
if ( this.length ) {
data = dataUser.get( elem );
data = data_user.get( elem );
 
if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
i = attrs.length;
while ( i-- ) {
 
// Support: IE 11 only
// Support: IE11+
// The attrs elements can be null (#14894)
if ( attrs[ i ] ) {
name = attrs[ i ].name;
if ( name.indexOf( "data-" ) === 0 ) {
name = jQuery.camelCase( name.slice( 5 ) );
name = jQuery.camelCase( name.slice(5) );
dataAttr( elem, name, data[ name ] );
}
}
}
dataPriv.set( elem, "hasDataAttrs", true );
data_priv.set( elem, "hasDataAttrs", true );
}
}
 
@@ -126,13 +106,14 @@
 
// Sets multiple values
if ( typeof key === "object" ) {
return this.each( function() {
dataUser.set( this, key );
} );
return this.each(function() {
data_user.set( this, key );
});
}
 
return access( this, function( value ) {
var data;
var data,
camelKey = jQuery.camelCase( key );
 
// The calling jQuery object (element matches) is not empty
// (and therefore has an element appears at this[ 0 ]) and the
@@ -140,10 +121,16 @@
// will result in `undefined` for elem = this[ 0 ] which will
// throw an exception if an attempt to read a data cache is made.
if ( elem && value === undefined ) {
// Attempt to get data from the cache
// with the key as-is
data = data_user.get( elem, key );
if ( data !== undefined ) {
return data;
}
 
// Attempt to get data from the cache
// The key will always be camelCased in Data
data = dataUser.get( elem, key );
// with the key camelized
data = data_user.get( elem, camelKey );
if ( data !== undefined ) {
return data;
}
@@ -150,7 +137,7 @@
 
// Attempt to "discover" the data in
// HTML5 custom data-* attrs
data = dataAttr( elem, key );
data = dataAttr( elem, camelKey, undefined );
if ( data !== undefined ) {
return data;
}
@@ -160,20 +147,32 @@
}
 
// Set the data...
this.each( function() {
this.each(function() {
// First, attempt to store a copy or reference of any
// data that might've been store with a camelCased key.
var data = data_user.get( this, camelKey );
 
// We always store the camelCased key
dataUser.set( this, key, value );
} );
// For HTML5 data-* attribute interop, we have to
// store property names with dashes in a camelCase form.
// This might not apply to all properties...*
data_user.set( this, camelKey, value );
 
// *... In the case of properties that might _actually_
// have dashes, we need to also store a copy of that
// unchanged property.
if ( key.indexOf("-") !== -1 && data !== undefined ) {
data_user.set( this, key, value );
}
});
}, null, value, arguments.length > 1, null, true );
},
 
removeData: function( key ) {
return this.each( function() {
dataUser.remove( this, key );
} );
return this.each(function() {
data_user.remove( this, key );
});
}
} );
});
 
return jQuery;
} );
});