aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-01-22 05:14:45 +0000
committerJohn Resig <jeresig@gmail.com>2007-01-22 05:14:45 +0000
commitd2f9022a8ebbfadeb6a329714a607d2dc2882769 (patch)
treef4dd3bca530f67c233ef7f909ede986ab5193ec8
parent23220321d1c937a69b7c2a51766ce8940724e7bf (diff)
downloadjquery-d2f9022a8ebbfadeb6a329714a607d2dc2882769.tar.gz
jquery-d2f9022a8ebbfadeb6a329714a607d2dc2882769.zip
Refactored the trigger code a little bit.
-rw-r--r--src/event/event.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/event/event.js b/src/event/event.js
index 565b9154c..812d6f268 100644
--- a/src/event/event.js
+++ b/src/event/event.js
@@ -80,29 +80,30 @@ jQuery.event = {
});
// Handle triggering a single element
- else if ( element["on" + type] ) {
- // Pass along a fake event
- data.unshift( this.fix({ type: type, target: element }) );
+ else {
+ var handler = element["on" + type ], val,
+ fn = jQuery.isFunction( element[ type ] );
+
+ if ( handler ) {
+ // Pass along a fake event
+ data.unshift( this.fix({ type: type, target: element }) );
- // Trigger the event
- var val = element["on" + type].apply( element, data );
+ // Trigger the event
+ if ( (val = handler.apply( element, data )) !== false )
+ this.triggered = true;
+ }
- if ( val !== false && jQuery.isFunction( element[ type ] ) ) {
- this.triggered = true;
+ if ( fn && val !== false )
element[ type ]();
- }
- } else if ( jQuery.isFunction( element[ type ] ) )
- element[ type ]();
+
+ this.triggered = false;
+ }
},
handle: function(event) {
- if ( typeof jQuery == "undefined" ) return;
-
- // Handle the second event of a trigger
- if ( jQuery.event.triggered ) {
- jQuery.event.triggered = false;
- return;
- }
+ // Handle the second event of a trigger and when
+ // an event is called after a page has unloaded
+ if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return;
// Empty object is for triggered events with no data
event = jQuery.event.fix( event || window.event || {} );