Skip to content

Commit

Permalink
Merge pull request #13907 from twbs/fat-12145
Browse files Browse the repository at this point in the history
add "focus" to focused btns with button plugin
  • Loading branch information
mdo committed Jul 7, 2014
2 parents 719cde1 + 6b6476f commit 907b3b2
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 907b3b2

Please sign in to comment.