Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a way to have buttons-radio but where a clicked button can be un-selected #3991

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions docs/assets/js/bootstrap-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}


Expand Down Expand Up @@ -93,4 +101,4 @@
})
})

}(window.jQuery);
}(window.jQuery);
21 changes: 15 additions & 6 deletions docs/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,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');
}
}


Expand Down Expand Up @@ -242,7 +250,8 @@
})
})

}(window.jQuery);/* ==========================================================
}(window.jQuery);
/* ==========================================================
* bootstrap-carousel.js v2.0.4
* http://twitter.github.com/bootstrap/javascript.html#carousel
* ==========================================================
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 docs/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,16 @@ <h2>Example uses</h2>
</div>
</td>
</tr>
<tr>
<td>Optional Radio</td>
<td>
<div class="btn-group" data-toggle="buttons-radio-optional">
<button class="btn btn-primary">Left</button>
<button class="btn btn-primary">Middle</button>
<button class="btn btn-primary">Right</button>
</div>
</td>
</tr>
</tbody>
</table>
<hr>
Expand Down Expand Up @@ -1482,6 +1492,7 @@ <h4>.typeahead(options)</h4>
</div>
</section>


<!-- Footer
================================================== -->
<footer class="footer">
Expand Down
12 changes: 11 additions & 1 deletion docs/templates/pages/javascript.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,16 @@ $('#my-alert').bind('closed', function () {
</div>
</td>
</tr>
<tr>
<td>{{_i}}Optional Radio{{/i}}</td>
<td>
<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>
</td>
</tr>
</tbody>
</table>
<hr>
Expand Down Expand Up @@ -1402,4 +1412,4 @@ $('.carousel').carousel({
<p>{{_i}}Initializes an input with a typeahead.{{/i}}</p>
</div>
</div>
</section>
</section>
20 changes: 14 additions & 6 deletions js/bootstrap-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}


Expand Down Expand Up @@ -93,4 +101,4 @@
})
})

}(window.jQuery);
}(window.jQuery);