mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Data: Don't expose jQuery.acceptData
jQuery.acceptData is an undocumented internal API that shouldn't be exposed.
(cherry-picked from 224271982e
)
Fixes gh-2555
This commit is contained in:
parent
eac265ccdd
commit
bec2ba2312
@ -2,8 +2,8 @@ define( [
|
||||
"./core",
|
||||
"./var/deletedIds",
|
||||
"./data/support",
|
||||
"./data/accepts"
|
||||
], function( jQuery, deletedIds, support ) {
|
||||
"./data/var/acceptData"
|
||||
], function( jQuery, deletedIds, support, acceptData ) {
|
||||
|
||||
var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
|
||||
rmultiDash = /([A-Z])/g;
|
||||
@ -59,7 +59,7 @@ function isEmptyDataObject( obj ) {
|
||||
}
|
||||
|
||||
function internalData( elem, key, data, pvt /* Internal Use Only */ ) {
|
||||
if ( !jQuery.acceptData( elem ) ) {
|
||||
if ( !acceptData( elem ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ function internalData( elem, key, data, pvt /* Internal Use Only */ ) {
|
||||
}
|
||||
|
||||
function internalRemoveData( elem, key, pvt ) {
|
||||
if ( !jQuery.acceptData( elem ) ) {
|
||||
if ( !acceptData( elem ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
define( [
|
||||
"../core"
|
||||
], function( jQuery ) {
|
||||
define( function() {
|
||||
|
||||
/**
|
||||
* Determines whether an object can have data
|
||||
*/
|
||||
jQuery.acceptData = function( elem ) {
|
||||
return function( elem ) {
|
||||
var noData = jQuery.noData[ ( elem.nodeName + " " ).toLowerCase() ],
|
||||
nodeType = +elem.nodeType || 1;
|
||||
|
||||
@ -17,5 +15,4 @@ jQuery.acceptData = function( elem ) {
|
||||
!noData || noData !== true && elem.getAttribute( "classid" ) === noData;
|
||||
};
|
||||
|
||||
return jQuery.acceptData;
|
||||
} );
|
@ -5,11 +5,12 @@ define( [
|
||||
"./var/hasOwn",
|
||||
"./var/slice",
|
||||
"./event/support",
|
||||
"./data/var/acceptData",
|
||||
|
||||
"./core/init",
|
||||
"./data",
|
||||
"./selector"
|
||||
], function( jQuery, document, rnotwhite, hasOwn, slice, support ) {
|
||||
], function( jQuery, document, rnotwhite, hasOwn, slice, support, acceptData ) {
|
||||
|
||||
var rformElems = /^(?:input|select|textarea)$/i,
|
||||
rkeyEvent = /^key/,
|
||||
@ -391,7 +392,7 @@ jQuery.event = {
|
||||
|
||||
// Native handler
|
||||
handle = ontype && cur[ ontype ];
|
||||
if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
|
||||
if ( handle && handle.apply && acceptData( cur ) ) {
|
||||
event.result = handle.apply( cur, data );
|
||||
if ( event.result === false ) {
|
||||
event.preventDefault();
|
||||
@ -406,7 +407,7 @@ jQuery.event = {
|
||||
if (
|
||||
( !special._default ||
|
||||
special._default.apply( eventPath.pop(), data ) === false
|
||||
) && jQuery.acceptData( elem )
|
||||
) && acceptData( elem )
|
||||
) {
|
||||
|
||||
// Call a native DOM method on the target with the same name name as the event.
|
||||
|
@ -17,16 +17,16 @@ define( [
|
||||
"./manipulation/setGlobalEval",
|
||||
"./manipulation/buildFragment",
|
||||
"./manipulation/support",
|
||||
"./data/var/acceptData",
|
||||
|
||||
"./core/init",
|
||||
"./data/accepts",
|
||||
"./traversing",
|
||||
"./selector",
|
||||
"./event"
|
||||
], function( jQuery, document, concat, push, deletedIds, access,
|
||||
rcheckableType, rtagName, rscriptType, rleadingWhitespace, nodeNames,
|
||||
createSafeFragment, wrapMap, getAll, setGlobalEval,
|
||||
buildFragment, support ) {
|
||||
buildFragment, support, acceptData ) {
|
||||
|
||||
var rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
|
||||
rnoshimcache = new RegExp( "<(?:" + nodeNames + ")[\\s/>]", "i" ),
|
||||
@ -322,7 +322,7 @@ jQuery.extend( {
|
||||
return clone;
|
||||
},
|
||||
|
||||
cleanData: function( elems, /* internal */ acceptData ) {
|
||||
cleanData: function( elems, /* internal */ forceAcceptData ) {
|
||||
var elem, type, id, data,
|
||||
i = 0,
|
||||
internalKey = jQuery.expando,
|
||||
@ -331,7 +331,7 @@ jQuery.extend( {
|
||||
special = jQuery.event.special;
|
||||
|
||||
for ( ; ( elem = elems[ i ] ) != null; i++ ) {
|
||||
if ( acceptData || jQuery.acceptData( elem ) ) {
|
||||
if ( forceAcceptData || acceptData( elem ) ) {
|
||||
|
||||
id = elem[ internalKey ];
|
||||
data = id && cache[ id ];
|
||||
|
@ -224,52 +224,36 @@ QUnit.test( "Data is not being set on comment and text nodes", function( assert
|
||||
|
||||
} );
|
||||
|
||||
QUnit.test( "jQuery.acceptData", function( assert ) {
|
||||
QUnit.test( "acceptData", function( assert ) {
|
||||
assert.expect( 10 );
|
||||
|
||||
var flash, pdf;
|
||||
var flash, pdf, form;
|
||||
|
||||
assert.ok(
|
||||
jQuery.acceptData( document ), "document"
|
||||
);
|
||||
assert.ok(
|
||||
jQuery.acceptData( document.documentElement ), "documentElement"
|
||||
);
|
||||
assert.ok(
|
||||
jQuery.acceptData( {} ), "object"
|
||||
);
|
||||
assert.ok(
|
||||
!jQuery.acceptData( document.createElement( "embed" ) ), "embed"
|
||||
);
|
||||
assert.equal( 42, jQuery( document ).data( "test", 42 ).data( "test" ), "document" );
|
||||
assert.equal( 42, jQuery( document.documentElement ).data( "test", 42 ).data( "test" ), "documentElement" );
|
||||
assert.equal( 42, jQuery( {} ).data( "test", 42 ).data( "test" ), "object" );
|
||||
assert.equal( undefined, jQuery( document.createElement( "embed" ) ).data( "test", 42 ).data( "test" ), "embed" );
|
||||
|
||||
flash = document.createElement( "object" );
|
||||
flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
|
||||
assert.ok(
|
||||
jQuery.acceptData( flash ), "flash"
|
||||
);
|
||||
assert.equal( 42, jQuery( flash ).data( "test", 42 ).data( "test" ), "flash" );
|
||||
|
||||
pdf = document.createElement( "object" );
|
||||
pdf.setAttribute( "classid", "clsid:CA8A9780-280D-11CF-A24D-444553540000" );
|
||||
assert.ok(
|
||||
!jQuery.acceptData( pdf ), "pdf"
|
||||
);
|
||||
assert.equal( undefined, jQuery( pdf ).data( "test", 42 ).data( "test" ), "pdf" );
|
||||
|
||||
assert.ok(
|
||||
!jQuery.acceptData( document.createComment( "" ) ), "comment"
|
||||
);
|
||||
assert.ok(
|
||||
!jQuery.acceptData( document.createTextNode( "" ) ), "text"
|
||||
);
|
||||
assert.ok(
|
||||
!jQuery.acceptData( document.createDocumentFragment() ), "documentFragment"
|
||||
);
|
||||
assert.equal( undefined, jQuery( document.createComment( "" ) ).data( "test", 42 ).data( "test" ), "comment" );
|
||||
assert.equal( undefined, jQuery( document.createTextNode( "" ) ).data( "test", 42 ).data( "test" ), "text" );
|
||||
assert.equal( undefined, jQuery( document.createDocumentFragment() ).data( "test", 42 ).data( "test" ), "documentFragment" );
|
||||
|
||||
assert.ok(
|
||||
jQuery.acceptData(
|
||||
jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ]
|
||||
),
|
||||
"form with aliased DOM properties"
|
||||
);
|
||||
form = jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ];
|
||||
assert.equal( 42, jQuery( form ) .data( "test", 42 ).data( "test" ), "form with aliased DOM properties" );
|
||||
|
||||
// Clean up.
|
||||
jQuery.removeData( document );
|
||||
jQuery.removeData( document.documentElement );
|
||||
jQuery.removeData( flash );
|
||||
jQuery.removeData( form );
|
||||
} );
|
||||
|
||||
// attempting to access the data of an undefined jQuery element should be undefined
|
||||
|
Loading…
Reference in New Issue
Block a user