Skip to content

Commit

Permalink
feat(calendar): avoid unnecessary redraw
Browse files Browse the repository at this point in the history
Whenever a calendar popup is shown the calendar gets redrawn several times even if nothing was changed!
  • Loading branch information
lubber-de authored Jun 30, 2020
1 parent 580d79b commit 339e7fe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/definitions/modules/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ $.fn.calendar = function(parameters) {
var onShow = function () {
//reset the focus date onShow
module.set.focusDate(module.get.date());
module.set.mode(settings.startMode);
module.set.mode(module.get.validatedMode(settings.startMode));
return settings.onShow.apply($container, arguments);
};
var on = module.setting('on');
Expand Down Expand Up @@ -197,6 +197,7 @@ $.fn.calendar = function(parameters) {
date = parser.date($input.val(), settings);
}
module.set.date(date, settings.formatInput, false);
module.set.mode(module.get.mode(), false);
}
},

Expand Down Expand Up @@ -622,6 +623,9 @@ $.fn.calendar = function(parameters) {
mode: function () {
//only returns valid modes for the current settings
var mode = $module.data(metadata.mode) || settings.startMode;
return module.get.validatedMode(mode);
},
validatedMode: function(mode){
var validModes = module.get.validModes();
if ($.inArray(mode, validModes) >= 0) {
return mode;
Expand Down Expand Up @@ -739,7 +743,7 @@ $.fn.calendar = function(parameters) {
module.set.monthOffset(monthOffset, false);
}
}
var changed = module.set.dataKeyValue(metadata.focusDate, date, refreshCalendar);
var changed = module.set.dataKeyValue(metadata.focusDate, date, !!date && refreshCalendar);
updateFocus = (updateFocus !== false && changed && refreshCalendar === false) || focusDateUsedForRange != updateRange;
focusDateUsedForRange = updateRange;
if (updateFocus) {
Expand Down

0 comments on commit 339e7fe

Please sign in to comment.