Skip to content

Commit

Permalink
Update hydra to have scroll into view functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
MAX-786 committed Jul 4, 2024
1 parent 2f54099 commit d70224e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/hydra-js/hydra.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Bridge {
this.deleteButton = null;
this.clickOnBtn = false;
this.quantaToolbar = null;
this.currentPathname =
typeof window !== 'undefined' ? window.location.pathname : null;
this.init();
}

Expand All @@ -20,11 +22,19 @@ class Bridge {
}

if (window.self !== window.top) {
this.navigationHandler = (event) => {
window.parent.postMessage(
{ type: 'URL_CHANGE', url: event.destination.url },
this.adminOrigin,
);
// Handle URL changes generically (no chromium-specific code here)
this.navigationHandler = (e) => {
const newPathname = new URL(e.destination.url).pathname;
if (
newPathname !== this.currentPathname ||
this.currentPathname === null
) {
this.currentUrl = newPathname;
window.parent.postMessage(
{ type: 'URL_CHANGE', url: e.destination.url },
this.adminOrigin,
);
}
};

// Ensure we don't add multiple listeners
Expand Down Expand Up @@ -214,6 +224,12 @@ class Bridge {
window.addEventListener('message', this.messageHandler);
}

/**
* Checks if an element is visible in the viewport
* @param {} el
* @param {} partiallyVisible
* @returns boolean - true if the element is visible in the viewport
*/
elementIsVisibleInViewport(el, partiallyVisible = false) {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
Expand Down

0 comments on commit d70224e

Please sign in to comment.