r3564 committed - Buttons: proper support for radio toggling.

r3564 committed - Buttons: proper support for radio toggling.

Revision: 3564
Author: scott.gonzalez
Date: Wed Dec 30 12:14:25 2009
Log: Buttons: proper support for radio toggling.
http://code.google.com/p/jquery-ui/source/detail?r=3564
Modified:
/branches/dev/ui/jquery.ui.button.js
=======================================
--- /branches/dev/ui/jquery.ui.button.js    Wed Dec 30 10:17:06 2009
+++ /branches/dev/ui/jquery.ui.button.js    Wed Dec 30 12:14:25 2009
@@ -13,16 +13,6 @@
*/
(function($) {
-/*
-
-Todo:
-- uncheck other radios when one is clicked
-
-Notes:
-- disabling a button set makes buttons very hard to see because they're
faded twice
-
-*/
-
var lastActive,
    baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
    otherClasses = "ui-state-hover ui-state-active " +
@@ -63,33 +53,46 @@
                $(this).removeClass(hoverClass);
            });
-        if (toggleButton) {
-            this.buttonElement.bind('click.button', function() {
-                if (options.disabled) { return; }
-                $(this).toggleClass("ui-state-active");
-                self.element
-                    .attr("checked", function() {
-                        return self.type == 'checkbox'
-                            ? !this.checked
-                            // radio
-                            : true;
-                    })
-                    .click();
-            });
-        } else {
-            this.buttonElement
-                .bind("mousedown.button", function() {
+        switch (this.type) {
+            case 'checkbox':
+                this.buttonElement.bind('click.button', function() {
                    if (options.disabled) { return; }
-                    $(this).addClass("ui-state-active");
-                    lastActive = this;
-                    $(document).one('mouseup', function() {
-                        lastActive = null;
-                    });
-                })
-                .bind("mouseup.button", function() {
+                    $(this).toggleClass("ui-state-active");
+                    self.element
+                        .attr("checked", !this.checked)
+                        .click();
+                });
+            break;
+            case 'radio':
+                this.buttonElement.bind('click.button', function() {
                    if (options.disabled) { return; }
-                    $(this).removeClass("ui-state-active");
+                    $(this).addClass("ui-state-active");
+                    self.element
+                        .attr("checked", true)
+                        .click();
+                    $('[name=' + self.element.attr('name') + ']')
+                        .not(self.element)
+                        .map(function() {
+                            return $(this).button('widget')[0];
+                        })
+                        .removeClass('ui-state-active');
                });
+            break;
+            default:
+                this.buttonElement
+                    .bind("mousedown.button", function() {
+                        if (options.disabled) { return; }
+                        $(this).addClass("ui-state-active");
+                        lastActive = this;
+                        $(document).one('mouseup', function() {
+                            lastActive = null;
+                        });
+                    })
+                    .bind("mouseup.button", function() {
+                        if (options.disabled) { return; }
+                        $(this).removeClass("ui-state-active");
+                    });
+            break;
        }
        this._resetButton();
--