Skip to content
Permalink
Browse files
Improved event fixing, using less browser and more object detection
  • Loading branch information
jzaefferer committed Dec 20, 2006
1 parent dd27ea5 commit 0d149e52e6d3326730c6a5e688d5496a7ab91a87
Showing with 14 additions and 15 deletions.
  1. +1 −0 newandnoteworthy.txt
  2. +13 −15 src/jquery/jquery.js
@@ -7,6 +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

1.0.4
-----
@@ -1960,9 +1960,6 @@ jQuery.extend({

event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data

// If no correct event was found, fail
if ( !event ) return false;

var returnValue = true;

var c = this.events[event.type];
@@ -1985,36 +1982,37 @@ jQuery.extend({
},

fix: function(event) {
// check IE
if(jQuery.browser.msie) {
// fix target property, if available
// check prevents overwriting of fake target coming from trigger
if(event.srcElement)
event.target = event.srcElement;

// calculate pageX/Y
// fix target property, if available
if(event.srcElement)
event.target = event.srcElement;

// calculate pageX/Y if missing
if(typeof event.pageX == "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 safari and if target is a textnode
} else if(jQuery.browser.safari && event.target.nodeType == 3) {
// check if target is a textnode (only for safari)
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)
if (!event.preventDefault) {
event.preventDefault = function() {
this.returnValue = false;
};
}

if (!event.stopPropagation)
if (!event.stopPropagation) {
event.stopPropagation = function() {
this.cancelBubble = true;
};
}

return event;
}

0 comments on commit 0d149e5

Please sign in to comment.