Skip to content

Commit ea50e8a

Browse files
committed
add active class to css for buttons, write new spec for button, "use strict"
1 parent e8b66a9 commit ea50e8a

13 files changed

+109
-34
lines changed

bootstrap.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ footer {
19171917
border-color: #0064cd #0064cd #003f81;
19181918
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
19191919
}
1920-
.btn:active {
1920+
.btn:active, .btn.active {
19211921
-webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05);
19221922
-moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05);
19231923
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05);

docs/javascript.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ <h3>Demo</h3>
314314
</div>
315315
</section>
316316

317-
<!-- Tabs
317+
<!-- Buttons
318318
================================================== -->
319319

320320
<section id="buttons">
@@ -329,10 +329,11 @@ <h1>Buttons <small>bootstrap-buttons.js</small></h1>
329329
<div class="span12 columns">
330330
<h3>Using bootstrap-buttons.js</h3>
331331
<pre class="prettyprint linenums">$('.tabs').button()</pre>
332-
<h3>Markup</h3>
333-
<p>You can leverage bootstraps button toggle helper without writing any javascript by using the <code>data-toggle</code> attribute.</p>
334-
<pre class="prettyprint linenums">&lt;button class="btn" data-toggle="toggle" &gt;...&lt;/button&gt;</pre>
335332
<h3>Methods</h3>
333+
<h4>$().button('toggle')</h4>
334+
<p>Toggles push state. Gives btn the look that it's been activated.</p>
335+
<p><span class="label notice">Notice</span> You can enable auto toggling of a button by using the <code>data-toggle</code> attribute.</p>
336+
<pre class="prettyprint linenums">&lt;button class="btn" data-toggle="toggle" &gt;...&lt;/button&gt;</pre>
336337
<h4>$().button('loading')</h4>
337338
<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>.
338339
</p>
@@ -346,7 +347,8 @@ <h4>$().button(string)</h4>
346347
$('.btn').button('complete')
347348
&lt;/scrip&gt;</pre>
348349
<h3>Demo</h3>
349-
<button id="fat-btn" class="btn danger">Click me</button>
350+
<button id="fat-btn" data-loading-text="foo" class="btn danger">Loading Demo</button>
351+
<button class="btn" data-toggle="toggle">Toggle Demo</button>
350352
<script>
351353
$(function() {
352354
var btn = $('#fat-btn').click(function () {
@@ -442,22 +444,22 @@ <h3>Demo</h3>
442444
</li>
443445
</ul>
444446
<div id="my-tab-content" class="tab-content">
445-
<div class="active" id="home">
447+
<div class="active tab-pane" id="home">
446448
<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>
447449
</div>
448-
<div id="profile">
450+
<div class="tab-pane" id="profile">
449451
<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>
450452
</div>
451-
<div id="messages">
453+
<div class="tab-pane" id="messages">
452454
<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>
453455
</div>
454-
<div id="settings">
456+
<div class="tab-pane" id="settings">
455457
<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>
456458
</div>
457-
<div id="fat">
459+
<div class="tab-pane" id="fat">
458460
<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>
459461
</div>
460-
<div id="mdo">
462+
<div class="tab-pane" id="mdo">
461463
<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>
462464
</div>
463465
</div>

js/bootstrap-alerts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function( $ ){
2222

23+
"use strict"
24+
2325
/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
2426
* ======================================================= */
2527

js/bootstrap-buttons.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,27 @@
3636
$el.removeClass(d).removeAttr(d)
3737
}
3838

39-
$.fn.button = function(state) {
40-
var d = 'disabled'
39+
function toggle(el) {
40+
$(el).toggleClass('active')
41+
}
42+
43+
$.fn.button = function(options) {
4144
return this.each(function () {
42-
state && setState(this, state)
45+
if (options == 'toggle') {
46+
return toggle(this)
47+
}
48+
options && setState(this, options)
4349
})
4450
}
4551

4652
$.fn.button.defaults = {
4753
loadingText: 'loading...'
4854
}
4955

56+
$(function () {
57+
$('body').delegate('.btn[data-toggle]', 'click', function () {
58+
$(this).button('toggle')
59+
})
60+
})
61+
5062
}( window.jQuery || window.ender );

js/bootstrap-dropdown.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function( $ ){
2222

23+
"use strict"
24+
2325
/* DROPDOWN PLUGIN DEFINITION
2426
* ========================== */
2527

js/bootstrap-modal.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function( $ ){
2222

23+
"use strict"
24+
2325
/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
2426
* ======================================================= */
2527

@@ -115,17 +117,9 @@
115117
.trigger('hide')
116118
.removeClass('in')
117119

118-
function removeElement () {
119-
that.$element
120-
.hide()
121-
.trigger('hidden')
122-
123-
backdrop.call(that)
124-
}
125-
126120
$.support.transition && this.$element.hasClass('fade') ?
127-
this.$element.one(transitionEnd, removeElement) :
128-
removeElement()
121+
this.$element.one(transitionEnd, $.proxy(hideModal, this)) :
122+
hideModal.call(this)
129123

130124
return this
131125
}
@@ -136,6 +130,14 @@
136130
/* MODAL PRIVATE METHODS
137131
* ===================== */
138132

133+
function hideModal (that) {
134+
this.$element
135+
.hide()
136+
.trigger('hidden')
137+
138+
backdrop.call(this)
139+
}
140+
139141
function backdrop ( callback ) {
140142
var that = this
141143
, animate = this.$element.hasClass('fade') ? 'fade' : ''
@@ -162,19 +164,20 @@
162164
} else if ( !this.isShown && this.$backdrop ) {
163165
this.$backdrop.removeClass('in')
164166

165-
function removeElement() {
166-
that.$backdrop.remove()
167-
that.$backdrop = null
168-
}
169-
170167
$.support.transition && this.$element.hasClass('fade')?
171-
this.$backdrop.one(transitionEnd, removeElement) :
172-
removeElement()
168+
this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) :
169+
removeBackdrop.call(this)
170+
173171
} else if ( callback ) {
174172
callback()
175173
}
176174
}
177175

176+
function removeBackdrop() {
177+
this.$backdrop.remove()
178+
this.$backdrop = null
179+
}
180+
178181
function escape() {
179182
var that = this
180183
if ( this.isShown && this.settings.keyboard ) {

js/bootstrap-popover.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function( $ ) {
2222

23+
"use strict"
24+
2325
var Popover = function ( element, options ) {
2426
this.$element = $(element)
2527
this.options = options

js/bootstrap-scrollspy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function ( $ ) {
2222

23+
"use strict"
24+
2325
var $window = $(window)
2426

2527
function ScrollSpy( topbar, selector ) {

js/bootstrap-tabs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
!function( $ ){
2222

23+
"use strict"
24+
2325
function activate ( element, container ) {
2426
container
2527
.find('> .active')
@@ -39,6 +41,7 @@
3941
, $ul = $this.closest('ul:not(.dropdown-menu)')
4042
, href = $this.attr('href')
4143
, previous
44+
, $href
4245

4346
if ( /^#\w+/.test(href) ) {
4447
e.preventDefault()

js/bootstrap-twipsy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
!function( $ ) {
2323

24+
"use strict"
25+
2426
/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
2527
* ======================================================= */
2628

js/tests/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Bootstrap Plugin Test Suite</title>
55

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

99
<!-- qunit -->
1010
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
@@ -17,6 +17,7 @@
1717
<script src="../../js/bootstrap-tabs.js"></script>
1818
<script src="../../js/bootstrap-twipsy.js"></script>
1919
<script src="../../js/bootstrap-popover.js"></script>
20+
<script src="../../js/bootstrap-buttons.js"></script>
2021

2122
<!-- unit tests -->
2223
<script src="unit/bootstrap-alerts.js"></script>
@@ -25,6 +26,7 @@
2526
<script src="unit/bootstrap-popover.js"></script>
2627
<script src="unit/bootstrap-tabs.js"></script>
2728
<script src="unit/bootstrap-twipsy.js"></script>
29+
<script src="unit/bootstrap-buttons.js"></script>
2830

2931
<body>
3032
<div>

js/tests/unit/bootstrap-buttons.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$(function () {
2+
3+
module("bootstrap-buttons")
4+
5+
test("should be defined on jquery object", function () {
6+
ok($(document.body).button, 'tabs method is defined')
7+
})
8+
9+
test("should return element", function () {
10+
ok($(document.body).button()[0] == document.body, 'document.body returned')
11+
})
12+
13+
test("should return set state to loading", function () {
14+
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
15+
equals(btn.html(), 'mdo', 'btn text equals mdo')
16+
btn.button('loading')
17+
equals(btn.html(), 'fat', 'btn text equals fat')
18+
ok(btn.attr('disabled'), 'btn is disabled')
19+
ok(btn.hasClass('disabled'), 'btn has disabled class')
20+
})
21+
22+
test("should return reset state", function () {
23+
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
24+
equals(btn.html(), 'mdo', 'btn text equals mdo')
25+
btn.button('loading')
26+
equals(btn.html(), 'fat', 'btn text equals fat')
27+
ok(btn.attr('disabled'), 'btn is disabled')
28+
ok(btn.hasClass('disabled'), 'btn is disabled')
29+
btn.button('reset')
30+
equals(btn.html(), 'mdo', 'btn text equals mdo')
31+
ok(!btn.attr('disabled'), 'btn is not disabled')
32+
ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
33+
})
34+
35+
test("should toggle active", function () {
36+
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
37+
ok(!btn.hasClass('active'), 'btn does not have active class')
38+
btn.button('toggle')
39+
ok(btn.hasClass('active'), 'btn has class active')
40+
})
41+
42+
})

lib/patterns.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ footer {
573573
.transition(.1s linear all);
574574

575575
// Active and Disabled states
576-
&:active {
576+
&.active,
577+
:active {
577578
@shadow: inset 0 2px 4px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.05);
578579
.box-shadow(@shadow);
579580
}

0 commit comments

Comments
 (0)