diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2013-02-03 15:27:55 -0500 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2013-02-03 15:27:55 -0500 |
commit | 7f94a5cc3a167a710576c008da2c186a98ce2dd4 (patch) | |
tree | d4a3e8ec0e4385d305676b74a663de3017c48438 /src/manipulation.js | |
parent | ed0e2d1e8a5005a80d0dd127dc4019f696471ad6 (diff) | |
download | jquery-7f94a5cc3a167a710576c008da2c186a98ce2dd4.tar.gz jquery-7f94a5cc3a167a710576c008da2c186a98ce2dd4.zip |
2.0: Rewrite data.js (Incl. event, manipulation, tests)
Diffstat (limited to 'src/manipulation.js')
-rw-r--r-- | src/manipulation.js | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index 708d7851d..d50ebddf7 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -328,7 +328,7 @@ jQuery.fn.extend({ for ( i = 0; i < hasScripts; i++ ) { node = scripts[ i ]; 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 ) { // Hope ajax is available... @@ -511,11 +511,9 @@ jQuery.extend({ }, cleanData: function( elems, /* internal */ acceptData ) { - var id, data, elem, type, + var data, elem, type, l = elems.length, i = 0, - internalKey = jQuery.expando, - cache = jQuery.cache, special = jQuery.event.special; for ( ; i < l; i++ ) { @@ -523,8 +521,7 @@ jQuery.extend({ if ( acceptData || jQuery.acceptData( elem ) ) { - id = elem[ internalKey ]; - data = id && cache[ id ]; + data = data_priv.access( elem ); if ( data ) { for ( type in data.events ) { @@ -536,14 +533,10 @@ jQuery.extend({ 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 + data_discard( elem ); } } }); @@ -576,38 +569,49 @@ function setGlobalEval( elems, refElements ) { i = 0; 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 ) { + var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events; - if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { + if ( dest.nodeType !== 1 ) { return; } - var i, l, type, - oldData = jQuery._data( src ), - curData = jQuery._data( dest, oldData ), - events = oldData.events; + // 1. Copy private data: events, handlers, etc. + if ( data_priv.hasData( src ) ) { + pdataOld = data_priv.access( src ); + pdataCur = jQuery.extend( {}, pdataOld ); + events = pdataOld.events; + + data_priv.set( dest, pdataCur ); - if ( events ) { - delete curData.handle; - curData.events = {}; + if ( events ) { + delete pdataCur.handle; + pdataCur.events = {}; - for ( type in events ) { - for ( i = 0, l = events[ type ].length; i < l; i++ ) { - jQuery.event.add( dest, type, events[ type ][ i ] ); + 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 - if ( curData.data ) { - curData.data = jQuery.extend( {}, curData.data ); + // 2. Copy user data + if ( data_user.hasData( src ) ) { + udataOld = data_user.access( src ); + udataCur = jQuery.extend( {}, udataOld ); + + data_user.set( dest, udataCur ); } } + function getAll( context, tag ) { var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) : context.querySelectorAll ? context.querySelectorAll( tag || "*" ) : |