Skip to content

Commit

Permalink
buttons-radio-optional: just like buttons-radio but a clicked button …
Browse files Browse the repository at this point in the history
…can be un-clicked
  • Loading branch information
philfreo committed Jul 4, 2012
1 parent 857b8fb commit c191522
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
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);

0 comments on commit c191522

Please sign in to comment.