Skip to main content

Bug Tracker

Side navigation

Ticket #1204: event_patch.diff
File event_patch.diff, 2.0 KB (added by yehuda, May 18, 2007 11:22PM UTC)

Updated patch

Index: /Users/yehudakatz/Documents/workspace/jquery/trunk/jquery/src/event/event.js
===================================================================
--- /Users/yehudakatz/Documents/workspace/jquery/trunk/jquery/src/event/event.js	(revision 1912)
+++ /Users/yehudakatz/Documents/workspace/jquery/trunk/jquery/src/event/event.js	(working copy)
@@ -186,8 +186,21 @@
 		if ( !event.target && event.srcElement )
 			event.target = event.srcElement;
 
+    // Add relatedTarget, if necessary
+    if ( event.relatedTarget == null && event.fromElement != null )
+      event.relatedTarget = (event.fromElement == event.target) ? event.toElement : event.fromElement;
+
+    // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
+    if ( event.metaKey == null && event.ctrlKey != null )
+      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 == null && event.button != null )
+      event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
+
 		// Calculate pageX/Y if missing and clientX/Y available
-		if ( event.pageX == undefined && event.clientX != undefined ) {
+		if ( event.pageX == null && event.clientX != null ) {
 			var e = document.documentElement || document.body;
 			event.pageX = event.clientX + e.scrollLeft;
 			event.pageY = event.clientY + e.scrollTop;
@@ -192,6 +205,14 @@
 			event.pageX = event.clientX + e.scrollLeft;
 			event.pageY = event.clientY + e.scrollTop;
 		}
+
+    // Add which for keypresses: keyCode
+    if ( (event.which == null || event.type == "keypress") && event.keyCode != null )
+      event.which = event.keyCode;    
+
+    // If it's a keypress event, add charCode to IE
+    if ( event.charCode == null && event.type == "keypress" )
+      event.charCode = event.keyCode;
 				
 		// check if target is a textnode (safari)
 		if (jQuery.browser.safari && event.target.nodeType == 3) {

Download in other formats:

Original Format