aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.button.js
diff options
context:
space:
mode:
authorKris Borchers <kris.borchers@gmail.com>2011-05-13 15:28:10 -0400
committerScott González <scott.gonzalez@gmail.com>2011-05-13 15:29:03 -0400
commit427f3d4345c6c3507fefcd9319adaf5588faaad4 (patch)
treef92221f6028b4280b47262bbc23943ce9db021e3 /ui/jquery.ui.button.js
parent16b4ffb791f50d8852289db88eef175b6d1adb97 (diff)
downloadjquery-ui-427f3d4345c6c3507fefcd9319adaf5588faaad4.tar.gz
jquery-ui-427f3d4345c6c3507fefcd9319adaf5588faaad4.zip
Button: Don't fire click/change events if mouse was dragged during click of toggle (checkbox/radio) button. Fixed #6970 - Button state inconsistencies after (accidental) drag-clicking the button.
(cherry picked from commit a69a1788bc5cd67c6e627e519e20897a0c238945)
Diffstat (limited to 'ui/jquery.ui.button.js')
-rw-r--r--ui/jquery.ui.button.js29
1 files changed, 26 insertions, 3 deletions
diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js
index a1be75d8e..2539846f6 100644
--- a/ui/jquery.ui.button.js
+++ b/ui/jquery.ui.button.js
@@ -13,7 +13,7 @@
*/
(function( $, undefined ) {
-var lastActive,
+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",
@@ -111,13 +111,36 @@ $.widget( "ui.button", {
if ( toggleButton ) {
this.element.bind( "change.button", function() {
+ if ( clickDragged ) {
+ return;
+ }
self.refresh();
});
+ // if mouse moves between mousedown and mouseup (drag) set clickDragged flag
+ // prevents issue where button state changes but checkbox/radio checked state
+ // does not in Firefox (see ticket #6970)
+ this.buttonElement
+ .bind( "mousedown.button", function( event ) {
+ if ( options.disabled ) {
+ return;
+ }
+ clickDragged = false;
+ startXPos = event.pageX;
+ startYPos = event.pageY;
+ })
+ .bind( "mouseup.button", function( event ) {
+ if ( options.disabled ) {
+ return;
+ }
+ if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
+ clickDragged = true;
+ }
+ });
}
if ( this.type === "checkbox" ) {
this.buttonElement.bind( "click.button", function() {
- if ( options.disabled ) {
+ if ( options.disabled || clickDragged ) {
return false;
}
$( this ).toggleClass( "ui-state-active" );
@@ -125,7 +148,7 @@ $.widget( "ui.button", {
});
} else if ( this.type === "radio" ) {
this.buttonElement.bind( "click.button", function() {
- if ( options.disabled ) {
+ if ( options.disabled || clickDragged ) {
return false;
}
$( this ).addClass( "ui-state-active" );