|
1 | 1 | /*! |
2 | | - * Bootstrap-checkbox v1.2.15 (https://vsn4ik.github.io/bootstrap-checkbox/) |
| 2 | + * Bootstrap-checkbox v1.3.0 (https://vsn4ik.github.io/bootstrap-checkbox/) |
3 | 3 | * Copyright 2013-2016 Vasily A. (https://github.com/vsn4ik) |
4 | 4 | * Licensed under the MIT license |
5 | 5 | */ |
|
27 | 27 | } |
28 | 28 | })(function($) { |
29 | 29 | $.create = function() { |
30 | | - return $($.map(arguments, function(tagName) { |
31 | | - return document.createElement(tagName); |
32 | | - })); |
| 30 | + return $($.map(arguments, $.proxy(document, 'createElement'))); |
33 | 31 | }; |
34 | 32 |
|
35 | 33 | function Checkboxpicker(element, options) { |
36 | 34 | this.element = element; |
37 | 35 | this.$element = $(element); |
38 | 36 |
|
39 | | - this.options = $.extend({}, $.fn.checkboxpicker.defaults, options, this.$element.data()); |
| 37 | + var data = this.$element.data(); |
| 38 | + |
| 39 | + // === '': <... data-reverse> |
| 40 | + if (data.reverse === '') { |
| 41 | + data.reverse = true; |
| 42 | + } |
| 43 | + |
| 44 | + // === '': <... data-switch-always> |
| 45 | + if (data.switchAlways === '') { |
| 46 | + data.switchAlways = true; |
| 47 | + } |
| 48 | + |
| 49 | + this.options = $.extend({}, $.fn.checkboxpicker.defaults, options, data); |
40 | 50 |
|
41 | 51 | if (this.$element.closest('label').length) { |
42 | 52 | console.warn(this.options.warningMessage); |
|
49 | 59 | // .btn-group-justified works with <a> elements as the <button> doesn't pick up the styles |
50 | 60 | this.$buttons = $.create('a', 'a').addClass('btn'); |
51 | 61 |
|
52 | | - // === '': <... data-reverse> |
53 | | - var reverse = this.options.reverse || this.options.reverse === ''; |
54 | | - |
55 | | - this.$off = this.$buttons.eq(reverse ? 1 : 0); |
56 | | - this.$on = this.$buttons.eq(reverse ? 0 : 1); |
| 62 | + this.$off = this.$buttons.eq(this.options.reverse ? 1 : 0); |
| 63 | + this.$on = this.$buttons.eq(this.options.reverse ? 0 : 1); |
57 | 64 |
|
58 | 65 | this.init(); |
59 | 66 | } |
|
123 | 130 | this.$group.on('keydown', $.proxy(this, 'keydown')); |
124 | 131 |
|
125 | 132 | // Don't trigger if <a> element has .disabled class, fine! |
126 | | - this.$group.on('click', 'a:not(.active)', $.proxy(this, 'click')); |
| 133 | + this.$buttons.on('click', $.proxy(this, 'click')); |
127 | 134 |
|
128 | 135 | this.$element.on('change', $.proxy(this, 'toggleChecked')); |
129 | 136 | $(this.element.labels).on('click', $.proxy(this, 'focus')); |
|
172 | 179 | // Original behavior |
173 | 180 | this.$group.trigger('focus'); |
174 | 181 | }, |
175 | | - click: function() { |
176 | | - this.change(!this.element.checked); |
| 182 | + click: function(event) { |
| 183 | + var $button = $(event.target); |
| 184 | + |
| 185 | + if (!$button.hasClass('active') || this.options.switchAlways) { |
| 186 | + this.change(!this.element.checked); |
| 187 | + } |
177 | 188 | }, |
178 | 189 | change: function(value) { |
179 | 190 | // Fix #12 |
|
0 commit comments