Make sure that expando properties aren't set on embed, applet, or object elements...
[jquery.git] / src / event.js
index acf363b..128f78f 100644 (file)
@@ -126,7 +126,7 @@ jQuery.event = {
                                        types = types.type;
                                }
 
                                        types = types.type;
                                }
 
-                               // Handle multiple events seperated by a space
+                               // Handle multiple events separated by a space
                                // jQuery(...).unbind("mouseover mouseout", fn);
                                types = types.split(/\s+/);
                                var i = 0;
                                // jQuery(...).unbind("mouseover mouseout", fn);
                                types = types.split(/\s+/);
                                var i = 0;
@@ -135,7 +135,7 @@ jQuery.event = {
                                        var namespaces = type.split(".");
                                        type = namespaces.shift();
                                        var all = !namespaces.length,
                                        var namespaces = type.split(".");
                                        type = namespaces.shift();
                                        var all = !namespaces.length,
-                                               cleaned = jQuery.map( namespaces.slice(0).sort() , function(nm){ return nm.replace(/[^\w\s\.\|`]/g, function(ch){return "\\"+ch  }) }),
+                                               cleaned = jQuery.map( namespaces.slice(0).sort() , function(nm){ return nm.replace(/[^\w\s\.\|`]/g, function(ch){return "\\"+ch;  }); }),
                                                namespace = new RegExp("(^|\\.)" + cleaned.join("\\.(?:.*\\.)?") + "(\\.|$)"),
                                                special = this.special[ type ] || {};
 
                                                namespace = new RegExp("(^|\\.)" + cleaned.join("\\.(?:.*\\.)?") + "(\\.|$)"),
                                                special = this.special[ type ] || {};
 
@@ -257,18 +257,20 @@ jQuery.event = {
                        nativeHandler = elem[ "on" + type ];
                // prevent IE from throwing an error for some elements with some event types, see #3533
                } catch (e) {}
                        nativeHandler = elem[ "on" + type ];
                // prevent IE from throwing an error for some elements with some event types, see #3533
                } catch (e) {}
-               // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
-               if ( (!nativeFn || (jQuery.nodeName(elem, 'a') && type === "click")) && nativeHandler && nativeHandler.apply( elem, data ) === false ) {
-                       event.result = false;
-               }
+
+               var isClick = jQuery.nodeName(elem, "a") && type === "click";
 
                // Trigger the native events (except for clicks on links)
 
                // Trigger the native events (except for clicks on links)
-               if ( !bubbling && nativeFn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type === "click") ) {
+               if ( !bubbling && nativeFn && !event.isDefaultPrevented() && !isClick ) {
                        this.triggered = true;
                        try {
                                nativeFn();
                        // prevent IE from throwing an error for some hidden elements
                        } catch (e) {}
                        this.triggered = true;
                        try {
                                nativeFn();
                        // prevent IE from throwing an error for some hidden elements
                        } catch (e) {}
+
+               // Handle triggering native .onfoo handlers
+               } else if ( nativeHandler && nativeHandler.apply( elem, data ) === false ) {
+                       event.result = false;
                }
 
                this.triggered = false;
                }
 
                this.triggered = false;
@@ -325,6 +327,8 @@ jQuery.event = {
 
                        }
                }
 
                        }
                }
+
+               return event.result;
        },
 
        props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
        },
 
        props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
@@ -430,6 +434,21 @@ jQuery.event = {
                                }
                        },
                        special: {}
                                }
                        },
                        special: {}
+               },
+               beforeunload: {
+                       setup: function( data, namespaces, fn ) {
+                               // We only want to do this special case on windows
+                               if ( this.setInterval ) {
+                                       this.onbeforeunload = fn;
+                               }
+
+                               return false;
+                       },
+                       teardown: function( namespaces, fn ) {
+                               if ( this.onbeforeunload === fn ) {
+                                       this.onbeforeunload = null;
+                               }
+                       }
                }
        }
 };
                }
        }
 };
