Skip to content

Commit d596626

Browse files
committed
Add style option.
1 parent acccef0 commit d596626

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 vsn4ik
3+
Copyright (c) 2013-2014 vsn4ik
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ For some working examples of bootstrap-checkbox, visit our [examples page](http:
2727
+ <https://github.com/vsn4ik>
2828

2929
## License
30-
Copyright 2014 vsn4ik.
30+
Copyright 2013-2014 vsn4ik.
3131

3232
Licensed under [the MIT License](LICENSE).

dist/bootstrap-checkbox.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Bootstrap-checkbox
33
* http://vsn4ik.github.io/bootstrap-checkbox
44
*
5-
* Copyright (c) 2014 vsn4ik
5+
* Copyright 2013-2014 vsn4ik
66
* Licensed under the MIT License
77
*/
88

@@ -17,38 +17,42 @@ if (typeof jQuery === 'undefined') {
1717
this.element = element;
1818
this.options = $.extend({}, $.fn.checkboxpicker.defaults, options, $(element).data());
1919

20-
this.$buttons = $('<button><button>')
21-
.addClass('btn')
22-
.attr({ type: 'button', tabindex: -1 })
23-
.prop('disabled', element.disabled)
24-
.click(this.clicked.bind(this));
20+
// .btn-group-justified only works with <a> elements as the <button> doesn't pick up the styles
21+
this.$buttons = $('<a><a>').addClass('btn').click(this.clicked.bind(this));
2522

26-
this.$on = this.$buttons.eq(0).html(this.options.onLabel);
27-
this.$off = this.$buttons.eq(1).html(this.options.offLabel);
23+
this.$off = this.$buttons.eq(0).html(this.options.offLabel);
24+
this.$on = this.$buttons.eq(1).html(this.options.onLabel);
2825

2926
this.init();
3027

3128
$(element).hide().change(this.render.bind(this));
3229

3330
this.$group = $('<div class="btn-group">')
3431
.append(this.$buttons)
35-
.insertAfter(element)
36-
.keydown(this.keydown.bind(this));
32+
.keydown(this.keydown.bind(this))
33+
.insertAfter(element);
34+
35+
if (this.options.style) {
36+
this.$group.addClass(this.options.style);
37+
}
3738

3839
if (element.title) {
3940
this.$group.attr('title', element.title);
4041
}
4142
else {
42-
if (this.options.onTitle) {
43-
this.$on.attr('title', this.options.onTitle);
44-
}
45-
4643
if (this.options.offTitle) {
4744
this.$off.attr('title', this.options.offTitle);
4845
}
46+
47+
if (this.options.onTitle) {
48+
this.$on.attr('title', this.options.onTitle);
49+
}
4950
}
5051

51-
if (!element.disabled) {
52+
if (element.disabled) {
53+
this.$buttons.addClass('disabled');
54+
}
55+
else {
5256
this.$group.attr('tabindex', 0);
5357
}
5458
};
@@ -67,8 +71,8 @@ if (typeof jQuery === 'undefined') {
6771
render: function() {
6872
this.$group.not(':focus').focus();
6973
this.$buttons.toggleClass('active ' + this.options.defaultClass);
70-
this.$on.toggleClass(this.options.onClass);
7174
this.$off.toggleClass(this.options.offClass);
75+
this.$on.toggleClass(this.options.onClass);
7276
},
7377
change: function() {
7478
$(this.element).prop('checked', !this.element.checked).change();
@@ -98,12 +102,13 @@ if (typeof jQuery === 'undefined') {
98102
// HTML5 data-*.
99103
// <input data-on-label="43"> --> $('input').data('onLabel') == '43'.
100104
$.fn.checkboxpicker.defaults = {
105+
style: false,
101106
defaultClass: 'btn-default',
102-
onClass: 'btn-success',
103107
offClass: 'btn-danger',
104-
onLabel: 'Yes',
108+
onClass: 'btn-success',
105109
offLabel: 'No',
106-
onTitle: false,
107-
offTitle: false
110+
onLabel: 'Yes',
111+
offTitle: false,
112+
onTitle: false
108113
};
109114
})(jQuery);

dist/bootstrap-checkbox.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)