MCPcopy Create free account
hub / github.com/JsAaron/jQuery / internalData

Function internalData

2.1.1/test/jquery-1.11.1.js:3683–3770  ·  view source on GitHub ↗
( elem, name, data, pvt /* Internal Use Only */ )

Source from the content-addressed store, hash-verified

3681}
3682
3683function internalData( elem, name, data, pvt /* Internal Use Only */ ) {
3684 if ( !jQuery.acceptData( elem ) ) {
3685 return;
3686 }
3687
3688 var ret, thisCache,
3689 internalKey = jQuery.expando,
3690
3691 // We have to handle DOM nodes and JS objects differently because IE6-7
3692 // can't GC object references properly across the DOM-JS boundary
3693 isNode = elem.nodeType,
3694
3695 // Only DOM nodes need the global jQuery cache; JS object data is
3696 // attached directly to the object so GC can occur automatically
3697 cache = isNode ? jQuery.cache : elem,
3698
3699 // Only defining an ID for JS objects if its cache already exists allows
3700 // the code to shortcut on the same path as a DOM node with no cache
3701 id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey;
3702
3703 // Avoid doing any more work than we need to when trying to get data on an
3704 // object that has no data at all
3705 if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) {
3706 return;
3707 }
3708
3709 if ( !id ) {
3710 // Only DOM nodes need a new unique ID for each element since their data
3711 // ends up in the global cache
3712 if ( isNode ) {
3713 id = elem[ internalKey ] = deletedIds.pop() || jQuery.guid++;
3714 } else {
3715 id = internalKey;
3716 }
3717 }
3718
3719 if ( !cache[ id ] ) {
3720 // Avoid exposing jQuery metadata on plain JS objects when the object
3721 // is serialized using JSON.stringify
3722 cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
3723 }
3724
3725 // An object can be passed to jQuery.data instead of a key/value pair; this gets
3726 // shallow copied over onto the existing cache
3727 if ( typeof name === "object" || typeof name === "function" ) {
3728 if ( pvt ) {
3729 cache[ id ] = jQuery.extend( cache[ id ], name );
3730 } else {
3731 cache[ id ].data = jQuery.extend( cache[ id ].data, name );
3732 }
3733 }
3734
3735 thisCache = cache[ id ];
3736
3737 // jQuery data() is stored in a separate object inside the object's internal data
3738 // cache in order to avoid key collisions between internal data and user-defined
3739 // data.
3740 if ( !pvt ) {

Callers 1

jquery-1.11.1.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected