From ea50e8aeeed6616a61a7e44d28fe60ced327be0c Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 29 Oct 2011 18:49:35 -0700 Subject: [PATCH] add active class to css for buttons, write new spec for button, "use strict" --- bootstrap.css | 2 +- docs/javascript.html | 24 +++++++++-------- js/bootstrap-alerts.js | 2 ++ js/bootstrap-buttons.js | 18 ++++++++++--- js/bootstrap-dropdown.js | 2 ++ js/bootstrap-modal.js | 37 ++++++++++++++------------ js/bootstrap-popover.js | 2 ++ js/bootstrap-scrollspy.js | 2 ++ js/bootstrap-tabs.js | 3 +++ js/bootstrap-twipsy.js | 2 ++ js/tests/index.html | 4 ++- js/tests/unit/bootstrap-buttons.js | 42 ++++++++++++++++++++++++++++++ lib/patterns.less | 3 ++- 13 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 js/tests/unit/bootstrap-buttons.js diff --git a/bootstrap.css b/bootstrap.css index d849cfb605..2f4924eb03 100644 --- a/bootstrap.css +++ b/bootstrap.css @@ -1917,7 +1917,7 @@ footer { 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); } -.btn:active { +.btn:active, .btn.active { -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); diff --git a/docs/javascript.html b/docs/javascript.html index 02c0f6a004..47edf2b751 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -314,7 +314,7 @@ $('#my-modal').bind('hidden', function () { -
@@ -329,10 +329,11 @@ $('#my-modal').bind('hidden', function () {

Using bootstrap-buttons.js

$('.tabs').button()
-

Markup

-

You can leverage bootstraps button toggle helper without writing any javascript by using the data-toggle attribute.

-
<button class="btn" data-toggle="toggle" >...</button>

Methods

+

$().button('toggle')

+

Toggles push state. Gives btn the look that it's been activated.

+

Notice You can enable auto toggling of a button by using the data-toggle attribute.

+
<button class="btn" data-toggle="toggle" >...</button>

$().button('loading')

Sets button state to loading - disables button and swaps text to loading text. Loading text should be defined on the button element using the data attribute data-loading-text.

@@ -346,7 +347,8 @@ $('#my-modal').bind('hidden', function () { $('.btn').button('complete') </scrip>

Demo

- + + + @@ -17,6 +17,7 @@ + @@ -25,6 +26,7 @@ +
diff --git a/js/tests/unit/bootstrap-buttons.js b/js/tests/unit/bootstrap-buttons.js new file mode 100644 index 0000000000..9784f52224 --- /dev/null +++ b/js/tests/unit/bootstrap-buttons.js @@ -0,0 +1,42 @@ +$(function () { + + module("bootstrap-buttons") + + test("should be defined on jquery object", function () { + ok($(document.body).button, 'tabs method is defined') + }) + + test("should return element", function () { + ok($(document.body).button()[0] == document.body, 'document.body returned') + }) + + test("should return set state to loading", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') + }) + + test("should return reset state", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn is disabled') + btn.button('reset') + equals(btn.html(), 'mdo', 'btn text equals mdo') + ok(!btn.attr('disabled'), 'btn is not disabled') + ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + }) + + test("should toggle active", function () { + var btn = $('') + ok(!btn.hasClass('active'), 'btn does not have active class') + btn.button('toggle') + ok(btn.hasClass('active'), 'btn has class active') + }) + +}) \ No newline at end of file diff --git a/lib/patterns.less b/lib/patterns.less index 5f4192d893..307bfe4e66 100644 --- a/lib/patterns.less +++ b/lib/patterns.less @@ -573,7 +573,8 @@ footer { .transition(.1s linear all); // Active and Disabled states - &:active { + &.active, + :active { @shadow: inset 0 2px 4px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.05); .box-shadow(@shadow); }