Skip to content

Commit

Permalink
add active class to css for buttons, write new spec for button, "use …
Browse files Browse the repository at this point in the history
…strict"
  • Loading branch information
fat committed Oct 30, 2011
1 parent e8b66a9 commit ea50e8a
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions docs/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ <h3>Demo</h3>
</div>
</section>

<!-- Tabs
<!-- Buttons
================================================== -->

<section id="buttons">
Expand All @@ -329,10 +329,11 @@ <h1>Buttons <small>bootstrap-buttons.js</small></h1>
<div class="span12 columns">
<h3>Using bootstrap-buttons.js</h3>
<pre class="prettyprint linenums">$('.tabs').button()</pre>
<h3>Markup</h3>
<p>You can leverage bootstraps button toggle helper without writing any javascript by using the <code>data-toggle</code> attribute.</p>
<pre class="prettyprint linenums">&lt;button class="btn" data-toggle="toggle" &gt;...&lt;/button&gt;</pre>
<h3>Methods</h3>
<h4>$().button('toggle')</h4>
<p>Toggles push state. Gives btn the look that it's been activated.</p>
<p><span class="label notice">Notice</span> You can enable auto toggling of a button by using the <code>data-toggle</code> attribute.</p>
<pre class="prettyprint linenums">&lt;button class="btn" data-toggle="toggle" &gt;...&lt;/button&gt;</pre>
<h4>$().button('loading')</h4>
<p>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 <code>data-loading-text</code>.
</p>
Expand All @@ -346,7 +347,8 @@ <h4>$().button(string)</h4>
$('.btn').button('complete')
&lt;/scrip&gt;</pre>
<h3>Demo</h3>
<button id="fat-btn" class="btn danger">Click me</button>
<button id="fat-btn" data-loading-text="foo" class="btn danger">Loading Demo</button>
<button class="btn" data-toggle="toggle">Toggle Demo</button>
<script>
$(function() {
var btn = $('#fat-btn').click(function () {
Expand Down Expand Up @@ -442,22 +444,22 @@ <h3>Demo</h3>
</li>
</ul>
<div id="my-tab-content" class="tab-content">
<div class="active" id="home">
<div class="active tab-pane" id="home">
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</div>
<div id="profile">
<div class="tab-pane" id="profile">
<p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.</p>
</div>
<div id="messages">
<div class="tab-pane" id="messages">
<p>Banksy do proident, brooklyn photo booth delectus sunt artisan sed organic exercitation eiusmod four loko. Quis tattooed iphone esse aliqua. Master cleanse vero fixie mcsweeney's. Ethical portland aute, irony food truck pitchfork lomo eu anim. Aesthetic blog DIY, ethical beard leggings tofu consequat whatever cardigan nostrud. Helvetica you probably haven't heard of them carles, marfa veniam occaecat lomo before they sold out in shoreditch scenester sustainable thundercats. Consectetur tofu craft beer, mollit brunch fap echo park pitchfork mustache dolor.</p>
</div>
<div id="settings">
<div class="tab-pane" id="settings">
<p>Sunt qui biodiesel mollit officia, fanny pack put a bird on it thundercats seitan squid ad wolf bicycle rights blog. Et aute readymade farm-to-table carles 8-bit, nesciunt nulla etsy adipisicing organic ea. Master cleanse mollit high life, next level Austin nesciunt american apparel twee mustache adipisicing reprehenderit hoodie portland irony. Aliqua tofu quinoa +1 commodo eiusmod. High life williamsburg cupidatat twee homo leggings. Four loko vinyl DIY consectetur nisi, marfa retro keffiyeh vegan. Fanny pack viral retro consectetur gentrify fap.</p>
</div>
<div id="fat">
<div class="tab-pane" id="fat">
<p>Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.</p>
</div>
<div id="mdo">
<div class="tab-pane" id="mdo">
<p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions js/bootstrap-alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function( $ ){

"use strict"

/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
* ======================================================= */

Expand Down
18 changes: 15 additions & 3 deletions js/bootstrap-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@
$el.removeClass(d).removeAttr(d)
}

$.fn.button = function(state) {
var d = 'disabled'
function toggle(el) {
$(el).toggleClass('active')
}

$.fn.button = function(options) {
return this.each(function () {
state && setState(this, state)
if (options == 'toggle') {
return toggle(this)
}
options && setState(this, options)
})
}

$.fn.button.defaults = {
loadingText: 'loading...'
}

$(function () {
$('body').delegate('.btn[data-toggle]', 'click', function () {
$(this).button('toggle')
})
})

}( window.jQuery || window.ender );
2 changes: 2 additions & 0 deletions js/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function( $ ){

"use strict"

/* DROPDOWN PLUGIN DEFINITION
* ========================== */

Expand Down
37 changes: 20 additions & 17 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function( $ ){

"use strict"

/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
* ======================================================= */

Expand Down Expand Up @@ -115,17 +117,9 @@
.trigger('hide')
.removeClass('in')

function removeElement () {
that.$element
.hide()
.trigger('hidden')

backdrop.call(that)
}

$.support.transition && this.$element.hasClass('fade') ?
this.$element.one(transitionEnd, removeElement) :
removeElement()
this.$element.one(transitionEnd, $.proxy(hideModal, this)) :
hideModal.call(this)

return this
}
Expand All @@ -136,6 +130,14 @@
/* MODAL PRIVATE METHODS
* ===================== */

function hideModal (that) {
this.$element
.hide()
.trigger('hidden')

backdrop.call(this)
}

function backdrop ( callback ) {
var that = this
, animate = this.$element.hasClass('fade') ? 'fade' : ''
Expand All @@ -162,19 +164,20 @@
} else if ( !this.isShown && this.$backdrop ) {
this.$backdrop.removeClass('in')

function removeElement() {
that.$backdrop.remove()
that.$backdrop = null
}

$.support.transition && this.$element.hasClass('fade')?
this.$backdrop.one(transitionEnd, removeElement) :
removeElement()
this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) :
removeBackdrop.call(this)

} else if ( callback ) {
callback()
}
}

function removeBackdrop() {
this.$backdrop.remove()
this.$backdrop = null
}

function escape() {
var that = this
if ( this.isShown && this.settings.keyboard ) {
Expand Down
2 changes: 2 additions & 0 deletions js/bootstrap-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function( $ ) {

"use strict"

var Popover = function ( element, options ) {
this.$element = $(element)
this.options = options
Expand Down
2 changes: 2 additions & 0 deletions js/bootstrap-scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function ( $ ) {

"use strict"

var $window = $(window)

function ScrollSpy( topbar, selector ) {
Expand Down
3 changes: 3 additions & 0 deletions js/bootstrap-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

!function( $ ){

"use strict"

function activate ( element, container ) {
container
.find('> .active')
Expand All @@ -39,6 +41,7 @@
, $ul = $this.closest('ul:not(.dropdown-menu)')
, href = $this.attr('href')
, previous
, $href

if ( /^#\w+/.test(href) ) {
e.preventDefault()
Expand Down
2 changes: 2 additions & 0 deletions js/bootstrap-twipsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

!function( $ ) {

"use strict"

/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
* ======================================================= */

Expand Down
4 changes: 3 additions & 1 deletion js/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Bootstrap Plugin Test Suite</title>

<!-- jquery -->
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

<!-- qunit -->
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
Expand All @@ -17,6 +17,7 @@
<script src="../../js/bootstrap-tabs.js"></script>
<script src="../../js/bootstrap-twipsy.js"></script>
<script src="../../js/bootstrap-popover.js"></script>
<script src="../../js/bootstrap-buttons.js"></script>

<!-- unit tests -->
<script src="unit/bootstrap-alerts.js"></script>
Expand All @@ -25,6 +26,7 @@
<script src="unit/bootstrap-popover.js"></script>
<script src="unit/bootstrap-tabs.js"></script>
<script src="unit/bootstrap-twipsy.js"></script>
<script src="unit/bootstrap-buttons.js"></script>

<body>
<div>
Expand Down
42 changes: 42 additions & 0 deletions js/tests/unit/bootstrap-buttons.js
Original file line number Diff line number Diff line change
@@ -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 = $('<button class="btn" data-loading-text="fat">mdo</button>')
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 = $('<button class="btn" data-loading-text="fat">mdo</button>')
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 = $('<button class="btn" data-loading-text="fat">mdo</button>')
ok(!btn.hasClass('active'), 'btn does not have active class')
btn.button('toggle')
ok(btn.hasClass('active'), 'btn has class active')
})

})
3 changes: 2 additions & 1 deletion lib/patterns.less
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ea50e8a

Please sign in to comment.