Skip to content

Commit 360eebe

Browse files
committed
Merge pull request #164 from frahugo/gh-pages
New option: showWidgetOnAddonClick
2 parents e2e17b8 + cb7234d commit 360eebe

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

js/bootstrap-timepicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
this.showSeconds = options.showSeconds;
2828
this.template = options.template;
2929
this.appendWidgetTo = options.appendWidgetTo;
30+
this.showWidgetOnAddonClick = options.showWidgetOnAddonClick;
3031

3132
this._init();
3233
};
@@ -37,7 +38,7 @@
3738
_init: function() {
3839
var self = this;
3940

40-
if (this.$element.parent().hasClass('input-append') || this.$element.parent().hasClass('input-prepend')) {
41+
if (this.showWidgetOnAddonClick && (this.$element.parent().hasClass('input-append') || this.$element.parent().hasClass('input-prepend'))) {
4142
this.$element.parent('.input-append, .input-prepend').find('.add-on').on({
4243
'click.timepicker': $.proxy(this.showWidget, this)
4344
});
@@ -1021,7 +1022,8 @@
10211022
showInputs: true,
10221023
showMeridian: true,
10231024
template: 'dropdown',
1024-
appendWidgetTo: '.bootstrap-timepicker'
1025+
appendWidgetTo: '.bootstrap-timepicker',
1026+
showWidgetOnAddonClick: true
10251027
};
10261028

10271029
$.fn.timepicker.Constructor = Timepicker;

js/bootstrap-timepicker.min.js

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

spec/js/MouseEventsSpec.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ describe('Mouse events feature', function() {
55
$input2,
66
$input3,
77
$input4,
8+
$input5,
89
$timepicker1,
910
$timepicker2,
1011
$timepicker3,
1112
$timepicker4,
13+
$timepicker5,
1214
tp1,
1315
tp2,
1416
tp3,
15-
tp4;
17+
tp4,
18+
tp5;
1619

1720
beforeEach(function () {
1821
loadFixtures('timepicker.html');
@@ -21,6 +24,10 @@ describe('Mouse events feature', function() {
2124
$timepicker1 = $input1.timepicker();
2225
tp1 = $timepicker1.data('timepicker');
2326

27+
$input5 = $('#timepicker5');
28+
$timepicker5 = $input1.timepicker({showWidgetOnAddonClick: false});
29+
tp5 = $timepicker5.data('timepicker');
30+
2431
$input2 = $('#timepicker2');
2532
$timepicker2 = $input2.timepicker({
2633
template: 'modal',
@@ -98,7 +105,13 @@ describe('Mouse events feature', function() {
98105

99106
});
100107

101-
it('should increment hour on button click and fire 1 changeTime event', function() {
108+
it('should not show widget when clicking add-on icon if showWidgetOnAddonClick is false', function() {
109+
expect(tp5.isOpen).toBe(false);
110+
$input5.parents('div').find('.add-on').trigger('click');
111+
expect(tp5.isOpen).toBe(false);
112+
});
113+
114+
it('should increment hour on button click', function() {
102115
tp1.setTime('11:30 AM');
103116
tp1.update();
104117

spec/js/TimepickerSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('Timepicker feature', function() {
7272
expect(tp1.modalBackdrop).toBe(false);
7373
expect(tp1.modalBackdrop).toBe(false);
7474
expect(tp1.isOpen).toBe(false);
75+
expect(tp1.showWidgetOnAddonClick).toBe(true);
7576
});
7677

7778
it('should allow user to configure defaults', function() {

0 commit comments

Comments
 (0)