diff --git a/bootstrap.css b/bootstrap.css index 69c53f484d55..48441bbc8833 100644 --- a/bootstrap.css +++ b/bootstrap.css @@ -6,7 +6,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Designed and built with all the love in the world @twitter by @mdo and @fat. - * Date: Sun Sep 18 14:19:52 PDT 2011 + * Date: Sun 25 Sep 2011 16:29:58 PDT */ /* Reset.less * Props to Eric Meyer (meyerweb.com) for his CSS reset file. We're using an adapted version here that cuts out some of the reset HTML elements we will never need here (i.e., dfn, samp, etc). @@ -1888,6 +1888,56 @@ button.btn::-moz-focus-inner, input[type=submit].btn::-moz-focus-inner { padding: 0; border: 0; } +.toggle.active { + background-color: #bfbfbf; + background-repeat: repeat-x; + background-image: -khtml-gradient(linear, left top, left bottom, from(#bfbfbf), to(#bfbfbf)); + background-image: -moz-linear-gradient(top, #bfbfbf, #bfbfbf); + background-image: -ms-linear-gradient(top, #bfbfbf, #bfbfbf); + background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #bfbfbf), color-stop(100%, #bfbfbf)); + background-image: -webkit-linear-gradient(top, #bfbfbf, #bfbfbf); + background-image: -o-linear-gradient(top, #bfbfbf, #bfbfbf); + background-image: linear-gradient(top, #bfbfbf, #bfbfbf); + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bfbfbf', endColorstr='#bfbfbf', GradientType=0); + color: #333; + text-decoration: none; + -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05); + -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05); + box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05); +} +.radio .active { + color: #ffffff; + background-color: #0064cd; + background-repeat: repeat-x; + background-image: -khtml-gradient(linear, left top, left bottom, from(#049cdb), to(#0064cd)); + background-image: -moz-linear-gradient(top, #049cdb, #0064cd); + background-image: -ms-linear-gradient(top, #049cdb, #0064cd); + background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #049cdb), color-stop(100%, #0064cd)); + background-image: -webkit-linear-gradient(top, #049cdb, #0064cd); + background-image: -o-linear-gradient(top, #049cdb, #0064cd); + background-image: linear-gradient(top, #049cdb, #0064cd); + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#049cdb', endColorstr='#0064cd', GradientType=0); + text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); + border-color: #0064cd #0064cd #003f81; + border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); +} +.btngroup { + display: inline-block; + vertical-align: bottom; +} +.btngroup .btn { + float: left; + border-radius: 0; +} +.btngroup .btn:nth-child(n+2) { + border-left: none; +} +.btngroup .btn:first-child { + border-radius: 4px 0 0 4px; +} +.btngroup .btn:last-child { + border-radius: 0px 4px 4px 0px; +} .close { float: right; color: #000000; diff --git a/bootstrap.min.css b/bootstrap.min.css index aabdf2428b30..b8220d47f941 100644 --- a/bootstrap.min.css +++ b/bootstrap.min.css @@ -272,6 +272,13 @@ footer{margin-top:17px;padding-top:17px;border-top:1px solid #eee;} .btn.small{padding:7px 9px 7px;font-size:11px;} :root .alert-message,:root .btn{border-radius:0 \0;} button.btn::-moz-focus-inner,input[type=submit].btn::-moz-focus-inner{padding:0;border:0;} +.toggle.active{background-color:#bfbfbf;background-repeat:repeat-x;background-image:-khtml-gradient(linear, left top, left bottom, from(#bfbfbf), to(#bfbfbf));background-image:-moz-linear-gradient(top, #bfbfbf, #bfbfbf);background-image:-ms-linear-gradient(top, #bfbfbf, #bfbfbf);background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #bfbfbf), color-stop(100%, #bfbfbf));background-image:-webkit-linear-gradient(top, #bfbfbf, #bfbfbf);background-image:-o-linear-gradient(top, #bfbfbf, #bfbfbf);background-image:linear-gradient(top, #bfbfbf, #bfbfbf);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#bfbfbf', endColorstr='#bfbfbf', GradientType=0);color:#333;text-decoration:none;-webkit-box-shadow:inset 0 2px 4px rgba(0, 0, 0, 0.25),0 1px 2px rgba(0, 0, 0, 0.05);-moz-box-shadow:inset 0 2px 4px rgba(0, 0, 0, 0.25),0 1px 2px rgba(0, 0, 0, 0.05);box-shadow:inset 0 2px 4px rgba(0, 0, 0, 0.25),0 1px 2px rgba(0, 0, 0, 0.05);} +.radio .active{color:#ffffff;background-color:#0064cd;background-repeat:repeat-x;background-image:-khtml-gradient(linear, left top, left bottom, from(#049cdb), to(#0064cd));background-image:-moz-linear-gradient(top, #049cdb, #0064cd);background-image:-ms-linear-gradient(top, #049cdb, #0064cd);background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #049cdb), color-stop(100%, #0064cd));background-image:-webkit-linear-gradient(top, #049cdb, #0064cd);background-image:-o-linear-gradient(top, #049cdb, #0064cd);background-image:linear-gradient(top, #049cdb, #0064cd);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#049cdb', endColorstr='#0064cd', GradientType=0);text-shadow:0 -1px 0 rgba(0, 0, 0, 0.25);border-color:#0064cd #0064cd #003f81;border-color:rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);} +.btngroup{display:inline-block;vertical-align:bottom;} +.btngroup .btn{float:left;border-radius:0;} +.btngroup .btn:nth-child(n+2){border-left:none;} +.btngroup .btn:first-child{border-radius:4px 0 0 4px;} +.btngroup .btn:last-child{border-radius:0px 4px 4px 0px;} .close{float:right;color:#000000;font-size:20px;font-weight:bold;line-height:13.5px;text-shadow:0 1px 0 #ffffff;filter:alpha(opacity=20);-khtml-opacity:0.2;-moz-opacity:0.2;opacity:0.2;}.close:hover{color:#000000;text-decoration:none;filter:alpha(opacity=40);-khtml-opacity:0.4;-moz-opacity:0.4;opacity:0.4;} .alert-message{position:relative;padding:7px 15px;margin-bottom:18px;color:#404040;background-color:#eedc94;background-repeat:repeat-x;background-image:-khtml-gradient(linear, left top, left bottom, from(#fceec1), to(#eedc94));background-image:-moz-linear-gradient(top, #fceec1, #eedc94);background-image:-ms-linear-gradient(top, #fceec1, #eedc94);background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #fceec1), color-stop(100%, #eedc94));background-image:-webkit-linear-gradient(top, #fceec1, #eedc94);background-image:-o-linear-gradient(top, #fceec1, #eedc94);background-image:linear-gradient(top, #fceec1, #eedc94);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fceec1', endColorstr='#eedc94', GradientType=0);text-shadow:0 -1px 0 rgba(0, 0, 0, 0.25);border-color:#eedc94 #eedc94 #e4c652;border-color:rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);text-shadow:0 1px 0 rgba(255, 255, 255, 0.5);border-width:1px;border-style:solid;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:inset 0 1px 0 rgba(255, 255, 255, 0.25);-moz-box-shadow:inset 0 1px 0 rgba(255, 255, 255, 0.25);box-shadow:inset 0 1px 0 rgba(255, 255, 255, 0.25);}.alert-message .close{*margin-top:3px;} .alert-message h5{line-height:18px;} diff --git a/docs/assets/js/application.js b/docs/assets/js/application.js index 5beba46e1fa4..ed5b16a75299 100644 --- a/docs/assets/js/application.js +++ b/docs/assets/js/application.js @@ -26,6 +26,10 @@ $(document).ready(function(){ e.preventDefault() }) + // radios and toggles + $('.radio .btn').radio() + $('.toggle.btn').toggleBtn(); + // Copy code blocks in docs $(".copy-code").focus(function () { var el = this; diff --git a/docs/index.html b/docs/index.html index 9fcc5c368f31..01961c6139e0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,6 +24,7 @@ + @@ -1291,6 +1292,50 @@

Buttons

+ +
+
+

Button Groups

+

Three flavours: regular, radios and toggles. First, wrap your buttons in a .btngroup.

+

For radios, apply .radio to the wrapper. For toggles, apply .toggle to each button in the group.

+

Get the javascript »

+
+
+

Groups

+
+
+ Left + Right +
+
+ 1 + 2 + 3 + 4 +
+
+

Radios

+

In a radio group, only one button may be active at a time. Add the class .radio to the button group.

+
+
+ Left + Middle + Right +
+
+

Toggles

+

Toggles work like radios, but each button in the group can be set independently. Add .toggle to each button in the button group. Lone buttons can also be toggles.

+
+
+ Left + Middle + Right +
+ + Toggle +
+
+
@@ -1742,6 +1787,10 @@

What's included

bootstrap-popover.js The popover plugin provides a simple interface for adding popovers to your application. It extends the boostrap-twipsy.js plugin, so be sure to grab that file as well when including popovers in your project! + + bootstrap-radiotoggle.js + This plugin adds interaction to radio and toggle button groups. +

Is javascript necessary?

diff --git a/docs/javascript.html b/docs/javascript.html index bb8864d463d3..92151a48d1e4 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -22,6 +22,7 @@ + @@ -52,6 +53,7 @@

Bootstrap JS

  • Twipsy
  • Popover
  • Alerts
  • +
  • Toggles
  • @@ -658,6 +660,73 @@

    Demo

    + +
    + +
    +
    +

    Toggle buttons and radio buttons in button groups.

    + Download +
    +
    +

    Using bootstrap-radiotoggle.js

    +
    +$('.radio .btn').radio()
    +
    +$('.toggle.btn').toggleBtn()
    +

    Markup

    +

    For radio buttons:

    +
    +<div class="btngroup radio">
    +  <a class="btn">Left</a>
    +  <a class="btn">Middle</a>
    +  <a class="btn">Right</a>
    +</div>
    +

    For toggle buttons:

    +
    +<div class="btngroup">
    +  <a class="btn toggle">Left</a>
    +  <a class="btn toggle">Right</a>
    +</div>
    +

    Toggles need not be in a button group:

    +
    +<a class="btn toggle">Toggle</a>
    +

    Methods

    +

    $().radio()

    +

    Adds radio button functionality to selected buttons.

    +

    $().toggleBtn()

    +

    Adds toggle button functionality to selected buttons.

    +

    Demo

    +
    +
    + Left + Middle + Right +
    +
    +
    +
    + Left + Middle + Right +
    + + Toggle +
    + +
    +
    +
    diff --git a/js/bootstrap-radiotoggle.js b/js/bootstrap-radiotoggle.js new file mode 100644 index 000000000000..538eeb39c1e1 --- /dev/null +++ b/js/bootstrap-radiotoggle.js @@ -0,0 +1,29 @@ +/* Radio and toggle buttons */ + +!function( $ ) { + + function activate( element, container ) { + container.find( '.active' ).removeClass( 'active' ) + element.addClass('active') + } + + jQuery.fn.radio = function() { + + return this.each( function() { + var $this = $(this) + $this.click( function() { + activate( $this, $this.parent() ) + }) + }) + } + + jQuery.fn.toggleBtn = function() { + return this.each( function() { + var $this = $(this) + $this.click( function() { + $this.toggleClass('active') + }) + }) + } + +}( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/tests/index.html b/js/tests/index.html index 2ca94102ad32..99f12334daf8 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -17,6 +17,7 @@ + @@ -25,6 +26,8 @@ + +
    diff --git a/js/tests/unit/bootstrap-radiotoggle.js b/js/tests/unit/bootstrap-radiotoggle.js new file mode 100644 index 000000000000..75ac8fde8106 --- /dev/null +++ b/js/tests/unit/bootstrap-radiotoggle.js @@ -0,0 +1,39 @@ +$(function () { + + module("bootstrap-radiotoggle") + + test("should be defined on jquery object", function () { + ok($(document.body).radio, 'radio method is defined') + ok($(document.body).toggleBtn, 'toggleBtn method is defined') + }) + + test("should return element", function () { + ok($(document.body).radio()[0] == document.body, 'radio method returned document.body' ) + ok($(document.body).toggleBtn()[0] == document.body, 'toggleBtn method returned document.body') + }) + + test("should toggle element on click (toggleBtn)", function () { + var toggleHTML = 'Toggle' + , toggle = $(toggleHTML).toggleBtn() + + toggle.click() + + ok(toggle.hasClass('active'), 'add .active on click') + + toggle.click() + + ok(!toggle.hasClass('active'), 'remove .active on next click') + }) + + test("should activate focused radio on click (radio)", function () { + var radioHTML = '
    ' + + 'OneTwo' + + '
    ' + , radio = $(radioHTML).find('a').radio() + + radio.eq(0).click() + + ok(radio.eq(0).hasClass('active'), 'add .active to focused button') + ok(!radio.eq(1).hasClass('active'), 'remove .active from other buttons') + }) +}) \ No newline at end of file diff --git a/lib/patterns.less b/lib/patterns.less index ce387614e9a1..9b674ac916fa 100644 --- a/lib/patterns.less +++ b/lib/patterns.less @@ -591,6 +591,7 @@ footer { font-size: @basefont - 2px; } } + // Super jank hack for removing border-radius from IE9 so we can keep filter gradients on alerts and buttons :root .alert-message, :root .btn { @@ -606,6 +607,40 @@ input[type=submit].btn { } } +// RADIO, TOGGLE AND GROUPED BUTTONS +// --------------------------------- + +// active state for radio and toggle buttons +.toggle.active { + #gradient > .vertical(darken(#ffffff, 25%), darken(#ffffff, 25%)); + color: #333; + text-decoration: none; + @shadow: inset 0 2px 4px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.05); + .box-shadow(@shadow); +} +.radio .active { + color: @white; + .gradientBar(@blue, @blueDark) +} + +// Classes for button groups +.btngroup { + display: inline-block; + vertical-align: bottom; +} +.btngroup .btn { + float: left; + border-radius: 0; +} +.btngroup .btn:nth-child(n+2) { + border-left: none; +} +.btngroup .btn:first-child { + border-radius: 4px 0 0 4px; +} +.btngroup .btn:last-child { + border-radius: 0px 4px 4px 0px; +} // CLOSE ICONS // -----------