Twitter boostrap radio to button-radio
The idea here is to auto-transform a radio group as a twitter bootstrap button with the radio-group simulated
by clawfire
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/bootstrap.min.js"></script>
<form action="#" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="user[orderMagazine]">Wanna receive cool stuff for free ?</label>
<div class="" data-toggle="buttonCheckbox">
<label class="">
<input type="radio" name="user[orderMagazine]" value="0" checked="checked">
Nop
</label>
<label class="">
<input type="radio" name="user[orderMagazine]" value="1">
Yep, digital goods only
</label>
<label class="">
<input type="radio" name="user[orderMagazine]" value="2">
Yep, fancy old physical paper please.
</label>
</div>
</div>
</form>
CSS
/*!
* Bootstrap v2.2.2
*
* Copyright 2012 Twitter, Inc
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world @twitter by @mdo and @fat.
*/
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section {
display: block;
}
audio, canvas, video {
display: inline-block;
*display: inline;
*zoom: 1;
}
audio:not([controls]) {
display: none;
}
html {
font-size: 100%;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
a:focus {
outline: thin dotted #333;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
a:hover, a:active {
outline: 0;
}
sub, sup {
position: relative;
font-size: 75%;
line-height: 0;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
img {
width: auto\9;
height: auto;
max-width: 100%;
vertical-align: middle;
border: 0;
-ms-interpolation-mode: bicubic;
}
#map_canvas img, .google-maps img {
max-width: none;
}
button, input, select, textarea {
margin: 0;
font-size: 100%;
vertical-align: middle;
}
button, input {
*overflow: visible;
line-height: normal;
}
button::-moz-focus-inner, input::-moz-focus-inner {
padding: 0;
border: 0;
}
button, html input[type="button"], input[type="reset"], input[type="submit"] {
cursor: pointer;
-webkit-appearance: button;
}
label, select, button, input[type="button"], input[type="reset"], input[type="submit"], input[type="radio"], input[type="checkbox"] {
cursor: pointer;
}
input[type="search"] {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
-webkit-appearance: textfield;
}
input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none;
}
textarea {
overflow: auto;
vertical-align: top;
}
@media...
JavaScript
$('[data-toggle="buttonCheckbox"]').prepend('<div class="controls"><div class="btn-group" data-toggle="buttons-radio"></div></div>').find('label').addClass('hide');
$('label','[data-toggle="buttonCheckbox"]').each(function(){
var input = $('input',this);
if(input.is(':checked'))var component = '<button type="button" class="btn btn-small active"></button>';
else var component = '<button type="button" class="btn btn-small"></button>';
$(component).text($(this).text()).on('click',input,function(event){
input.click();
}).appendTo('.btn-group',$(this).closest('[data-toggle="buttonCheckbox"]'));
});