aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2011-11-24 14:43:26 -0800
committerJacob Thornton <[email protected]>2011-11-24 14:43:26 -0800
commitb2650859d6c6dcb0665311b6e983d230fee1111f (patch)
tree5fc6bae4bf825eec78d79c99f99914ccfc3c0401 /js
parent36a7eb3851855b608266f301a63b561ac316bca9 (diff)
downloadbootstrap-b2650859d6c6dcb0665311b6e983d230fee1111f.tar.xz
bootstrap-b2650859d6c6dcb0665311b6e983d230fee1111f.zip
update buttons js for button groups
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-buttons.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js
index 2fe1a7352..759a65f84 100644
--- a/js/bootstrap-buttons.js
+++ b/js/bootstrap-buttons.js
@@ -25,26 +25,36 @@
var d = 'disabled'
, $el = $(el)
, data = $el.data()
+ , val = $el.is('input') ? 'val' : 'html'
state = state + 'Text'
- data.resetText || $el.data('resetText', $el.html())
+ data.resetText || $el.data('resetText', $el[val]())
- $el.html( data[state] || $.fn.button.defaults[state] )
+ $el[val]( data[state] || $.fn.button.defaults[state] )
- state == 'loadingText' ?
- $el.addClass(d).attr(d, d) :
- $el.removeClass(d).removeAttr(d)
+ setTimeout(function () {
+ state == 'loadingText' ?
+ $el.addClass(d).attr(d, d) :
+ $el.removeClass(d).removeAttr(d)
+ }, 0)
}
function toggle(el) {
- $(el).toggleClass('active')
+ var $el = $(el)
+ , $parent = $el.parent('[data-toggle="buttons-radio"]')
+
+ if ($parent) {
+ $parent
+ .find('.active')
+ .removeClass('active')
+ }
+
+ $el.toggleClass('active')
}
$.fn.button = function(options) {
return this.each(function () {
- if (options == 'toggle') {
- return toggle(this)
- }
+ if (options == 'toggle') return toggle(this)
options && setState(this, options)
})
}
@@ -54,8 +64,8 @@
}
$(function () {
- $('body').delegate('.btn[data-toggle]', 'click', function () {
- $(this).button('toggle')
+ $('body').delegate('[data-toggle^=button]', 'click', function (e) {
+ $(e.srcElement).button('toggle')
})
})