diff options
| author | Mark Otto <[email protected]> | 2013-07-18 01:25:28 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2013-07-18 01:25:28 -0700 |
| commit | 6e04925328c74dde8d98676b5148d646ea055e9b (patch) | |
| tree | afe6d9aef724184db7c893b6d324519b729d3fc9 /js | |
| parent | e72b524d416a5b3352274e0d748ffd77ceecf100 (diff) | |
| parent | 6ec8a1e44f6b58ed57d015916a4fe39bfb0e2340 (diff) | |
| download | bootstrap-6e04925328c74dde8d98676b5148d646ea055e9b.tar.xz bootstrap-6e04925328c74dde8d98676b5148d646ea055e9b.zip | |
Merge branch '3.0.0-wip' of github.com:twitter/bootstrap into 3.0.0-wip
Diffstat (limited to 'js')
| -rw-r--r-- | js/button.js | 8 | ||||
| -rw-r--r-- | js/tests/unit/button.js | 33 |
2 files changed, 28 insertions, 13 deletions
diff --git a/js/button.js b/js/button.js index c29647840..b4d66b68b 100644 --- a/js/button.js +++ b/js/button.js @@ -53,10 +53,11 @@ } Button.prototype.toggle = function () { - var $parent = this.$element.closest('[data-toggle="buttons-radio"]') + var $parent = this.$element.closest('[data-toggle="buttons"]') - if ($parent) { - $parent.find('.active').removeClass('active') + if ($parent.length) { + var $input = this.$element.find('input').prop('checked', !this.$element.hasClass('active')) + if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active') } this.$element.toggleClass('active') @@ -100,6 +101,7 @@ var $btn = $(e.target) if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') $btn.button('toggle') + e.preventDefault() }) }(window.jQuery); diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 943d36d1b..0f8988a7d 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -69,7 +69,7 @@ $(function () { }) test("should toggle active when btn children are clicked within btn-group", function () { - var btngroup = $('<div class="btn-group" data-toggle="buttons-checkbox"></div>') + var btngroup = $('<div class="btn-group" data-toggle="buttons"></div>') , btn = $('<button class="btn">fat</button>') , inner = $('<i></i>') btngroup @@ -81,22 +81,35 @@ $(function () { }) test("should check for closest matching toggle", function () { - var group = $("<div data-toggle='buttons-radio'></div>") - , btn1 = $("<button class='btn active'></button>") - , btn2 = $("<button class='btn'></button>") - , wrap = $("<div></div>") + var group = '<div class="btn-group" data-toggle="buttons">' + + '<label class="btn btn-primary active">' + + '<input type="radio" name="options" id="option1" checked="true"> Option 1' + + '</label>' + + '<label class="btn btn-primary">' + + '<input type="radio" name="options" id="option2"> Option 2' + + '</label>' + + '<label class="btn btn-primary">' + + '<input type="radio" name="options" id="option3"> Option 3' + + '</label>' + + '</div>' - wrap.append(btn1, btn2) + group = $(group) - group - .append(wrap) - .appendTo($('#qunit-fixture')) + var btn1 = $(group.children()[0]) + var btn2 = $(group.children()[1]) + var btn3 = $(group.children()[2]) + + group.appendTo($('#qunit-fixture')) ok(btn1.hasClass('active'), 'btn1 has active class') + ok(btn1.find('input').prop('checked'), 'btn1 is checked') ok(!btn2.hasClass('active'), 'btn2 does not have active class') - btn2.click() + ok(!btn2.find('input').prop('checked'), 'btn2 is not checked') + btn2.find('input').click() ok(!btn1.hasClass('active'), 'btn1 does not have active class') + ok(!btn1.find('input').prop('checked'), 'btn1 is checked') ok(btn2.hasClass('active'), 'btn2 has active class') + ok(btn2.find('input').prop('checked'), 'btn2 is checked') }) }) |
