Skip to content

Commit ae0b664

Browse files
authored
fix(calendar): adjust tooltip positions according to popup position
The default tooltip position of cell tooltips is left center. This leads into situations where the tooltip is cut to the left. On first instantiation of a calendar popup the position of tooltips is not correctly fetched because the popup module hasn't adjusted its pointer position classes yet. Because of this ,the direction of possible cell tooltips is wrongly calculated. If the same calendar is opened a second time, this does not occur anymore, because the popup module has now adjusted its position. This PR now adjusts any existing cell tooltip positions inside the calendar whenever the popup get's shown (the popup module always (re-)calculates its position then). So this not only fixes it on first instantiation but also in case the calendar position changes while scrolling , so the popup will possibly to displayed in another direction. As this is not a module setting but a decision of the module itself, this is a backward compatible change which just fixes the behavior. Btw. it wasn't happening before, because the calendar popup was called twice (thus correcting it's position), but that was now fixed by #1439
1 parent 5bf395a commit ae0b664

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/definitions/modules/calendar.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ $.fn.calendar = function(parameters) {
141141
$container = $('<div/>').addClass(className.popup)[domPositionFunction]($activatorParent);
142142
}
143143
$container.addClass(className.calendar);
144-
var onVisible = settings.onVisible;
144+
var onVisible = function () {
145+
module.refreshTooltips();
146+
return settings.onVisible.apply($container, arguments);
147+
};
145148
var onHidden = settings.onHidden;
146149
if (!$input.length) {
147150
//no input, $container has to handle focus/blur
148151
$container.attr('tabindex', '0');
149152
onVisible = function () {
153+
module.refreshTooltips();
150154
module.focus();
151155
return settings.onVisible.apply($container, arguments);
152156
};
@@ -178,6 +182,7 @@ $.fn.calendar = function(parameters) {
178182
if ($activator.length && !settings.inline) {
179183
return;
180184
}
185+
settings.inline = true;
181186
$container = $('<div/>').addClass(className.calendar).appendTo($module);
182187
if (!$input.length) {
183188
$container.attr('tabindex', '0');
@@ -397,6 +402,10 @@ $.fn.calendar = function(parameters) {
397402
}
398403

399404
module.update.focus(false, table);
405+
406+
if(settings.inline){
407+
module.refreshTooltips();
408+
}
400409
}
401410
}
402411
},
@@ -438,6 +447,20 @@ $.fn.calendar = function(parameters) {
438447
module.create.calendar();
439448
},
440449

450+
refreshTooltips: function() {
451+
var winWidth = $(window).width();
452+
$container.find('td[data-position]').each(function () {
453+
var cell = $(this);
454+
var tooltipWidth = window.getComputedStyle(cell[0], ':after').width.replace(/[^0-9\.]/g,'');
455+
var tooltipPosition = cell.attr('data-position');
456+
// use a fallback width of 250 (calendar width) for IE/Edge (which return "auto")
457+
var calcPosition = (winWidth - cell.width() - (parseInt(tooltipWidth,10) || 250)) > cell.offset().left ? 'right' : 'left';
458+
if(tooltipPosition.indexOf(calcPosition) === -1) {
459+
cell.attr('data-position',tooltipPosition.replace(/(left|right)/,calcPosition));
460+
}
461+
});
462+
},
463+
441464
bind: {
442465
events: function () {
443466
module.debug('Binding events');

0 commit comments

Comments
 (0)