Updates to data.js re-write to pass events and manipulation (full pass in local test runs)

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
Rick Waldron 2012-12-31 16:20:35 -05:00
parent d1de3000c6
commit b9cdc4136b
3 changed files with 43 additions and 38 deletions

View File

@ -1,4 +1,4 @@
var user, priv, var user, priv, data_user, data_priv,
rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g; rmultiDash = /([A-Z])/g;
@ -131,13 +131,14 @@ Data.prototype = {
// This will be used by remove() in manipulation to sever // This will be used by remove() in manipulation to sever
// remaining references to node objects. One day we'll replace the dual // remaining references to node objects. One day we'll replace the dual
// arrays with a WeakMap and this won't be an issue. // arrays with a WeakMap and this won't be an issue.
// function data_discard( owner ) { function data_discard( owner ) {
// user.discard( owner ); user.discard( owner );
// priv.discard( owner ); priv.discard( owner );
// } }
user = new Data(); // These may used throughout the jQuery core codebase
priv = new Data(); user = data_user = new Data();
priv = data_priv = new Data();
jQuery.extend({ jQuery.extend({
@ -198,7 +199,7 @@ jQuery.fn.extend({
dataAttr( elem, name, data[ name ] ); dataAttr( elem, name, data[ name ] );
} }
} }
priv.set( elem, { hasDataAttrs: true }); priv.set( elem, "hasDataAttrs", true );
} }
} }

View File

@ -16,7 +16,7 @@ jQuery.event = {
t = 0; t = 0;
// Don't attach events to noData or text/comment nodes (allow plain objects tho) // Don't attach events to noData or text/comment nodes (allow plain objects tho)
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) { if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = data_priv.get( elem )) ) {
return; return;
} }
@ -124,7 +124,7 @@ jQuery.event = {
var tns, type, origType, namespaces, origCount, var tns, type, origType, namespaces, origCount,
j, events, special, eventType, handleObj, j, events, special, eventType, handleObj,
t = 0, t = 0,
elemData = jQuery.hasData( elem ) && jQuery._data( elem ); elemData = data_priv.hasData( elem ) && data_priv.get( elem );
if ( !elemData || !(events = elemData.events) ) { if ( !elemData || !(events = elemData.events) ) {
return; return;

View File

@ -327,7 +327,7 @@ jQuery.fn.extend({
for ( i = 0; i < hasScripts; i++ ) { for ( i = 0; i < hasScripts; i++ ) {
node = scripts[ i ]; node = scripts[ i ];
if ( rscriptType.test( node.type || "" ) && if ( rscriptType.test( node.type || "" ) &&
!jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) { !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
if ( node.src ) { if ( node.src ) {
// Hope ajax is available... // Hope ajax is available...
@ -514,20 +514,16 @@ jQuery.extend({
}, },
cleanData: function( elems, /* internal */ acceptData ) { cleanData: function( elems, /* internal */ acceptData ) {
var id, data, elem, type, var data, elem, type,
l = elems.length, l = elems.length,
i = 0, i = 0,
internalKey = jQuery.expando,
cache = jQuery.cache,
special = jQuery.event.special; special = jQuery.event.special;
for ( ; i < l; i++ ) { for ( ; i < l; i++ ) {
elem = elems[ i ]; elem = elems[ i ];
if ( acceptData || jQuery.acceptData( elem ) ) { if ( acceptData || jQuery.acceptData( elem ) ) {
data = data_priv.access( elem );
id = elem[ internalKey ];
data = id && cache[ id ];
if ( data ) { if ( data ) {
for ( type in data.events ) { for ( type in data.events ) {
@ -539,14 +535,12 @@ jQuery.extend({
jQuery.removeEvent( elem, type, data.handle ); jQuery.removeEvent( elem, type, data.handle );
} }
} }
// Remove cache only if it was not already removed by jQuery.event.remove
if ( cache[ id ] ) {
delete cache[ id ];
delete elem[ internalKey ];
}
} }
} }
// Discard any remaining `private` and `user` data
// (Splices the data objects out of the internal cache arrays)
data_discard( elem );
} }
} }
}); });
@ -580,35 +574,45 @@ function setGlobalEval( elems, refElements ) {
i = 0; i = 0;
for ( ; i < l; i++ ) { for ( ; i < l; i++ ) {
jQuery._data( elems[ i ], "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); data_priv.set(
elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
);
} }
} }
function cloneCopyEvent( src, dest ) { function cloneCopyEvent( src, dest ) {
var i, l, type, pOld, pCur, uOld, uCur, events;
if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { if ( dest.nodeType !== 1 ) {
return; return;
} }
var i, l, type, // 1. Copy private data: events, handlers, etc.
oldData = jQuery._data( src ), if ( data_priv.hasData( src ) ) {
curData = jQuery._data( dest, oldData ), pOld = data_priv.access( src );
events = oldData.events; pCur = jQuery.extend( {}, pOld );
events = pOld.events;
if ( events ) { data_priv.set( dest, pCur );
delete curData.handle;
curData.events = {};
for ( type in events ) { if ( events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) { delete pCur.handle;
jQuery.event.add( dest, type, events[ type ][ i ] ); pCur.events = {};
for ( type in events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( dest, type, events[ type ][ i ] );
}
} }
} }
} }
// make the cloned public data object a copy from the original // 2. Copy user data
if ( curData.data ) { if ( data_user.hasData( src ) ) {
curData.data = jQuery.extend( {}, curData.data ); uOld = data_user.access( src );
uCur = jQuery.extend( {}, uOld );
data_user.set( dest, uCur );
} }
} }