Skip to content

Commit 8bb477b

Browse files
authored
fix(calendar): fix the popup show function getting called twice
This PR fixes an issue where the popup would be called to be shown twice because the two modules are listening to the events to show the popup when only one should be. I've thus removed the calendar's listeners since the popup ones that should be expected. This PR also fixes the end calendars' popup which were also getting called to be shown twice when using the default settings for input calendars. The calendar module was focusing the input which is triggering the focus event that is also listened by the popup module. With this PR, the popup's show method is called only if the listener is not on focus, so that the input can still be focused. This can be a big performance issue on heavy DOM trees as the popup position calculation is very heavy.
1 parent 6ba815e commit 8bb477b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/definitions/modules/calendar.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ $.fn.calendar = function(parameters) {
116116
module.set.maxDate($module.data(metadata.maxDate));
117117
}
118118
module.setting('type', module.get.type());
119+
module.setting('on', settings.on || ($input.length ? 'focus' : 'click'));
119120
},
120121
popup: function () {
121122
if (settings.inline) {
@@ -159,7 +160,7 @@ $.fn.calendar = function(parameters) {
159160
module.set.mode(settings.startMode);
160161
return settings.onShow.apply($container, arguments);
161162
};
162-
var on = settings.on || ($input.length ? 'focus' : 'click');
163+
var on = module.setting('on');
163164
var options = $.extend({}, settings.popupOptions, {
164165
popup: $container,
165166
on: on,
@@ -446,7 +447,6 @@ $.fn.calendar = function(parameters) {
446447
$input.on('input' + eventNamespace, module.event.inputChange);
447448
$input.on('focus' + eventNamespace, module.event.inputFocus);
448449
$input.on('blur' + eventNamespace, module.event.inputBlur);
449-
$input.on('click' + eventNamespace, module.event.inputClick);
450450
$input.on('keydown' + eventNamespace, module.event.keydown);
451451
} else {
452452
$container.on('keydown' + eventNamespace, module.event.keydown);
@@ -575,9 +575,6 @@ $.fn.calendar = function(parameters) {
575575
var text = formatter.datetime(date, settings);
576576
$input.val(text);
577577
}
578-
},
579-
inputClick: function () {
580-
module.popup('show');
581578
}
582579
},
583580

@@ -802,10 +799,12 @@ $.fn.calendar = function(parameters) {
802799
var canceled = module.set.date(date) === false;
803800
if (!canceled && settings.closable) {
804801
module.popup('hide');
805-
//if this is a range calendar, show the end date calendar popup and focus the input
802+
//if this is a range calendar, focus the container or input. This will open the popup from its event listeners.
806803
var endModule = module.get.calendarModule(settings.endCalendar);
807804
if (endModule) {
808-
endModule.popup('show');
805+
if (endModule.setting('on') !== 'focus') {
806+
endModule.popup('show');
807+
}
809808
endModule.focus();
810809
}
811810
}

0 commit comments

Comments
 (0)