From 37e899d76630d29565c0c6ff67885eee01777e1a Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 18 Jul 2013 00:59:31 -0700 Subject: get button js working with actual form elements p cooll --- js/button.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'js/button.js') diff --git a/js/button.js b/js/button.js index c29647840..c0127cc5f 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') @@ -98,6 +99,7 @@ $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) { var $btn = $(e.target) + if ($btn.has('input').length) return // throw away double event for inputs if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') $btn.button('toggle') }) -- cgit v1.2.3 From 4b40ee692dc066f2ad3c4dd96af67a83475f5cbe Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 18 Jul 2013 01:07:11 -0700 Subject: cleaner way of preventing double click events + clean up tests for jshint --- js/button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/button.js') diff --git a/js/button.js b/js/button.js index c0127cc5f..b4d66b68b 100644 --- a/js/button.js +++ b/js/button.js @@ -99,9 +99,9 @@ $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) { var $btn = $(e.target) - if ($btn.has('input').length) return // throw away double event for inputs if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') $btn.button('toggle') + e.preventDefault() }) }(window.jQuery); -- cgit v1.2.3