@@ -536,23 +555,25 @@ delegate = function( event ) {
 
 // Create mouseenter and mouseleave events
 jQuery.each({
 
 // Create mouseenter and mouseleave events
 jQuery.each({
-       mouseover: "mouseenter",
-       mouseout: "mouseleave"
+       mouseenter: "mouseover",
+       mouseleave: "mouseout"
 }, function( orig, fix ) {
 }, function( orig, fix ) {
-       jQuery.event.special[ fix ] = {
+       jQuery.event.special[ orig ] = {
                setup: function(data){
                setup: function(data){
-                       jQuery.event.add( this, orig, data && data.selector ? delegate : withinElement, fix );
+                       jQuery.event.add( this, fix, data && data.selector ? delegate : withinElement, orig );
                },
                teardown: function(data){
                },
                teardown: function(data){
-                       jQuery.event.remove( this, orig, data && data.selector ? delegate : withinElement );
+                       jQuery.event.remove( this, fix, data && data.selector ? delegate : withinElement );
                }
        };
 });
 
 // submit delegation
                }
        };
 });
 
 // submit delegation
+if ( !jQuery.support.submitBubbles ) {
+
 jQuery.event.special.submit = {
        setup: function( data, namespaces, fn ) {
 jQuery.event.special.submit = {
        setup: function( data, namespaces, fn ) {
-               if ( !jQuery.support.submitBubbles && this.nodeName.toLowerCase() !== "form" ) {
+               if ( this.nodeName.toLowerCase() !== "form" ) {
                        jQuery.event.add(this, "click.specialSubmit." + fn.guid, function( e ) {
                                var elem = e.target, type = elem.type;
 
                        jQuery.event.add(this, "click.specialSubmit." + fn.guid, function( e ) {
                                var elem = e.target, type = elem.type;
 
@@ -569,8 +590,6 @@ jQuery.event.special.submit = {
                                }
                        });
                }
                                }
                        });
                }
-
-               return false;
        },
 
        remove: function( namespaces, fn ) {
        },
 
        remove: function( namespaces, fn ) {
@@ -579,7 +598,11 @@ jQuery.event.special.submit = {
        }
 };
 
        }
 };
 
+}
+
 // change delegation, happens here so we have bind.
 // change delegation, happens here so we have bind.
+if ( !jQuery.support.changeBubbles ) {
+
 jQuery.event.special.change = {
        filters: {
                click: function( e ) { 
 jQuery.event.special.change = {
        filters: {
                click: function( e ) { 
@@ -628,21 +651,16 @@ jQuery.event.special.change = {
                }
        },
        setup: function( data, namespaces, fn ) {
                }
        },
        setup: function( data, namespaces, fn ) {
-               // return false if we bubble
-               if ( !jQuery.support.changeBubbles ) {
-                       for ( var type in changeFilters ) {
-                               jQuery.event.add( this, type + ".specialChange." + fn.guid, changeFilters[type] );
-                       }
+               for ( var type in changeFilters ) {
+                       jQuery.event.add( this, type + ".specialChange." + fn.guid, changeFilters[type] );
                }
                
                // always want to listen for change for trigger
                return false;
        },
        remove: function( namespaces, fn ) {
                }
                
                // always want to listen for change for trigger
                return false;
        },
        remove: function( namespaces, fn ) {
-               if ( !jQuery.support.changeBubbles ) {
-                       for ( var type in changeFilters ) {
-                               jQuery.event.remove( this, type + ".specialChange" + (fn ? "."+fn.guid : ""), changeFilters[type] );
-                       }
+               for ( var type in changeFilters ) {
+                       jQuery.event.remove( this, type + ".specialChange" + (fn ? "."+fn.guid : ""), changeFilters[type] );
                }
        }
 };
                }
        }
 };
@@ -655,36 +673,26 @@ function trigger( type, elem, args ) {
 }
 
 // Create "bubbling" focus and blur events
 }
 
 // Create "bubbling" focus and blur events
-jQuery.each({
-       focus: "focusin",
-       blur: "focusout"
-}, function( orig, fix ){
-       var event = jQuery.event,
-               handle = event.handle;
-       
-       function ieHandler() { 
-               arguments[0].type = orig;
-               return handle.apply(this, arguments);
-       }
+if ( !jQuery.support.focusBubbles ) {
 
 
-       event.special[orig] = {
-               setup:function() {
-                       if ( this.addEventListener ) {
-                               this.addEventListener( orig, handle, true );
-                       } else {
-                               event.add( this, fix, ieHandler );
-                       }
+jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ){
+       event.special[ orig ] = {
+               setup: function() {
+                       jQuery.event.add( this, fix, ieHandler );
                }, 
                }, 
-               teardown:function() { 
-                       if ( this.removeEventListener ) {
-                               this.removeEventListener( orig, handle, true );
-                       } else {
-                               event.remove( this, fix, ieHandler );
-                       }
+               teardown: function() { 
+                       jQuery.event.remove( this, fix, ieHandler );
                }
        };
                }
        };
+
+       function ieHandler() { 
+               arguments[0].type = orig;
+               return jQuery.event.handle.apply(this, arguments);
+       }
 });
 
 });
 
+}
+
 jQuery.fn.extend({
        // TODO: make bind(), unbind() and one() DRY!
        bind: function( type, data, fn, thisObject ) {
 jQuery.fn.extend({
        // TODO: make bind(), unbind() and one() DRY!
        bind: function( type, data, fn, thisObject ) {