Skip to content

Commit 76db8a9

Browse files
committed
Allow data to be bound to Flash objects (but still stopping short of attaching to applets. Fixes #6121.
1 parent f10057b commit 76db8a9

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/data.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ jQuery.extend({
1717
// attempt to add expando properties to them.
1818
noData: {
1919
"embed": true,
20-
"object": true,
20+
// Ban all objects except for Flash (which handle expandos)
21+
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
2122
"applet": true
2223
},
2324

2425
data: function( elem, name, data ) {
25-
if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
26+
if ( !jQuery.acceptData( elem ) ) {
2627
return;
2728
}
2829

@@ -85,7 +86,7 @@ jQuery.extend({
8586
},
8687

8788
removeData: function( elem, name ) {
88-
if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
89+
if ( !jQuery.acceptData( elem ) ) {
8990
return;
9091
}
9192

@@ -126,6 +127,19 @@ jQuery.extend({
126127
delete cache[ id ];
127128
}
128129
}
130+
},
131+
132+
// A method for determining if a DOM node can handle the data expando
133+
acceptData: function( elem ) {
134+
if ( elem.nodeName ) {
135+
match = jQuery.noData[ elem.nodeName.toLowerCase() ];
136+
137+
if ( match ) {
138+
return !(match === true || elem.getAttribute("classid") !== match);
139+
}
140+
}
141+
142+
return true;
129143
}
130144
});
131145

test/unit/data.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ test("expando", function(){
2424
equals( id.foo, "bar", "jQuery.data worked correctly" );
2525
});
2626

27+
test("jQuery.acceptData", function() {
28+
expect(7);
29+
30+
ok( jQuery.acceptData( document ), "document" );
31+
ok( jQuery.acceptData( document.documentElement ), "documentElement" );
32+
ok( jQuery.acceptData( {} ), "object" );
33+
ok( !jQuery.acceptData( document.createElement("embed") ), "embed" );
34+
ok( !jQuery.acceptData( document.createElement("applet") ), "applet" );
35+
36+
var flash = document.createElement("object");
37+
flash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
38+
ok( jQuery.acceptData( flash ), "flash" );
39+
40+
var applet = document.createElement("object");
41+
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
42+
ok( !jQuery.acceptData( applet ), "applet" );
43+
});
44+
2745
test("jQuery.data", function() {
2846
expect(13);
2947
var div = document.createElement("div");

0 commit comments

Comments
 (0)