]> source.dussan.org Git - jquery.git/commitdiff
Made sure that return false works in .live() along with the event object being passed...
authorJohn Resig <jeresig@gmail.com>
Tue, 30 Dec 2008 20:45:33 +0000 (20:45 +0000)
committerJohn Resig <jeresig@gmail.com>
Tue, 30 Dec 2008 20:45:33 +0000 (20:45 +0000)
src/event.js
test/unit/event.js

index 74bc1df2986412f22b0a184a5347aa1810573f8a..0710b7bfad710b2d37b19f50ac2c576dfdcf91ac 100644 (file)
@@ -551,14 +551,18 @@ jQuery.fn.extend({
 });
 
 function liveHandler( event ){
-       var check = RegExp("(^|\\.)" + event.type + "(\\.|$)");
+       var check = RegExp("(^|\\.)" + event.type + "(\\.|$)"), stop = true;
        jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){
                if ( check.test(fn.type) ) {
                        var elem = jQuery(event.target).closest(fn.data)[0];
-                       if ( elem )
-                               jQuery.event.trigger( event.type, fn.data, elem, false, fn, false );
+                       if ( elem ) {
+                               var ret = jQuery.event.trigger( event.type, [event, fn.data], elem, false, fn, false );
+                               if ( ret === false )
+                                       stop = false;
+                       }
                }
        });
+       return stop;
 }
 
 function liveConvert(type, selector){
index fd91819356a45a8470a55a981cf6138658502d8e..e80774fa09d75fd3fc443b00379f8076ccea976e 100644 (file)
@@ -439,7 +439,7 @@ test("toggle(Function, Function, ...)", function() {
 });
 
 test(".live()/.die()", function() {
-       expect(28);
+       expect(30);
 
        var submit = 0, div = 0, livea = 0, liveb = 0;
 
@@ -501,6 +501,20 @@ test(".live()/.die()", function() {
        jQuery("div#nothiddendiv").die("click");
        jQuery("div").die("click");
        jQuery("div").die("submit");
+
+       // Verify that return false prevents default action
+       jQuery("#anchor2").live("click", function(){ return false; });
+       var hash = window.location.hash;
+       jQuery("#anchor2").trigger("click");
+       equals( window.location.hash, hash, "return false worked" );
+       jQuery("#anchor2").die("click");
+
+       // Verify that .preventDefault() prevents default action
+       jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
+       var hash = window.location.hash;
+       jQuery("#anchor2").trigger("click");
+       equals( window.location.hash, hash, "e.preventDefault() worked" );
+       jQuery("#anchor2").die("click");
 });
 
 /*