From 5dc6b7ce3469eaadb37a151d449e8d36571d1894 Mon Sep 17 00:00:00 2001 From: Alexander Farkas Date: Mon, 21 Dec 2009 15:32:32 -0500 Subject: Used the patch from Alexander as the basis for a rewrite of the IE change event logic. Now has full parity with the regular change event in other browsers: Works with regular bind, works better with multiple selects, works as a regular change event (note test suite changes), works with readonly/disabled inputs, and much more. The original patch had a number of problems, including firing the change event too many times, not bubblinb properly, and not handling clicks on multi-selects properly - that should all be fixed now. Thanks Alexander for the patch pushing in the right direction. --- test/delegatetest.html | 249 ++++++++++++++++++++++++++++--------------------- test/unit/event.js | 36 ++----- 2 files changed, 153 insertions(+), 132 deletions(-) (limited to 'test') diff --git a/test/delegatetest.html b/test/delegatetest.html index cf30d87e3..e3ebbfc6e 100644 --- a/test/delegatetest.html +++ b/test/delegatetest.html @@ -2,122 +2,161 @@

Change Tests

- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- Change each: - - - - - - -
- - -
- -
- - -
- - - - $().bind('change')
Results:SELECTMULTICHECKBOXRADIOTEXTTEXTAREADOCUMENT
+ Change each: + + + + + + +
+ + + + +
+ +
+ + + + +
+ + + + + $(document).bind('change')
Live:SELECTMULTICHECKBOXRADIOTEXTTEXTAREADOCUMENT
Bind:SELECTMULTICHECKBOXRADIOTEXTTEXTAREA

Submit Tests

- - - - - - - - - - - - - - + + + + + + + + + + + + + +
- Submit each: - -
- -
-
-
- -
-
-
- -
-
$().bind('submit')
Results:TEXTPASSWORDBUTTONDOCUMENT
+ Submit each: + +
+ +
+
+
+ +
+
+
+ +
+
$(document).bind('submit')
Results:TEXTPASSWORDBUTTONDOCUMENT
- + + diff --git a/test/unit/event.js b/test/unit/event.js index 80a2e6a0b..70c721f82 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -873,26 +873,20 @@ test("live with change", function(){ // test click on select - // first click sets data - if ( !jQuery.support.changeBubbles ) { - select[0].selectedIndex = 1; - select.trigger("keyup"); - } - // second click that changed it selectChange = 0; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger(jQuery.support.changeBubbles ? "change" : "click"); + select.trigger("change"); equals( selectChange, 1, "Change on click." ); // test keys on select selectChange = 0; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger(jQuery.support.changeBubbles ? "change" : "keyup"); + select.trigger("change"); equals( selectChange, 1, "Change on keyup." ); // test click on checkbox - checkbox.trigger(jQuery.support.changeBubbles ? "change" : "click"); + checkbox.trigger("change"); equals( checkboxChange, 1, "Change on checkbox." ); // test before activate on radio @@ -903,12 +897,8 @@ test("live with change", function(){ textareaChange++; }); - if ( !jQuery.support.changeBubbles ) { - textarea.trigger("focus"); - } - textarea.val(oldVal + "foo"); - textarea.trigger(jQuery.support.changeBubbles ? "change" : "blur"); + textarea.trigger("change"); equals( textareaChange, 1, "Change on textarea." ); textarea.val(oldVal); @@ -920,12 +910,8 @@ test("live with change", function(){ textChange++; }); - if ( !jQuery.support.changeBubbles ) { - text.trigger("focus"); - } - text.val(oldVal+"foo"); - text.trigger(jQuery.support.changeBubbles ? "change" : "blur"); + text.trigger("change"); equals( textChange, 1, "Change on text input." ); text.val(oldTextVal); @@ -937,12 +923,8 @@ test("live with change", function(){ passwordChange++; }); - if ( !jQuery.support.changeBubbles ) { - password.trigger("focus"); - } - password.val(oldPasswordVal + "foo"); - password.trigger(jQuery.support.changeBubbles ? "change" : "blur"); + password.trigger("change"); equals( passwordChange, 1, "Change on password input." ); password.val(oldPasswordVal); @@ -954,17 +936,17 @@ test("live with change", function(){ selectChange = 0; select.die("change"); select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger(jQuery.support.changeBubbles ? "change" : "click"); + select.trigger("change"); equals( selectChange, 0, "Die on click works." ); selectChange = 0; select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger(jQuery.support.changeBubbles ? "change" : "keyup"); + select.trigger("change"); equals( selectChange, 0, "Die on keyup works." ); // die specific checkbox checkbox.die("change", checkboxFunction); - checkbox.trigger(jQuery.support.changeBubbles ? "change" : "click"); + checkbox.trigger("change"); equals( checkboxChange, 1, "Die on checkbox." ); }); -- cgit v1.2.3