From 2de31fdbf498a6c20d196a96d007ea0f069644c5 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Sun, 7 Apr 2013 12:57:15 -0400 Subject: Button: On form reset only call refresh on current button widgets. Fixed #9213: Button: timeout in formResetHandler causing refresh to be called on non-widgets --- tests/unit/button/button_core.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/unit/button') diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index dbc079818..16c7ca450 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -153,6 +153,30 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) ); }); +asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function() { + expect( 2 ); + var form = $( "
" + + "" + + "" + + "
" ), + button = form.find( "button" ).button(), + checkbox = form.find( "input[type=checkbox]" ).button(); + + checkbox.prop( "checked", false ).button( "refresh" ); + ok( !checkbox.button( "widget" ).hasClass( "ui-state-active" ) ); + + form.get( 0 ).reset(); + + // #9213: If a button has been removed, refresh should not be called on it when + // its corresponding form is reset. + button.remove(); + + setTimeout(function() { + ok( checkbox.button( "widget" ).hasClass( "ui-state-active" )); + start(); + }); +}); + asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() { expect( 2 ); var check = $( "#check" ).button(), -- cgit v1.2.3 From 0d0b05ec7cf702b8782b19c993eeb30398a090f4 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 11 Apr 2013 14:03:51 -0400 Subject: Button: Remove ui-state-focus class when becoming disabled. Fixes #9169 - Button: Disabled button maintains ui-state-focus in IE & Firefox on Windows. --- tests/unit/button/button.html | 2 ++ tests/unit/button/button_core.js | 13 +++++++++++++ ui/jquery.ui.button.js | 27 +++++++++++++++------------ 3 files changed, 30 insertions(+), 12 deletions(-) (limited to 'tests/unit/button') diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html index eeb568686..223581ef7 100644 --- a/tests/unit/button/button.html +++ b/tests/unit/button/button.html @@ -71,6 +71,8 @@
+ + diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index 16c7ca450..55dda68b3 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -196,4 +196,17 @@ test( "#7534 - Button label selector works for ids with \":\"", function() { ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" ); }); +asyncTest( "#9169 - Disabled button maintains ui-state-focus", function() { + expect( 2 ); + var element = $( "#button1" ).button(); + element[ 0 ].focus(); + setTimeout(function() { + ok( element.hasClass( "ui-state-focus" ), "button has ui-state-focus" ); + element.button( "disable" ); + ok( !element.hasClass( "ui-state-focus" ), + "button does not have ui-state-focus when disabled" ); + start(); + }); +}); + })(jQuery); diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index dd6892275..ae3b86ae9 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -16,7 +16,6 @@ var lastActive, startXPos, startYPos, clickDragged, baseClasses = "ui-button ui-widget ui-state-default ui-corner-all", - stateClasses = "ui-state-hover ui-state-active ", typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only", formResetHandler = function() { var form = $( this ); @@ -71,8 +70,7 @@ $.widget( "ui.button", { var that = this, options = this.options, toggleButton = this.type === "checkbox" || this.type === "radio", - activeClass = !toggleButton ? "ui-state-active" : "", - focusClass = "ui-state-focus"; + activeClass = !toggleButton ? "ui-state-active" : ""; if ( options.label === null ) { options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html()); @@ -104,14 +102,16 @@ $.widget( "ui.button", { } }); - this.element - .bind( "focus" + this.eventNamespace, function() { - // no need to check disabled, focus won't be triggered anyway - that.buttonElement.addClass( focusClass ); - }) - .bind( "blur" + this.eventNamespace, function() { - that.buttonElement.removeClass( focusClass ); - }); + // Can't use _focusable() because the element that receives focus + // and the element that gets the ui-state-focus class are different + this._on({ + focus: function() { + this.buttonElement.addClass( "ui-state-focus" ); + }, + blur: function() { + this.buttonElement.removeClass( "ui-state-focus" ); + } + }); if ( toggleButton ) { this.element.bind( "change" + this.eventNamespace, function() { @@ -257,7 +257,7 @@ $.widget( "ui.button", { this.element .removeClass( "ui-helper-hidden-accessible" ); this.buttonElement - .removeClass( baseClasses + " " + stateClasses + " " + typeClasses ) + .removeClass( baseClasses + " ui-state-active " + typeClasses ) .removeAttr( "role" ) .removeAttr( "aria-pressed" ) .html( this.buttonElement.find(".ui-button-text").html() ); @@ -272,6 +272,9 @@ $.widget( "ui.button", { if ( key === "disabled" ) { this.widget().toggleClass( "ui-state-disabled", !!value ); this.element.prop( "disabled", !!value ); + if ( value ) { + this.buttonElement.removeClass( "ui-state-focus" ); + } return; } this._resetButton(); -- cgit v1.2.3 From 7c939aadf8c661f1230627d51bf1450f99effcc3 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Sun, 14 Apr 2013 12:58:42 -0400 Subject: Test Suite: Remove Flaky Datepicker test, and correct more old jQuery test cases for old Opera and old Safari. --- tests/unit/button/button_core.js | 2 +- tests/unit/datepicker/datepicker_options.js | 11 ++++++----- tests/unit/draggable/draggable_core.js | 1 + tests/unit/draggable/draggable_options.js | 13 +++++++++---- 4 files changed, 17 insertions(+), 10 deletions(-) (limited to 'tests/unit/button') diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index 55dda68b3..6df7da9db 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -166,7 +166,7 @@ asyncTest( "Resetting a button's form should refresh the visual state of the but ok( !checkbox.button( "widget" ).hasClass( "ui-state-active" ) ); form.get( 0 ).reset(); - + // #9213: If a button has been removed, refresh should not be called on it when // its corresponding form is reset. button.remove(); diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index a5d66314c..a763b2fda 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -1066,11 +1066,12 @@ test("formatDate", function() { "Format date 'jour' d 'de' MM (''DD''), yy with settings"); }); -test("Ticket 6827: formatDate day of year calculation is wrong during day lights savings time", function(){ - expect( 1 ); - var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT")); - equal(time, "089"); -}); +// TODO: Fix this test so it isn't mysteriously flaky in Browserstack on certain OS/Browser combos +// test("Ticket 6827: formatDate day of year calculation is wrong during day lights savings time", function(){ +// expect( 1 ); +// var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT")); +// equal(time, "089"); +// }); test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler", function() { expect( 3 ); diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js index dd71bd48b..e7fcdfa87 100644 --- a/tests/unit/draggable/draggable_core.js +++ b/tests/unit/draggable/draggable_core.js @@ -94,6 +94,7 @@ test( "#8269: Removing draggable element on drop", function() { // Support: Opera 12.10, Safari 5.1, jQuery <1.8 if ( TestHelpers.draggable.unreliableContains ) { ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); + ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); } else { element.simulate( "drag", { handle: "corner", diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index c361318b1..ef551003d 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -472,10 +472,15 @@ test( "#6889: Cursor doesn't revert to pre-dragging state after revert action wh }), expected = getCursor(); - element.simulate( "drag", { - dx: -1, - dy: -1 - }); + if ( TestHelpers.draggable.unreliableContains ) { + ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); + ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); + } else { + element.simulate( "drag", { + dx: -1, + dy: -1 + }); + } }); test( "cursor, default, switching after initialization", function() { -- cgit v1.2.3