Added support for bubbling triggered events.
[jquery.git] / src / event.js
index 7bbca2a..8fb77a9 100644 (file)
@@ -13,7 +13,7 @@ jQuery.event = {
 
                // For whatever reason, IE has trouble passing the window object
                // around, causing it to be cloned in the process
-               if ( jQuery.browser.msie && elem.setInterval )
+               if ( elem.setInterval && elem != window )
                        elem = window;
 
                // Make sure that the function being executed has a unique ID
@@ -40,8 +40,9 @@ jQuery.event = {
                        handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
                                // 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 jQuery.event.handle.apply(arguments.callee.elem, arguments);
+                               return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
+                                       jQuery.event.handle.apply(arguments.callee.elem, arguments) :
+                                       undefined;
                        });
                // Add elem as a property of the handle function
                // This is to prevent a memory leak with non-native
@@ -115,7 +116,7 @@ jQuery.event = {
                                        // Namespaced event handlers
                                        var namespace = type.split(".");
                                        type = namespace.shift();
-                                       namespace = RegExp(namespace.sort().join(".*\\.") + "(\\.|$)");
+                                       namespace = RegExp("(^|\\.)" + namespace.sort().join(".*\\.") + "(\\.|$)");
 
                                        if ( events[type] ) {
                                                // remove the given handler for the given type
@@ -211,6 +212,12 @@ jQuery.event = {
                        if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
                                val = false;
 
+                       if ( donative !== false && val !== false ) {
+                               var parent = elem.parentNode || elem.ownerDocument;
+                               if ( parent )
+                                       jQuery.event.trigger(type, data, parent, donative);
+                       }
+
                        // Extra functions don't get the custom event object
                        if ( event )
                                data.shift();
@@ -248,9 +255,11 @@ jQuery.event = {
                // Namespaced event handlers
                namespace = event.type.split(".");
                event.type = namespace.shift();
-               namespace = RegExp(namespace.sort().join(".*\\.") + "(\\.|$)");
+
                // Cache this now, all = true means, any handler
-               all = !namespace && !event.exclusive;
+               all = !namespace.length && !event.exclusive;
+               
+               namespace = RegExp("(^|\\.)" + namespace.sort().join(".*\\.") + "(\\.|$)");
 
                handlers = ( jQuery.data(this, "events") || {} )[event.type];
 
@@ -380,39 +389,37 @@ function stopImmediatePropagation(){
        this.stopPropagation();
 }
 
-if ( !jQuery.browser.msie ){   
-       // Checks if an event happened on an element within another element
-       // Used in jQuery.event.special.mouseenter and mouseleave handlers
-       var withinElement = function(event) {
-               // Check if mouse(over|out) are still within the same parent element
-               var parent = event.relatedTarget;
-               // Traverse up the tree
-               while ( parent && parent != this )
-                       try { parent = parent.parentNode; }
-                       catch(e) { parent = this; }
-               
-               if( parent != this ){
-                       // set the correct event type
-                       event.type = event.data;
-                       // handle event if we actually just moused on to a non sub-element
-                       jQuery.event.handle.apply( this, arguments );
-               }
-       };
+// Checks if an event happened on an element within another element
+// Used in jQuery.event.special.mouseenter and mouseleave handlers
+var withinElement = function(event) {
+       // Check if mouse(over|out) are still within the same parent element
+       var parent = event.relatedTarget;
+       // Traverse up the tree
+       while ( parent && parent != this )
+               try { parent = parent.parentNode; }
+               catch(e) { parent = this; }
        
-       jQuery.each({ 
-               mouseover: 'mouseenter', 
-               mouseout: 'mouseleave'
-       }, function( orig, fix ){
-               jQuery.event.special[ fix ] = {
-                       setup: function(){
-                               jQuery.event.add( this, orig, withinElement, fix );
-                       },
-                       teardown: function(){
-                               jQuery.event.remove( this, orig, withinElement );
-                       }
-               };                         
-       });
-}
+       if( parent != this ){
+               // set the correct event type
+               event.type = event.data;
+               // handle event if we actually just moused on to a non sub-element
+               jQuery.event.handle.apply( this, arguments );
+       }
+};
+       
+jQuery.each({ 
+       mouseover: 'mouseenter', 
+       mouseout: 'mouseleave'
+}, function( orig, fix ){
+       jQuery.event.special[ fix ] = {
+               setup: function(){
+                       jQuery.event.add( this, orig, withinElement, fix );
+               },
+               teardown: function(){
+                       jQuery.event.remove( this, orig, withinElement );
+               }
+       };                         
+});
 
 jQuery.fn.extend({
        bind: function( type, data, fn ) {