Modified onexxx handlers to unbind themselve when executed; Reintroduced event fixes (and added some more comments)
This commit is contained in:
parent
440d512edd
commit
4e5b46f7f6
|
@ -1592,20 +1592,15 @@ new function(){
|
||||||
|
|
||||||
// Finally, handle events that only fire once
|
// Finally, handle events that only fire once
|
||||||
jQuery.fn["one"+o] = function(f){
|
jQuery.fn["one"+o] = function(f){
|
||||||
// Attach the event listener
|
// save cloned reference to this
|
||||||
return this.each(function(){
|
var element = jQuery(this);
|
||||||
|
var handler = function() {
|
||||||
var count = 0;
|
// unbind itself when executed
|
||||||
|
element.unbind(o, handler);
|
||||||
// Add the event
|
// apply original handler with the same arguments
|
||||||
jQuery.event.add( this, o, function(e){
|
f.apply(this, arguments);
|
||||||
// If this function has already been executed, stop
|
};
|
||||||
if ( count++ ) return true;
|
return this.bind(o, handler);
|
||||||
|
|
||||||
// And execute the bound function
|
|
||||||
return f.apply(this, [e]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
15
src/jquery/jquery.js
vendored
15
src/jquery/jquery.js
vendored
|
@ -2295,16 +2295,25 @@ jQuery.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
fix: function(event) {
|
fix: function(event) {
|
||||||
if ( event ) {
|
// check IE
|
||||||
|
if(jQuery.browser.msie) {
|
||||||
|
// get real event from window.event
|
||||||
|
event = window.event;
|
||||||
event.preventDefault = function() {
|
event.preventDefault = function() {
|
||||||
this.returnValue = false;
|
this.returnValue = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
event.stopPropagation = function() {
|
event.stopPropagation = function() {
|
||||||
this.cancelBubble = true;
|
this.cancelBubble = true;
|
||||||
};
|
};
|
||||||
|
// fix target property
|
||||||
|
event.target = event.srcElement;
|
||||||
|
// check safari and if target is a textnode
|
||||||
|
} else 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue