diff --git a/bootstrap.css b/bootstrap.css index d849cfb6058dd48aac1df17caff5a4e867b66613..2f4924eb03fab9cd3fa2cf4295f590665c8bd823 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 02c0f6a004161e80f12eae836ad4ceda31d6d78f..47edf2b75156c00fd2453d17cb9dfaaec0dd05fe 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -314,7 +314,7 @@ $('#my-modal').bind('hidden', function () { </div> </section> - <!-- Tabs + <!-- Buttons ================================================== --> <section id="buttons"> @@ -329,10 +329,11 @@ $('#my-modal').bind('hidden', function () { <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"><button class="btn" data-toggle="toggle" >...</button></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"><button class="btn" data-toggle="toggle" >...</button></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> @@ -346,7 +347,8 @@ $('#my-modal').bind('hidden', function () { $('.btn').button('complete') </scrip></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 () { @@ -442,22 +444,22 @@ $('#.tabs').bind('change', function (e) { </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> diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index a8d15e24e0cb9c9b1151f96c837abde62e7e9d02..1c6f7f346ba3abeab3b640a16884338fa1c337ed 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index fe6c9c599946c90b4ad0173b1e86251248255196..1fcc5e5058e306452f3246ddcca929e6c4c9d582 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -36,10 +36,16 @@ $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) }) } @@ -47,4 +53,10 @@ loadingText: 'loading...' } + $(function () { + $('body').delegate('.btn[data-toggle]', 'click', function () { + $(this).button('toggle') + }) + }) + }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index 68a3db5f2052f2e43dde4e9aaced432eb9212c80..789d4a20710e3c5f10e8c56fad1273c21631c952 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* DROPDOWN PLUGIN DEFINITION * ========================== */ diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 2cc910989fbebff205a777146dc868d174f9fc1a..9c57f6ddf356c376acebbde0004f78225c61d5af 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ @@ -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 } @@ -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' : '' @@ -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 ) { diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 1cf4b8917ad35c1256ef9676ff1f372e80b2264e..a8a1d8e7bbcbe8d4844f4d43fc793e2d68757e75 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -20,6 +20,8 @@ !function( $ ) { + "use strict" + var Popover = function ( element, options ) { this.$element = $(element) this.options = options diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 5226d9dfe43479f6a3b33a9128b57b55e7cbe0ea..213de20d176d64d67bed9c9e117997d0eefd0031 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -20,6 +20,8 @@ !function ( $ ) { + "use strict" + var $window = $(window) function ScrollSpy( topbar, selector ) { diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index 9ccf8543658cbe3625ac935a89887a0f5f2b3daa..ef7d4af15b3d5fb71b7c6dde4577caabb526ec81 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + function activate ( element, container ) { container .find('> .active') @@ -39,6 +41,7 @@ , $ul = $this.closest('ul:not(.dropdown-menu)') , href = $this.attr('href') , previous + , $href if ( /^#\w+/.test(href) ) { e.preventDefault() diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 97cf47f46b89d22b3c8fd7ce911bd15f8fd25bfd..ad2938a1a8e8bd4b1a1a2cd1f8207ac73de6dc9b 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -21,6 +21,8 @@ !function( $ ) { + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ diff --git a/js/tests/index.html b/js/tests/index.html index 2ca94102ad32752ec1d4cb1809725454f9daeaf0..355c3f0af3a59ede09b65a30a6fc6f6e0665a7ef 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -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" /> @@ -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> @@ -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> diff --git a/js/tests/unit/bootstrap-buttons.js b/js/tests/unit/bootstrap-buttons.js new file mode 100644 index 0000000000000000000000000000000000000000..9784f52224006c62b6c23e21fde06ff39fd77033 --- /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 = $('<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') + }) + +}) \ No newline at end of file diff --git a/lib/patterns.less b/lib/patterns.less index 5f4192d893a5e884eec551614fe66d048ee611b6..307bfe4e66c79a931b0200b9d0e5357ab4a14c2a 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); }