r3540 committed - button refactoring: toggleButton to use the label instead of creating ...

r3540 committed - button refactoring: toggleButton to use the label instead of creating ...

Revision: 3540
Author: joern.zaefferer
Date: Sun Dec 27 06:15:23 2009
Log: button refactoring: toggleButton to use the label instead of creating
a button element
http://code.google.com/p/jquery-ui/source/detail?r=3540
Modified:
/branches/dev/ui/jquery.ui.button.js
=======================================
--- /branches/dev/ui/jquery.ui.button.js    Wed Dec 23 11:02:51 2009
+++ /branches/dev/ui/jquery.ui.button.js    Sun Dec 27 06:15:23 2009
@@ -30,7 +30,7 @@
var lastActive,
    baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
-    otherClasses = "ui-state-hover ui-state-focus " +
+    otherClasses = "ui-state-hover ui-state-active " +
        "ui-button-icons-only ui-button-icon-only ui-button-text-icons
ui-button-text-icon";
$.widget("ui.button", {
@@ -125,36 +125,32 @@
// TODO merge with button-widget
$.widget("ui.toggleButton", {
    _init: function() {
+        this.element.hide();
        var self = this,
            label = (this.label = $("[for='" + this.element.attr("id") + "']"));
-
-        label.add(this.element).hide();
-        this.button = $("<button/>")
-            .html("" + label.html())
-            .insertAfter(this.element)
-            .button()
+        label.button()
            .unbind("mousedown.button mouseup.button mouseleave.button")
-            .bind("click", function() {
+            .bind("click.button", function() {
                if (self.options.disabled) { return; }
                $(this).toggleClass("ui-state-active");
                self.element.attr("checked", function() {
-                    return !!this.checked;
+                    return !this.checked;
                })
                .click();
            })
-            .bind("mouseleave", function() {
+            .bind("mouseleave.button", function() {
                if (self.options.disabled) { return; }
                $(this).removeClass("ui-state-hover");
            });
-
+
        if (this.element.attr("checked")) {
-            this.button.addClass("ui-state-active");
+            label.addClass("ui-state-active");
        }
    },
    destroy: function() {
-        this.element.add(this.label).show();
-        this.button.remove();
+        this.element.show();
+        this.label.button("destroy");
        $.Widget.prototype.destroy.call(this);
    },
@@ -214,7 +210,7 @@
$.widget("ui.buttons", {
    _init: function() {
-        var buttons = this.buttons = this.element.find("button, :submit, :reset,
a").button();
+        var buttons = (this.buttons =
this.element.find("button, :submit, :reset, a").button());
        if (!buttons.length) {
            this.toggle = this.element.find(":checkbox").toggleButton();
            buttons = this.toggle.next();
--