@@ -402,63 +402,77 @@ $(function () {
402
402
// -------------
403
403
// Tooltip generation and handling
404
404
// -------------
405
- const toolTipArrowSize = 10 ;
405
+ /* _variables.scss & _navigation.scss - .tooltip:before */
406
+ const toolTipArrowHalfSize = 10 ; /* $tooltip-arrow-half-size */
406
407
var tooltip = null ;
407
408
var tooltipTarget = null ;
408
409
var elementUnderCursor = null ;
409
410
var shouldShowTooltip = false ;
410
411
var showTimeoutFuncID ;
411
412
var hideTimeoutFuncID ;
412
413
413
- function getTooltipPos ( event , tooltipTarget ) {
414
+ function setTooltipPos ( event , tooltipTarget , alignment ) {
414
415
const mouseX = event . clientX ;
415
416
const rect = tooltipTarget . getBoundingClientRect ( ) ;
416
- var computedStyle = window . getComputedStyle ( tooltipTarget ) ;
417
- var lineHeight = parseFloat ( computedStyle . getPropertyValue ( 'line-height' ) ) ;
418
-
417
+ var computedTargetStyle = window . getComputedStyle ( tooltipTarget ) ;
418
+ var lineHeight = parseFloat ( computedTargetStyle . getPropertyValue ( 'line-height' ) ) ;
419
+ // Size is still not yet calculated correctly here
420
+ var tooltipRect = tooltip . getBoundingClientRect ( ) ;
421
+ var computedTooltipStyle = window . getComputedStyle ( tooltip ) ;
422
+ var tooltipWidth = parseFloat ( computedTooltipStyle . getPropertyValue ( 'width' ) ) ;
419
423
var pos = new DOMPoint ( ) ;
424
+
425
+ var xShift = ( alignment == 'tooltip-align-left' ? tooltipWidth : ( alignment == 'tooltip-align-center' ? tooltipWidth / 2 : 0 ) ) ;
420
426
pos . x = mouseX ; // Use now mouse X instead - Math.max(0, pos.x + document.documentElement.scrollLeft + rect.left);
427
+ pos . x -= xShift ;
428
+
421
429
// If the occupied space of the tooltip target is bigger than its line height, it means it spanws to multiple lines
422
430
// align to the upper line part in that case if the mouse is on the right side of the middle of its rect, otherwise align to the bottom row part
423
431
var multilineUpperPart = ( rect . height > lineHeight && mouseX > rect . x + rect . width / 2 ) ;
424
432
pos . y = pos . y + document . documentElement . scrollTop + rect . top + rect . height / ( multilineUpperPart ? 2 : 1 ) ;
425
433
426
- return pos ;
434
+ var tooltipArrowHorizontalPadding = ( 4 * toolTipArrowHalfSize ) * ( alignment == 'tooltip-align-left' ? 1 : ( alignment == 'tooltip-align-right' ? - 1 : 0 ) ) ;
435
+ setArrowPosition ( '--tooltip-arrow-left' , xShift - tooltipArrowHorizontalPadding - toolTipArrowHalfSize ) ;
436
+ setArrowPosition ( '--tooltip-arrow-top' , - 1 * toolTipArrowHalfSize ) ;
437
+
438
+ tooltip . style . left = pos . x + tooltipArrowHorizontalPadding + 'px' ;
439
+ tooltip . style . top = pos . y + toolTipArrowHalfSize + 'px' ;
427
440
}
428
441
429
442
function setArrowPosition ( posName , position ) {
430
443
var newPosition = position + 'px' ;
431
444
tooltip . style . setProperty ( posName , newPosition ) ;
432
445
}
433
446
434
- function showTooltip ( event , tooltipText , isFullPageContent ) {
447
+ function showTooltip ( event , tooltipText , alignment , isFullPageContent ) {
435
448
tooltip . innerHTML = tooltipText . innerHTML ;
436
449
450
+ // FIXME: try to limit the tooltip height not to overflow at bottom
451
+ // This
452
+ // - still has no scroll bar in the inner content
453
+ // - screws up the arrow bellow
454
+ // var firstDiv = tooltip.querySelector("div");
455
+ // if (firstDiv) {
456
+ // tooltip.style.maxHeight = window.innerHeight + 'px';
457
+ // tooltip.style.overflowY = 'hidden';
458
+ // firstDiv.style.overflowY = 'auto';
459
+ // }
460
+
437
461
if ( isFullPageContent )
438
462
tooltip . classList . add ( "full-content-tooltip" ) ;
439
463
else
440
464
tooltip . classList . remove ( "full-content-tooltip" ) ;
441
-
442
- var tooltipPos = getTooltipPos ( event , tooltipTarget )
443
- var tooltipArrowLeftShift = 2 * toolTipArrowSize ;
444
-
445
- setArrowPosition ( '--tooltip-arrow-top' , - 1 * toolTipArrowSize ) ;
446
- setArrowPosition ( '--tooltip-arrow-left' , tooltipArrowLeftShift + toolTipArrowSize / 2 ) ;
447
-
448
- tooltip . style . left = tooltipPos . x - 2 * tooltipArrowLeftShift + 'px' ;
449
- tooltip . style . top = tooltipPos . y + toolTipArrowSize + 'px' ;
465
+ tooltip . classList . remove ( 'tooltip-align-left' , 'tooltip-align-center' , 'tooltip-align-right' ) ;
466
+ tooltip . classList . add ( alignment ) ;
467
+
468
+ setTooltipPos ( event , tooltipTarget , alignment )
450
469
451
470
shouldShowTooltip = true ;
452
471
453
472
clearTimeout ( hideTimeoutFuncID ) ;
454
473
clearTimeout ( showTimeoutFuncID ) ;
455
474
showTimeoutFuncID = setTimeout ( function ( ) {
456
475
if ( shouldShowTooltip ) {
457
- // Size is still not yet calculated correctly here
458
- // var rect = tooltip.getBoundingClientRect();
459
- // tooltip.style.top = (tooltipPos.y + rect.height) + 'px';
460
- // tooltip.style.left = (tooltipPos.x + rect.width / 2) + 'px';
461
-
462
476
tooltip . classList . add ( 'visible' ) ;
463
477
}
464
478
} , 100 ) ;
@@ -500,6 +514,7 @@ $(function () {
500
514
501
515
element . addEventListener ( 'mouseover' , function ( event ) {
502
516
var isFullPageContent = element . classList . contains ( 'full-content-tooltip' ) ;
517
+ var alignment = ( element . classList . contains ( 'tooltip-align-left' ) ? 'tooltip-align-left' : ( element . classList . contains ( 'tooltip-align-center' ) ? 'tooltip-align-center' : 'tooltip-align-right' ) ) ;
503
518
504
519
tooltipTarget = element ;
505
520
@@ -515,7 +530,10 @@ $(function () {
515
530
if ( newContent . length > 0 ) {
516
531
// cache for reuse
517
532
tooltipText . innerHTML = newContent ;
518
- showTooltip ( event , tooltipText , isFullPageContent ) ;
533
+ setTimeout ( ( ) => {
534
+ // Get the bounding client rect after rendering
535
+ showTooltip ( event , tooltipText , alignment , isFullPageContent ) ;
536
+ } , 0 ) ;
519
537
}
520
538
else {
521
539
// Quick navigation from another link with tooltip to this link would keep alive the previous tooltip
@@ -539,7 +557,7 @@ $(function () {
539
557
}
540
558
}
541
559
else
542
- showTooltip ( event , tooltipText , isFullPageContent ) ;
560
+ showTooltip ( event , tooltipText , alignment , isFullPageContent ) ;
543
561
} ) ;
544
562
} ) ;
545
563
0 commit comments