Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto positioning of tooltip #7996

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,53 @@
var actualWidth = $tip[0].offsetWidth
var actualHeight = $tip[0].offsetHeight

// Get positions
var tpt = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
var tpb = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
var tpr = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
var tpl = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}

// Get position room
var hast = (tpt.top > $(window).scrollTop())
var hasb = ((tpb.top + actualHeight) < ($(window).scrollTop() + $(window).height()))
var hasr = ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width()))
var hasl = (tpl.left > $(window).scrollLeft())

switch (placement) {
case 'top':
if (!hast) {
placement = hasb ? 'bottom' : (hasr ? 'right' : (hasl ? 'left' : 'right'))
}
break
case 'bottom':
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
if (!hasb) {
placement = hast ? 'top' : (hasr ? 'right' : (hasl ? 'left' : 'right'))
}
break
case 'top':
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
case 'right':
if (!hasr) {
placement = hasl ? 'left' : (hast ? 'top' : (hasb ? 'bottom' : 'right'))
}
break
case 'left':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
if (!hasl) {
placement = hasr ? 'right' : (hast ? 'top' : (hasb ? 'bottom' : 'right'))
}
break
}

switch (placement) {
case 'top':
tp = tpt;
break
case 'bottom':
tp = tpb;
break
case 'right':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
tp = tpr;
break
case 'left':
tp = tpl;
break
}

Expand Down