Skip to content

Commit

Permalink
Probably not the optimal solution, but tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Sep 16, 2009
1 parent 9ebb2fc commit 45dfa3b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/event.js
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -467,6 +467,7 @@ jQuery.Event.prototype = {
if ( !e ) {
return;
}

// if preventDefault exists run it on the original event
if ( e.preventDefault ) {
e.preventDefault();
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions test/unit/event.js
Expand Up @@ -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);

Expand Down

0 comments on commit 45dfa3b

Please sign in to comment.