diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-alerts.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-buttons.js | 18 | ||||
| -rw-r--r-- | js/bootstrap-dropdown.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-modal.js | 37 | ||||
| -rw-r--r-- | js/bootstrap-popover.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-scrollspy.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-tabs.js | 3 | ||||
| -rw-r--r-- | js/bootstrap-twipsy.js | 2 | ||||
| -rw-r--r-- | js/tests/index.html | 4 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-buttons.js | 42 |
10 files changed, 93 insertions, 21 deletions
diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index a8d15e24e..1c6f7f346 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 fe6c9c599..1fcc5e505 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 68a3db5f2..789d4a207 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 2cc910989..9c57f6ddf 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 1cf4b8917..a8a1d8e7b 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 5226d9dfe..213de20d1 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 9ccf85436..ef7d4af15 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 97cf47f46..ad2938a1a 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 2ca94102a..355c3f0af 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 000000000..9784f5222 --- /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 |
