diff --git a/docs/templates/pages/javascript.mustache b/docs/templates/pages/javascript.mustache index a73917f5e3105eb57971c947de3b1bb5a64af56a..c02b964513f026887e0eb4ee0b8e885f835284f6 100644 --- a/docs/templates/pages/javascript.mustache +++ b/docs/templates/pages/javascript.mustache @@ -1062,6 +1062,23 @@ $('#my-alert').bind('closed', function () { </div> </pre> + <h4>{{_i}}Radio - Optional{{/i}}</h4> + <p>{{_i}}Add data-toggle="buttons-radio-optional" for radio style toggling on btn-group, where deselecting a choice is allowed.{{/i}}</p> + <div class="bs-docs-example" style="padding-bottom: 24px;"> + <div class="btn-group" data-toggle="buttons-radio-optional"> + <button class="btn btn-primary">{{_i}}Left{{/i}}</button> + <button class="btn btn-primary">{{_i}}Middle{{/i}}</button> + <button class="btn btn-primary">{{_i}}Right{{/i}}</button> + </div> + </div>{{! /example }} +<pre class="prettyprint linenums"> +<div class="btn-group" data-toggle="buttons-radio-optional"> + <button class="btn">Left</button> + <button class="btn">Middle</button> + <button class="btn">Right</button> +</div> +</pre> + <hr class="bs-docs-separator"> diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 7f187be6206f7aadbe4e87b00a2452e4e057f7bc..aea94cc0fef76d4e028f544b25a1348f7c1e75fb 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -51,13 +51,21 @@ } Button.prototype.toggle = function () { - var $parent = this.$element.parent('[data-toggle="buttons-radio"]') - - $parent && $parent - .find('.active') - .removeClass('active') + var $parent = this.$element.parent('[data-toggle="buttons-radio"], [data-toggle="buttons-radio-optional"]') this.$element.toggleClass('active') + + if ($parent && $parent.attr('data-toggle') == 'buttons-radio') { + $parent + .find('.active') + .removeClass('active'); + this.$element.toggleClass('active') + } else if ($parent) { + $parent + .find('.active') + .not(this.$element) + .removeClass('active'); + } } @@ -93,4 +101,4 @@ }) }) -}(window.jQuery); \ No newline at end of file +}(window.jQuery);