]> source.dussan.org Git - jquery.git/commitdiff
jQuery.event.fix performance boost. An example: click event was previously ~3ms and...
authorBrandon Aaron <brandon.aaron@gmail.com>
Mon, 28 Apr 2008 21:09:27 +0000 (21:09 +0000)
committerBrandon Aaron <brandon.aaron@gmail.com>
Mon, 28 Apr 2008 21:09:27 +0000 (21:09 +0000)
src/event.js

index 2d9bdc27a8482fa2ce5094ebf394002af686892f..0cf6c58e5a0d843f7cfcba6251ec65b1f5f5deea 100644 (file)
@@ -184,8 +184,16 @@ jQuery.event = {
                                event = !data[0] || !data[0].preventDefault;
                        
                        // Pass along a fake event
-                       if ( event )
-                               data.unshift( { type: type, target: elem } );
+                       if ( event ) {
+                               data.unshift({ 
+                                       type: type, 
+                                       target: elem, 
+                                       preventDefault: function(){}, 
+                                       stopPropagation: function(){}, 
+                                       timeStamp: +new Date
+                               });
+                               data[0][expando] = true; // no need to fix fake event
+                       }
 
                        // Enforce the right trigger type
                        data[0].type = type;
@@ -265,11 +273,6 @@ jQuery.event = {
                        }
                }
 
-               // Clean up added properties in IE to prevent memory leak
-               if (jQuery.browser.msie)
-                       event.target = event.preventDefault = event.stopPropagation =
-                               event.handler = event.data = event[expando] = null;
-
                return val;
        },
 
@@ -278,9 +281,12 @@ jQuery.event = {
                        return event;
                
                // store a copy of the original event object 
-               // and clone to set read-only properties
+               // and "clone" to set read-only properties
                var originalEvent = event;
-               event = jQuery.extend({}, originalEvent);
+               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;
@@ -311,7 +317,7 @@ jQuery.event = {
                                
                // check if target is a textnode (safari)
                if ( event.target.nodeType == 3 )
-                       event.target = originalEvent.target.parentNode;
+                       event.target = event.target.parentNode;
 
                // Add relatedTarget, if necessary
                if ( !event.relatedTarget && event.fromElement )