Skip to content
Permalink
Browse files

Probably not the optimal solution, but tests pass.

  • Loading branch information
wycats committed Sep 16, 2009
1 parent 9ebb2fc commit 45dfa3b0fc49718c4f00600d1e25a129601d08ee
Showing with 53 additions and 1 deletion.
  1. +37 −1 src/event.js
  2. +16 −0 test/unit/event.js
@@ -405,7 +405,7 @@ jQuery.event = {
add: function( proxy, data, namespaces ) {
jQuery.extend( proxy, data || {} );
proxy.guid += data.selector + data.live;
jQuery.event.add( this, data.live, liveHandler );
jQuery.event.add( this, data.live, liveHandler, data );
},

remove: function( namespaces ) {
@@ -467,6 +467,7 @@ jQuery.Event.prototype = {
if ( !e ) {
return;
}

// if preventDefault exists run it on the original event
if ( e.preventDefault ) {
e.preventDefault();
@@ -533,6 +534,41 @@ jQuery.each({
};
});

(function() {

var event = jQuery.event,
special = event.special,
handle = event.handle;

special.submit = {
setup: function(data, namespaces) {
if(data.selector) {
event.add(this, 'click.specialSubmit', function(e, eventData) {
if(jQuery(e.target).filter(":submit, :image").closest(data.selector).length) {
e.type = "submit";
return handle.call( this, e, eventData );
}
});

event.add(this, 'keypress.specialSubmit', function( e, eventData ) {
if(jQuery(e.target).filter(":text, :password").closest(data.selector).length) {
e.type = "submit";
return handle.call( this, e, eventData );
}
});
} else {
return false;
}
},

remove: function(namespaces) {
event.remove(this, 'click.specialSubmit');
event.remove(this, 'keypress.specialSubmit');
}
};

})();

// Create "bubbling" focus and blur events
jQuery.each({
focus: "focusin",
@@ -798,6 +798,22 @@ test(".live()/.die()", function() {
jQuery('span#liveSpan1').die('click');
});

test("live with submit", function() {
var count = 0;

jQuery("#testForm").live("submit", function() {
count++;
return false;
});

jQuery("#testForm input[name=sub1]")[0].click();
jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13});

equals(2, count);

jQuery("#testForm").die("submit");
});

test("live with focus/blur", function(){
expect(2);

0 comments on commit 45dfa3b

Please sign in to comment.
You can’t perform that action at this time.