MCPcopy
hub / github.com/nbubna/store / internalData

Function internalData

libs/jquery/jquery.js:1525–1617  ·  view source on GitHub ↗
( elem, name, data, pvt /* Internal Use Only */ )

Source from the content-addressed store, hash-verified

1523 rmultiDash = /([A-Z])/g;
1524
1525function internalData( elem, name, data, pvt /* Internal Use Only */ ){
1526 if ( !jQuery.acceptData( elem ) ) {
1527 return;
1528 }
1529
1530 var thisCache, ret,
1531 internalKey = jQuery.expando,
1532 getByName = typeof name === "string",
1533
1534 // We have to handle DOM nodes and JS objects differently because IE6-7
1535 // can't GC object references properly across the DOM-JS boundary
1536 isNode = elem.nodeType,
1537
1538 // Only DOM nodes need the global jQuery cache; JS object data is
1539 // attached directly to the object so GC can occur automatically
1540 cache = isNode ? jQuery.cache : elem,
1541
1542 // Only defining an ID for JS objects if its cache already exists allows
1543 // the code to shortcut on the same path as a DOM node with no cache
1544 id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey;
1545
1546 // Avoid doing any more work than we need to when trying to get data on an
1547 // object that has no data at all
1548 if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && getByName && data === undefined ) {
1549 return;
1550 }
1551
1552 if ( !id ) {
1553 // Only DOM nodes need a new unique ID for each element since their data
1554 // ends up in the global cache
1555 if ( isNode ) {
1556 elem[ internalKey ] = id = core_deletedIds.pop() || jQuery.guid++;
1557 } else {
1558 id = internalKey;
1559 }
1560 }
1561
1562 if ( !cache[ id ] ) {
1563 cache[ id ] = {};
1564
1565 // Avoids exposing jQuery metadata on plain JS objects when the object
1566 // is serialized using JSON.stringify
1567 if ( !isNode ) {
1568 cache[ id ].toJSON = jQuery.noop;
1569 }
1570 }
1571
1572 // An object can be passed to jQuery.data instead of a key/value pair; this gets
1573 // shallow copied over onto the existing cache
1574 if ( typeof name === "object" || typeof name === "function" ) {
1575 if ( pvt ) {
1576 cache[ id ] = jQuery.extend( cache[ id ], name );
1577 } else {
1578 cache[ id ].data = jQuery.extend( cache[ id ].data, name );
1579 }
1580 }
1581
1582 thisCache = cache[ id ];

Callers 1

jquery.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…