diff --git a/js/button.js b/js/button.js index aa71450722..1d524154e6 100644 --- a/js/button.js +++ b/js/button.js @@ -97,14 +97,30 @@ } + // FOCUS SHIM (FOR BUTTON GROUPS) + // ============================== + + function getBtnTarget(target) { + var $target = $(target) + return $target.hasClass('btn') ? $target : $target.parent('.btn') + } + + // BUTTON DATA-API // =============== - $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { - var $btn = $(e.target) - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') - Plugin.call($btn, 'toggle') - e.preventDefault() - }) + $(document) + .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + Plugin.call($btn, 'toggle') + e.preventDefault() + }) + .on('focus.bs.button.data-api', '[data-toggle^="button"]', function (e) { + getBtnTarget(e.target).addClass('focus') + }) + .on('blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { + getBtnTarget(e.target).removeClass('focus') + }) }(jQuery);