PHRAS-965 - fix issues in tooltip positionning

This commit is contained in:
Florian BLOUET
2016-02-23 14:39:56 +01:00
parent c9b9f41f04
commit 8fea3c77a9
2 changed files with 75 additions and 41 deletions

View File

@@ -237,15 +237,16 @@
function positioning(event) { function positioning(event) {
helper.body.html(title); helper.body.html(title);
helper.body.show(); helper.body.show();
$this = $.tooltip.current; var $this = $.tooltip.current;
var tooltipSettings = settings($this) ? settings($this) : {};
var fixedPosition = tooltipSettings.fixable ? tooltipSettings.fixable : false;
// fix PNG background for IE // fix PNG background for IE
if (settings($this).fixPNG) if (tooltipSettings.fixPNG)
helper.parent.fixPNG(); helper.parent.fixPNG();
if (settings($this).outside) { if (tooltipSettings.outside) {
var width = 'auto'; var width = 'auto';
var height = 'auto'; var height = 'auto';
var tooltipId = settings($.tooltip.current).id; var tooltipId = tooltipSettings.id;
var $defaultTips = $('#' + tooltipId); var $defaultTips = $('#' + tooltipId);
var $audioTips = $('#' + tooltipId + ' .audioTips'); var $audioTips = $('#' + tooltipId + ' .audioTips');
var $imgTips = $('#' + tooltipId + ' .imgTips'); var $imgTips = $('#' + tooltipId + ' .imgTips');
@@ -254,7 +255,7 @@
var shouldResize = $('#' + tooltipId + ' .noToolTipResize').length === 0 ? true : false; var shouldResize = $('#' + tooltipId + ' .noToolTipResize').length === 0 ? true : false;
// get image or video original dimensions // get image or video original dimensions
var recordWidth = 240; var recordWidth = 260;
var recordHeight = 0; var recordHeight = 0;
var tooltipVerticalOffset = 75; var tooltipVerticalOffset = 75;
var tooltipHorizontalOffset = 35; var tooltipHorizontalOffset = 35;
@@ -278,6 +279,7 @@
recordWidth = parseInt($imgTips[0].style.width); recordWidth = parseInt($imgTips[0].style.width);
recordHeight = parseInt($imgTips[0].style.height); recordHeight = parseInt($imgTips[0].style.height);
$imgTips.css({display: 'block', margin: '0 auto'}); $imgTips.css({display: 'block', margin: '0 auto'});
$selector = $imgTips;
} }
else if ($documentTips[0] && shouldResize) { else if ($documentTips[0] && shouldResize) {
@@ -359,6 +361,8 @@
var $origEventTarget = $(event.target); var $origEventTarget = $(event.target);
// previewTips
// since event target can have different positionning, try to get common closest parent: // since event target can have different positionning, try to get common closest parent:
var $eventTarget = $origEventTarget.closest('.diapo'); var $eventTarget = $origEventTarget.closest('.diapo');
@@ -379,6 +383,7 @@
// fallback on original target if nothing found: // fallback on original target if nothing found:
$eventTarget = $origEventTarget; $eventTarget = $origEventTarget;
} }
var recordPosition = $eventTarget.offset(); var recordPosition = $eventTarget.offset();
var totalViewportWidth = viewportDimensions.x; var totalViewportWidth = viewportDimensions.x;
@@ -394,6 +399,7 @@
var tooltipSize = {width: tooltipWidth, height: tooltipHeight}; var tooltipSize = {width: tooltipWidth, height: tooltipHeight};
var position = 'top'; var position = 'top';
if (topAvailableSpace > bottomAvailableSpace) { if (topAvailableSpace > bottomAvailableSpace) {
shouldBeOnTop = true; shouldBeOnTop = true;
availableHeight = topAvailableSpace; availableHeight = topAvailableSpace;
@@ -413,6 +419,12 @@
position = 'top'; position = 'top';
} }
if (fixedPosition === true) {
leftAvailableSpace = totalViewportWidth;
topAvailableSpace = totalViewportHeight;
position = 'top';
}
switch (position) { switch (position) {
case 'top': case 'top':
tooltipSize = rescale(totalViewportWidth, topAvailableSpace, tooltipWidth, tooltipHeight, maxWidthAllowed, maxHeightAllowed); tooltipSize = rescale(totalViewportWidth, topAvailableSpace, tooltipWidth, tooltipHeight, maxWidthAllowed, maxHeightAllowed);
@@ -444,6 +456,14 @@
} }
// tooltipHeight = tooltipHeight + 18;
// tooltipWidth = tooltipWidth + 28;
if (fixedPosition === true) {
left = totalViewportWidth / 2 - (tooltipWidth / 2);
top = totalViewportHeight / 2 - (tooltipHeight / 2);
} else {
// try to vertical center, relative to source: // try to vertical center, relative to source:
if (position === 'left' || position === 'right') { if (position === 'left' || position === 'right') {
var verticalSpace = topAvailableSpace + (recordHeightOffset / 2) + (tooltipHeight / 2) var verticalSpace = topAvailableSpace + (recordHeightOffset / 2) + (tooltipHeight / 2)
@@ -460,8 +480,8 @@
if (position === 'top' || position === 'bottom') { if (position === 'top' || position === 'bottom') {
// push to left // push to left
// push to right // push to right
var takeLeftSpace = (tooltipSize.width / 2) + leftAvailableSpace; var takeLeftSpace = (tooltipWidth / 2) + leftAvailableSpace;
var takeRightSpace = (tooltipSize.width / 2) + rightAvailableSpace; var takeRightSpace = (tooltipWidth / 2) + rightAvailableSpace;
// if centering on top or bottom and tooltip is offcanvas // if centering on top or bottom and tooltip is offcanvas
if (takeLeftSpace > totalViewportWidth || takeRightSpace > totalViewportWidth) { if (takeLeftSpace > totalViewportWidth || takeRightSpace > totalViewportWidth) {
@@ -470,24 +490,38 @@
left = 0; left = 0;
} else { } else {
// push at right // push at right
left = totalViewportWidth - tooltipSize.width; left = totalViewportWidth - tooltipWidth;
} }
} else { } else {
// center // center
left = leftAvailableSpace - (tooltipSize.width / 2) + (recordWidthOffset / 2); left = leftAvailableSpace - (tooltipWidth / 2) + (recordWidthOffset / 2);
}
} }
} }
if (shouldResize) {
rescale(tooltipWidth - tooltipHorizontalOffset, tooltipHeight - tooltipVerticalOffset, recordWidth, recordHeight, maxWidthAllowed, maxHeightAllowed, $selector);
}
helper.parent.css({ var resizeProperties = {
width: shouldResize ? Math.round(tooltipWidth) : 'auto',
height: shouldResize ? Math.round(tooltipHeight) : 'auto',
left: left, left: left,
top: top top: top
}); };
if (shouldResize) {
// rescale $selector css:
rescale(tooltipWidth - tooltipHorizontalOffset, tooltipHeight - tooltipVerticalOffset, recordWidth, recordHeight, maxWidthAllowed, maxHeightAllowed, $selector);
// reset non used css properties:
resizeProperties['max-width'] = '';
resizeProperties['min-width'] = '';
} else {
// ensure tooltip width match with left position
resizeProperties['max-width'] = Math.round(tooltipWidth);
resizeProperties['min-width'] = Math.round(tooltipWidth);
}
resizeProperties['width'] = shouldResize ? Math.round(tooltipWidth) : 'auto';
resizeProperties['height'] = shouldResize ? Math.round(tooltipHeight) : 'auto';
helper.parent.css(resizeProperties);
} }
} }
handle.apply($this, arguments); handle.apply($this, arguments);

View File

@@ -93,7 +93,7 @@ $answersInfoLabelColor: #949494 !default;
left: 10px; left: 10px;
height: 60px; height: 60px;
width: 400px; width: 400px;
z-index: 1000; z-index: 100;
table{ table{
width: 100%; width: 100%;
tr{ tr{