r3315 committed - Buttons: Refactored tracking of last active button.
Revision: 3315
Author: scott.gonzalez
Date: Mon Sep 28 16:56:41 2009
Log: Buttons: Refactored tracking of last active button.
http://code.google.com/p/jquery-ui/source/detail?r=3315
Modified:
/branches/dev/ui/jquery.ui.button.js
=======================================
--- /branches/dev/ui/jquery.ui.button.js Mon Sep 28 10:01:08 2009
+++ /branches/dev/ui/jquery.ui.button.js Mon Sep 28 16:56:41 2009
@@ -12,6 +12,8 @@
*/
(function($) {
+var lastActive;
+
$.widget("ui.button", {
_init: function() {
var self = this;
@@ -20,17 +22,25 @@
.bind("mouseenter.button", function() {
if (self.options.disabled) { return; }
$(this).addClass("ui-state-hover");
- if (self.wasactive)
+ if (this == lastActive) {
$(this).addClass("ui-state-active");
+ }
})
.bind("mouseleave.button", function() {
if (self.options.disabled) { return; }
- self.wasactive = $(this).hasClass("ui-state-active");
$(this).removeClass("ui-state-hover ui-state-active");
})
- .bind("mousedown.button mouseup.button", function() {
+ .bind("mousedown.button", function() {
if (self.options.disabled) { return; }
- $(this).toggleClass("ui-state-active");
+ $(this).addClass("ui-state-active");
+ lastActive = this;
+ $(document).one('mouseup', function() {
+ lastActive = null;
+ });
+ })
+ .bind("mouseup.button", function() {
+ if (self.options.disabled) { return; }
+ $(this).removeClass("ui-state-active");
})
.bind("click", function(event) {
if (self.options.disabled) {
@@ -39,11 +49,6 @@
event.stopImmediatePropagation();
}
});
- // need to capture mouseup event outside a button, in case of
mousedown-mouseleave-mouseup
- // would be nice to replace this with something less obtrusive
- $().bind("mouseup.button", function() {
- self.wasactive = false;
- })
},
destroy: function() {
@@ -147,7 +152,7 @@
$(this).addClass("ui-corner-right");
}
});
-}
+};
})(jQuery);