From d8794a6a25c566e75d7ffb9c062cf2c464728b27 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Tue, 19 Aug 2014 15:26:57 -0700 Subject: [PATCH] fix bug where hover className wouldnt be removed from disabled button. issue 2235 --- src/Header.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Header.js b/src/Header.js index 494bbb7..3127f57 100644 --- a/src/Header.js +++ b/src/Header.js @@ -69,13 +69,13 @@ function Header(calendar, options) { isOnlyButtons = false; } else { - if (calendar[buttonName]) { - buttonClick = calendar[buttonName]; // calendar method - // NOTE: won't work when we move away from parasitic inheritance + if (calendar[buttonName]) { // a calendar method + buttonClick = function() { + calendar[buttonName](); + }; } - else if (fcViews[buttonName]) { + else if (fcViews[buttonName]) { // a view name buttonClick = function() { - button.removeClass(tm + '-state-hover'); // forget why calendar.changeView(buttonName); }; viewsWithButtons.push(buttonName); @@ -113,30 +113,47 @@ function Header(calendar, options) { '' ) .click(function() { + // don't process clicks for disabled buttons if (!button.hasClass(tm + '-state-disabled')) { + buttonClick(); + + // after the click action, if the button becomes the "active" tab, or disabled, + // it should never have a hover class, so remove it now. + if ( + button.hasClass(tm + '-state-active') || + button.hasClass(tm + '-state-disabled') + ) { + button.removeClass(tm + '-state-hover'); + } } }) .mousedown(function() { + // the *down* effect (mouse pressed in). + // only on buttons that are not the "active" tab, or disabled button .not('.' + tm + '-state-active') .not('.' + tm + '-state-disabled') .addClass(tm + '-state-down'); }) .mouseup(function() { + // undo the *down* effect button.removeClass(tm + '-state-down'); }) .hover( function() { + // the *hover* effect. + // only on buttons that are not the "active" tab, or disabled button .not('.' + tm + '-state-active') .not('.' + tm + '-state-disabled') .addClass(tm + '-state-hover'); }, function() { + // undo the *hover* effect button .removeClass(tm + '-state-hover') - .removeClass(tm + '-state-down'); + .removeClass(tm + '-state-down'); // if mouseleave happens before mouseup } );