1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-12 08:34:08 +02:00

update buttons js for button groups

This commit is contained in:
Jacob Thornton
2011-11-24 14:43:26 -08:00
parent 36a7eb3851
commit b2650859d6
5 changed files with 136 additions and 15 deletions

View File

@@ -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')
})
})