From d99b1317ea5a871087db8775d64b701175312198 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 20 Jan 2024 00:53:35 -0500 Subject: [PATCH] ensure the popup remains onscreen if it would go past the client area --- .../controls/AdditionalDetailWidget.js | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/phast/client/scripts/controls/AdditionalDetailWidget.js b/lib/phast/client/scripts/controls/AdditionalDetailWidget.js index 84d93b8..c46a31b 100644 --- a/lib/phast/client/scripts/controls/AdditionalDetailWidget.js +++ b/lib/phast/client/scripts/controls/AdditionalDetailWidget.js @@ -1,13 +1,68 @@ function AdditionalDetailWidget(parent) { this.Parent = parent; + this.Parent.addEventListener("transitionend", function(e) + { + if (!System.ClassList.Contains(this, "apb-selected")) + { + System.ClassList.Remove(document.body, "uwt-prevent-scrolling"); + } + }); + + this.InitializePopupLocation = function() + { + this.PreviewElement.style.top = ""; + this.PreviewElement.style.left = ""; + this.PreviewElement.style.position = "fixed"; + }; + this.UpdatePopupLocation = function() + { + this.InitializePopupLocation(); + + if (System.ClassList.Contains(this.PreviewElement, "uwt-loading")) + { + return; + } + + var buttonRect = this.ButtonLink.getBoundingClientRect(); + console.log ("button rect: "); + console.log(buttonRect); + + var previewRect = this.PreviewElement.getBoundingClientRect(); + console.log ("preview rect: "); + console.log(previewRect); + + this.PreviewElement.style.top = buttonRect.bottom + "px"; + this.PreviewElement.style.left = buttonRect.right + "px"; + + var offsetBottom = this.PreviewElement.offsetTop + previewRect.height; + console.log ("popup bottom: " + offsetBottom); + console.log ("document height: " + document.body.clientHeight); + + this.PreviewElement.style.left = buttonRect.right + "px"; + if (offsetBottom > document.body.clientHeight) + { + this.PreviewElement.style.top = ""; + this.PreviewElement.style.bottom = (document.body.clientHeight - buttonRect.top) + "px"; + } + else + { + this.PreviewElement.style.top = buttonRect.bottom + "px"; + this.PreviewElement.style.bottom = ""; + } + }; + this.Show = function () { + System.ClassList.Add(document.body, "uwt-prevent-scrolling"); + this.UpdatePopupLocation(); + this.OnOpening(); System.ClassList.Add(this.Parent, "apb-selected"); }; this.Hide = function () { + System.ClassList.Remove(document.body, "uwt-prevent-scrolling"); System.ClassList.Remove(this.Parent, "apb-selected"); }; this.Toggle = function () @@ -29,12 +84,14 @@ function AdditionalDetailWidget(parent) this.IconElement = parent.children[0]; this.TextLink = parent.children[1]; this.ButtonLink = parent.children[2]; + this.PreviewElement = parent.children[3]; } else { this.IconElement = null; this.TextLink = parent.children[0]; this.ButtonLink = parent.children[1]; + this.PreviewElement = parent.children[2]; } // aria @@ -64,7 +121,7 @@ function AdditionalDetailWidget(parent) this.TextLink.addEventListener("focus", function(e) { if (e.relatedTarget !== null) - { + {Show var pos = this.compareDocumentPosition(e.relatedTarget); if (pos == Node.DOCUMENT_POSITION_FOLLOWING && e.relatedTarget !== this.NativeObject.ButtonLink) {