Fixed event fixing (Opera provides event.srcElement, only create pageX if clientX is available)

This commit is contained in:
Jörn Zaefferer 2006-12-22 13:52:33 +00:00
parent ccc4c7663a
commit 30dc79f1d0
2 changed files with 6 additions and 10 deletions

View file

@ -7,7 +7,7 @@ New and Noteworthy
- Fixed synchronous requests - Fixed synchronous requests
- $.get, $.getIfModified, $.post, $.getScript and $.getJSON now all pass through the XMLHttpRequest as returned by $.ajax - $.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 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) - Fixed ID with context selectors (eg. div#id doesn't ignore "div" anymore)
- Improved jQuery.merge to avoid unnecessary loops - Improved jQuery.merge to avoid unnecessary loops
- Fixed docs for html(): Now mentions that is not available for XML documents - Fixed docs for html(): Now mentions that is not available for XML documents

14
src/jquery/jquery.js vendored
View file

@ -1982,38 +1982,34 @@ jQuery.extend({
}, },
fix: function(event) { fix: function(event) {
// fix target property, if available // fix target property, if necessary
if(event.srcElement) if(!event.target && event.srcElement)
event.target = event.srcElement; event.target = event.srcElement;
// calculate pageX/Y if missing // calculate pageX/Y if missing and clientX/Y available
if(typeof event.pageX == "undefined") { if(typeof event.pageX == "undefined" && typeof event.clientX != "undefined") {
var e = document.documentElement, b = document.body; var e = document.documentElement, b = document.body;
event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft); event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
event.pageY = event.clientY + (e.scrollTop || b.scrollTop); event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
} }
// check safari and if target is a textnode
// check if target is a textnode (only for safari)
if(jQuery.browser.safari && event.target.nodeType == 3) { if(jQuery.browser.safari && event.target.nodeType == 3) {
// target is readonly, clone the event object // target is readonly, clone the event object
event = jQuery.extend({}, event); event = jQuery.extend({}, event);
// get parentnode from textnode // get parentnode from textnode
event.target = event.target.parentNode; event.target = event.target.parentNode;
} }
// fix preventDefault and stopPropagation // fix preventDefault and stopPropagation
if (!event.preventDefault) { if (!event.preventDefault) {
event.preventDefault = function() { event.preventDefault = function() {
this.returnValue = false; this.returnValue = false;
}; };
} }
if (!event.stopPropagation) { if (!event.stopPropagation) {
event.stopPropagation = function() { event.stopPropagation = function() {
this.cancelBubble = true; this.cancelBubble = true;
}; };
} }
return event; return event;
} }
} }