rescape = /[^\w\s.|`]/g,
fcleanup = function( nm ) {
return nm.replace(rescape, "\\$&");
- },
- eventKey = "events";
+ };
/*
* A number of helper functions used for managing events.
return;
}
- var events = elemData[ eventKey ],
+ var events = elemData.events,
eventHandle = elemData.handle;
- if ( typeof events === "function" ) {
- // On plain objects events is a fn that holds the the data
- // which prevents this data from being JSON serialized
- // the function does not need to be called, it just contains the data
- eventHandle = events.handle;
- events = events.events;
-
- } else if ( !events ) {
- if ( !elem.nodeType ) {
- // On plain objects, create a fn that acts as the holder
- // of the values to avoid JSON serialization of event data
- elemData[ eventKey ] = elemData = function(){};
- }
-
+ if ( !events ) {
elemData.events = events = {};
}
var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
- events = elemData && elemData[ eventKey ];
+ events = elemData && elemData.events;
if ( !elemData || !events ) {
return;
}
- if ( typeof events === "function" ) {
- elemData = events;
- events = events.events;
- }
-
// types is actually an event object here
if ( types && types.type ) {
handler = types.handler;
delete elemData.events;
delete elemData.handle;
- if ( typeof elemData === "function" ) {
- jQuery.removeData( elem, eventKey, true );
-
- } else if ( jQuery.isEmptyObject( elemData ) ) {
+ if ( jQuery.isEmptyObject( elemData ) ) {
jQuery.removeData( elem, undefined, true );
}
}
// points to jQuery.expando
var internalKey = jQuery.expando,
internalCache = this[ internalKey ];
- if ( internalCache && internalCache.events && internalCache.events[type] ) {
+ if ( internalCache && internalCache.events && internalCache.events[ type ] ) {
jQuery.event.trigger( event, data, internalCache.handle.elem );
}
});
event.currentTarget = elem;
// Trigger the event, it is assumed that "handle" is a function
- var handle = elem.nodeType ?
- jQuery._data( elem, "handle" ) :
- (jQuery._data( elem, eventKey ) || {}).handle;
+ var handle = jQuery._data( elem, "handle" );
if ( handle ) {
handle.apply( elem, data );
event.namespace = event.namespace || namespace_sort.join(".");
- events = jQuery._data(this, eventKey);
-
- if ( typeof events === "function" ) {
- events = events.events;
- }
+ events = jQuery._data(this, "events");
handlers = (events || {})[ event.type ];
// Events bubbling up the document may have been marked as prevented
// by a handler lower down the tree; reflect the correct value.
- this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
+ this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;
// Event type
jQuery.event.special[ fix ] = {
setup: function() {
this.addEventListener( orig, handler, true );
- },
- teardown: function() {
+ },
+ teardown: function() {
this.removeEventListener( orig, handler, true );
}
};
var stop, maxLevel, related, match, handleObj, elem, j, i, l, data, close, namespace, ret,
elems = [],
selectors = [],
- events = jQuery._data( this, eventKey );
-
- if ( typeof events === "function" ) {
- events = events.events;
- }
+ events = jQuery._data( this, "events" );
// Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911)
if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) {
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
var dataObj = jQuery.data(elem);
- equals( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
+ equals( typeof dataObj, elem.nodeType ? "object" : "function", "Calling data with no args gives us a data object reference" );
strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
equals( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" };
- deepEqual( jQuery(obj).data(), {}, "Retrieve data object from a wrapped JS object (#7524)" );
-})
+ jQuery(obj).data("foo", "baz");
+
+ var dataObj = jQuery.extend(true, {}, jQuery(obj).data());
+
+ deepEqual( dataObj, { foo: "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
+});
test(".data(String) and .data(String, Object)", function() {
expect(29);
div.removeData("test.foo");
equals( div.data("test.foo"), undefined, "Make sure data is intact" );
-});
\ No newline at end of file
+});
+
+if (window.JSON && window.JSON.stringify) {
+ test("JSON serialization (#8108)", function () {
+ expect(1);
+
+ var obj = { foo: "bar" };
+ jQuery.data(obj, "hidden", true);
+
+ equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
+ });
+}
\ No newline at end of file
// Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) {
var e = document.createEvent( 'MouseEvents' );
- e.initEvent( "click", true, true );
+ e.initEvent( "click", true, true );
$jq[0].dispatchEvent(e);
}
else if ( $jq[0].click ) {
});
test("bind()/trigger()/unbind() on plain object", function() {
- expect( 8 );
+ expect( 7 );
var obj = {};
var events = jQuery._data(obj, "events");
ok( events, "Object has events bound." );
equals( obj.events, undefined, "Events object on plain objects is not events" );
- equals( typeof events, "function", "'events' expando is a function on plain objects." );
equals( obj.test, undefined, "Make sure that test event is not on the plain object." );
equals( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );