Skip to content

Commit e3d1d06

Browse files
committed
Fix for multiple show/hide events firing
1 parent 64427fb commit e3d1d06

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

daterangepicker.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @version: 1.3.7
2+
* @version: 1.3.8
33
* @author: Dan Grossman http://www.dangrossman.info/
4-
* @date: 2014-04-29
4+
* @date: 2014-07-10
55
* @copyright: Copyright (c) 2012-2014 Dan Grossman. All rights reserved.
66
* @license: Licensed under Apache License v2.0. See http://www.apache.org/licenses/LICENSE-2.0
77
* @website: http://www.improvely.com/
@@ -16,6 +16,9 @@
1616
//element that triggered the date range picker
1717
this.element = $(element);
1818

19+
//tracks visible state
20+
this.isShowing = false;
21+
1922
//create the picker HTML object
2023
var DRPTemplate = '<div class="daterangepicker dropdown-menu">' +
2124
'<div class="calendar left"></div>' +
@@ -501,6 +504,8 @@
501504
},
502505

503506
show: function (e) {
507+
if (this.isShowing) return;
508+
504509
this.element.addClass('active');
505510
this.container.show();
506511
this.move();
@@ -515,6 +520,7 @@
515520
// and also close when focus changes to outside the picker (eg. tabbing between controls)
516521
.on('focusin.daterangepicker', this._outsideClickProxy);
517522

523+
this.isShowing = true;
518524
this.element.trigger('show.daterangepicker', this);
519525
},
520526

@@ -531,10 +537,12 @@
531537
},
532538

533539
hide: function (e) {
540+
if (!this.isShowing) return;
541+
534542
$(document)
535-
.off('mousedown.daterangepicker', this._outsideClickProxy)
536-
.off('click.daterangepicker', this._outsideClickProxy)
537-
.off('focusin.daterangepicker', this._outsideClickProxy);
543+
.off('mousedown.daterangepicker')
544+
.off('click.daterangepicker', '[data-toggle=dropdown]')
545+
.off('focusin.daterangepicker');
538546

539547
this.element.removeClass('active');
540548
this.container.hide();
@@ -545,6 +553,7 @@
545553
this.oldStartDate = this.startDate.clone();
546554
this.oldEndDate = this.endDate.clone();
547555

556+
this.isShowing = false;
548557
this.element.trigger('hide.daterangepicker', this);
549558
},
550559

0 commit comments

Comments
 (0)