]> source.dussan.org Git - jquery.git/commitdiff
Provide a way to simulate default browser actions. Fixes #5973.
authorjeresig <jeresig@gmail.com>
Thu, 28 Jan 2010 19:34:09 +0000 (14:34 -0500)
committerjeresig <jeresig@gmail.com>
Thu, 28 Jan 2010 19:34:09 +0000 (14:34 -0500)
src/event.js
test/unit/event.js

index 53ef72c0c17d2a3733a446152a5a5c87558c5202..602332fb653414644148b66653404ddef0b35ff8 100644 (file)
@@ -333,9 +333,12 @@ jQuery.event = {
 
                } else if ( !event.isDefaultPrevented() ) {
                        var target = event.target, old,
-                               isClick = jQuery.nodeName(target, "a") && type === "click";
+                               isClick = jQuery.nodeName(target, "a") && type === "click",
+                               special = jQuery.event.special[ type ] || {};
+
+                       if ( (!special._default || special._default.call( elem, event ) === false) && 
+                               !isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) {
 
-                       if ( !isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) {
                                try {
                                        if ( target[ type ] ) {
                                                // Make sure that we don't accidentally re-trigger the onFOO events
index 824707fee91cdd28f8b37e9d49431dc56fb91ea5..b0cc5026dc246b1ccb6c8636ed077ae1f4f0ff4a 100644 (file)
@@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() {
 });
 
 test("bind(), namespace with special add", function() {
-       expect(9);
+       expect(18);
 
        var div = jQuery("<div/>").bind("test", function(e) {
                ok( true, "Test event fired." );
@@ -81,6 +81,11 @@ test("bind(), namespace with special add", function() {
        var i = 0;
 
        jQuery.event.special.test = {
+               _default: function(e) {
+                       equals( this, document, "Make sure we're at the top of the chain." );
+                       equals( e.type, "test", "And that we're still dealing with a test event." );
+                       equals( e.target, div[0], "And that the target is correct." );
+               },
                setup: function(){},
                teardown: function(){},
                add: function( handler, data, namespaces ) {