Skip to content

Commit

Permalink
Added untoggle api method to forcefully untoggle a button.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobstr committed Mar 4, 2013
1 parent eb24718 commit 3ac86f6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/assets/js/bootstrap-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
this.$element.toggleClass('active')
}

Button.prototype.untoggle = function() {
var $parent = this.$element.closest('[data-toggle="buttons-radio"]')

$parent && $parent
.find('.active')
.removeClass('active')

this.$element.removeClass('active')
}


/* BUTTON PLUGIN DEFINITION
* ======================== */
Expand All @@ -73,6 +83,7 @@
, options = typeof option == 'object' && option
if (!data) $this.data('button', (data = new Button(this, options)))
if (option == 'toggle') data.toggle()
else if (option == 'untoggle') data.untoggle()
else if (option) data.setState(option)
})
}
Expand Down
11 changes: 11 additions & 0 deletions docs/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@
this.$element.toggleClass('active')
}

Button.prototype.untoggle = function() {
var $parent = this.$element.closest('[data-toggle="buttons-radio"]')

$parent && $parent
.find('.active')
.removeClass('active')

this.$element.removeClass('active')
}


/* BUTTON PLUGIN DEFINITION
* ======================== */
Expand All @@ -230,6 +240,7 @@
, options = typeof option == 'object' && option
if (!data) $this.data('button', (data = new Button(this, options)))
if (option == 'toggle') data.toggle()
else if (option == 'untoggle') data.untoggle()
else if (option) data.setState(option)
})
}
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/bootstrap.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions js/bootstrap-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
this.$element.toggleClass('active')
}

Button.prototype.untoggle = function() {
var $parent = this.$element.closest('[data-toggle="buttons-radio"]')

$parent && $parent
.find('.active')
.removeClass('active')

this.$element.removeClass('active')
}


/* BUTTON PLUGIN DEFINITION
* ======================== */
Expand All @@ -73,6 +83,7 @@
, options = typeof option == 'object' && option
if (!data) $this.data('button', (data = new Button(this, options)))
if (option == 'toggle') data.toggle()
if (option == 'untoggle') data.untoggle()
else if (option) data.setState(option)
})
}
Expand Down
7 changes: 7 additions & 0 deletions js/tests/unit/bootstrap-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ $(function () {
ok(btn.hasClass('active'), 'btn has class active')
})

test("should untoggle", function() {
var btn = $('<button class="btn active">mdo</button>')
ok(btn.hasClass('active'), 'btn should have active class initially')
btn.button('untoggle')
ok(!btn.hasClass('active'), 'btn does not have active class')
})

test("should toggle active when btn children are clicked", function () {
var btn = $('<button class="btn" data-toggle="button">mdo</button>')
, inner = $('<i></i>')
Expand Down

0 comments on commit 3ac86f6

Please sign in to comment.