Fixed event fixing (Opera provides event.srcElement, only create pageX if clientX is available)
This commit is contained in:
parent
ccc4c7663a
commit
30dc79f1d0
2 changed files with 6 additions and 10 deletions
|
@ -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
|
||||
|
|
14
src/jquery/jquery.js
vendored
14
src/jquery/jquery.js
vendored
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue