--- jquery.r5374.js 2008-05-02 22:17:49.000000000 +0200 +++ jquery-r5374-patched.js 2008-05-02 21:10:16.000000000 +0200 @@ -2008,7 +2008,10 @@ } // Enforce the right trigger type - data[0].type = type; + if ( data[0].type != type ) { + data[0] = jQuery.event.create(data[0], { }); + data[0].type = type; + } if ( exclusive ) data[0].exclusive = true; @@ -2057,7 +2060,8 @@ // Namespaced event handlers namespace = event.type.split("."); - event.type = namespace[0]; + if (event.type != namespace[0]) + event.type = namespace[0]; namespace = namespace[1]; all = !namespace && !event.exclusive; //cache this now, all = true means, any handler @@ -2088,74 +2092,141 @@ return val; }, - fix: function(event) { - if ( event[expando] == true ) - return event; - - // store a copy of the original event object - // and "clone" to set read-only properties - var originalEvent = event; - event = { originalEvent: originalEvent }; - var props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" "); - for ( var i=props.length; i; i-- ) - event[ props[i] ] = originalEvent[ props[i] ]; - - // Mark it as fixed - event[expando] = true; - - // add preventDefault and stopPropagation since - // they will not work on the clone - event.preventDefault = function() { - // if preventDefault exists run it on the original event - if (originalEvent.preventDefault) - originalEvent.preventDefault(); - // otherwise set the returnValue property of the original event to false (IE) - originalEvent.returnValue = false; - }; - event.stopPropagation = function() { - // if stopPropagation exists run it on the original event - if (originalEvent.stopPropagation) - originalEvent.stopPropagation(); - // otherwise set the cancelBubble property of the original event to true (IE) - originalEvent.cancelBubble = true; - }; - - // Fix timeStamp - event.timeStamp = event.timeStamp || now(); - - // Fix target property, if necessary - if ( !event.target ) - event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either - - // check if target is a textnode (safari) - if ( event.target.nodeType == 3 ) - event.target = event.target.parentNode; - - // Add relatedTarget, if necessary - if ( !event.relatedTarget && event.fromElement ) - event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement; - - // Calculate pageX/Y if missing and clientX/Y available - if ( event.pageX == null && event.clientX != null ) { - var doc = document.documentElement, body = document.body; - event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0); - event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0); - } - - // Add which for key events - if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) - event.which = event.charCode || event.keyCode; - - // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) - if ( !event.metaKey && event.ctrlKey ) - event.metaKey = event.ctrlKey; - - // Add which for click: 1 == left; 2 == middle; 3 == right - // Note: button is not normalized, so don't use it - if ( !event.which && event.button ) - event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); - - return event; + // create a new event object to be able to set + // properties that normally are just read-only + create: function(e, o) { + + if ( e[expando] == true ) + return e; + + var i = -1, ev = {}, props = ( + // generic events + 'type target currentTarget eventPhase bubbles cancelable timeStamp ' + + // mouse events + 'view detail screenX screenY clientX clientY button relatedTarget wheelDelta ' + + // mutations events + 'attrName attrChange newValue prevValue relatedNode ' + + // keyboard events + 'altKey ctrlKey shiftKey metaKey charCode keyCode which ' + + // jQuery extended properties + 'pageX pageY ' + + // shouldn't be copied if not used + // expect clashes or nuked detection + // if other's code is used with jQuery +// 'data handler srcElement toElement fromElement' + + '' + ).split(" "); + + // set or copy the above event properties + while( props[++i] ) + ev[ props[i] ] = o[ props[i] ] || e[ props[i] ]; + + // store a copy of the original event + ev.originalEvent = e; + + // mark the event as fixed + ev[expando] = true; + + return ev; + }, + + fix: function(e) { + + // cache this + var root = document.documentElement, body = document.body; + + // optimized using lazy function definition + // and recreating a new event object template + + if ( document.createEventObject ) { + + jQuery.event.fix = function(e) { + + var ev = e; + + // prevent the execution of the default action + ev.preventDefault = e.preventDefault || function() { + // set the returnValue property of + // the original event to false (IE) + e.returnValue = false; + }; + + // stop the event bubbling up to other elements + ev.stopPropagation = e.stopPropagation || function() { + // set the cancelBubble property of + // the original event to true (IE) + e.cancelBubble = true; + }; + + // fix timestamp + ev.timeStamp = ev.timeStamp || now(); + + // fix target property + ev.target = ev.target || ev.srcElement || document; + + // Add relatedTarget, if necessary + ev.relatedTarget = ev.relatedTarget || (ev.fromElement == ev.target ? ev.toElement : ev.fromElement); + + // Calculate pageX/Y if missing and clientX/Y available + ev.pageX = ev.pageX || (ev.clientX + (root && root.scrollLeft || body && body.scrollLeft || 0) - (root.clientLeft || 0)); + ev.pageY = ev.pageY || (ev.clientY + (root && root.scrollTop || body && body.scrollTop || 0) - (root.clientTop || 0)); + + // Add which for key events + ev.which = ev.which || ((ev.charCode || ev.charCode === 0) ? ev.charCode : ev.keyCode); + + // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) + ev.metaKey = ev.metaKey || ev.ctrlKey; + + // Add which for click: 1 == left; 2 == middle; 3 == right + // Note: button is not normalized, so don't use it + ev.which = ev.which || (ev.button & 1 ? 1 : ( ev.button & 2 ? 3 : ( ev.button & 4 ? 2 : 0 ) )); + + // return the writable cloned event + return ev; + } + + } else { + + jQuery.event.fix = function(e) { + + var ev = e; + + // only done on custom, special or namespaced events + // and only if it has not already been done previously + if ( !ev.initEvent && !ev.originalEvent ) { + + // create a writable event object + ev = jQuery.event.create(e, { }); + + // add preventDefault and stopPropagation since + // they will not work on the clone event object + + // prevent the execution of the default action + ev.preventDefault = e.preventDefault || function() { + return false; + }; + + // stop the event bubbling up to other elements + ev.stopPropagation = e.stopPropagation || function() { + return false; + }; + + // save a copy of the original event + ev.originalEvent = e; + } + + // check if target is a textnode + if ( e.target.nodeType == 3 ) { + // dispatch event to parent container + // this have to be tested on Safari 2 + ev.target.parentNode.dispatchEvent(ev); + } + + return ev; + } + } + + return jQuery.event.fix(e); }, proxy: function( fn, proxy ){ @@ -2192,7 +2263,7 @@ // If we actually just moused on to a sub-element, ignore it if ( withinElement(event, this) ) return true; // Execute the right handlers by setting the event type to mouseenter - event.type = "mouseenter"; + arguments[0] = jQuery.event.create(arguments[0], { type: "mouseenter" }); return jQuery.event.handle.apply(this, arguments); } }, @@ -2214,7 +2285,7 @@ // If we actually just moused on to a sub-element, ignore it if ( withinElement(event, this) ) return true; // Execute the right handlers by setting the event type to mouseleave - event.type = "mouseleave"; + arguments[0] = jQuery.event.create(arguments[0], { type: "mouseleave" }); return jQuery.event.handle.apply(this, arguments); } }