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

Tooltip/popover placement update #9457

Merged
merged 8 commits into from
Apr 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/NuGetGallery/Scripts/gallery/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,40 @@
};

nuget.setPopovers = function () {
var popoverElement = $(this);
var popoverElementDom = this;
setPopoversInternal(this, rightWithVerticalFallback);
}

function rightWithVerticalFallback(popoverElement, ownerElement) {
// Both numbers below are in CSS pixels.
const MinSpaceOnRight = 150;
const MinSpaceOnTop = 100;

const ownerBoundingBox = ownerElement.getBoundingClientRect();
const spaceOnRight = window.innerWidth - ownerBoundingBox.right;
if (spaceOnRight > MinSpaceOnRight) {
return 'right';
}
const spaceOnTop = ownerBoundingBox.top;
if (spaceOnTop > MinSpaceOnTop) {
return 'top';
}

return 'bottom';
agr marked this conversation as resolved.
Show resolved Hide resolved
}

function setPopoversInternal(element, placement) {
var popoverElement = $(element);
var popoverElementDom = element;
var originalLabel = popoverElementDom.ariaLabel;
var popoverHideTimeMS = 2000;
var popoverFadeTimeMS = 200;

popoverElement.popover({ trigger: 'hover' });
var popoverOptions = { trigger: 'hover', container: 'body' };
if (placement) {
popoverOptions.placement = placement;
}

popoverElement.popover(popoverOptions);
popoverElement.click(popoverShowAndHide);
popoverElement.focus(popoverShowAndHide);
popoverElement.keyup(function (event) {
Expand Down