Skip to content
Permalink
Browse files
Fixed event fixing (Opera provides event.srcElement, only create page…
…X if clientX is available)
  • Loading branch information
jzaefferer committed Dec 22, 2006
1 parent ccc4c76 commit 30dc79f1d0aca3ead3980f890a546bc245feb5d5
Showing with 6 additions and 10 deletions.
  1. +1 −1 newandnoteworthy.txt
  2. +5 −9 src/jquery/jquery.js
@@ -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
@@ -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;
}
}

0 comments on commit 30dc79f

Please sign in to comment.