From 30dc79f1d0aca3ead3980f890a546bc245feb5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Zaefferer?= Date: Fri, 22 Dec 2006 13:52:33 +0000 Subject: [PATCH] Fixed event fixing (Opera provides event.srcElement, only create pageX if clientX is available) --- newandnoteworthy.txt | 2 +- src/jquery/jquery.js | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/newandnoteworthy.txt b/newandnoteworthy.txt index 713ef092..d0d6fc52 100644 --- a/newandnoteworthy.txt +++ b/newandnoteworthy.txt @@ -7,7 +7,7 @@ New and Noteworthy - Fixed synchronous requests - $.get, $.getIfModified, $.post, $.getScript and $.getJSON now all pass through the XMLHttpRequest as returned by $.ajax - Improved AJAX docs (eg. more examples for $.ajax - - Improved event fixing, using less browser and more object detection + - Improved event fixingFixed event fixing (Opera provides event.srcElement, must ignore it if target is available; only create pageX if clientX is available) - Fixed ID with context selectors (eg. div#id doesn't ignore "div" anymore) - Improved jQuery.merge to avoid unnecessary loops - Fixed docs for html(): Now mentions that is not available for XML documents diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 8a0a115c..330e05ad 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1982,38 +1982,34 @@ jQuery.extend({ }, fix: function(event) { - // fix target property, if available - if(event.srcElement) + // fix target property, if necessary + if(!event.target && event.srcElement) event.target = event.srcElement; - // calculate pageX/Y if missing - if(typeof event.pageX == "undefined") { + // calculate pageX/Y if missing and clientX/Y available + if(typeof event.pageX == "undefined" && typeof event.clientX != "undefined") { var e = document.documentElement, b = document.body; event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft); event.pageY = event.clientY + (e.scrollTop || b.scrollTop); } - - // check if target is a textnode (only for safari) + // check safari and if target is a textnode if(jQuery.browser.safari && event.target.nodeType == 3) { // target is readonly, clone the event object event = jQuery.extend({}, event); // get parentnode from textnode event.target = event.target.parentNode; } - // fix preventDefault and stopPropagation if (!event.preventDefault) { event.preventDefault = function() { this.returnValue = false; }; } - if (!event.stopPropagation) { event.stopPropagation = function() { this.cancelBubble = true; }; } - return event; } }