-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handled Responsiveness for all screens * Add event listeners to dynamically adjust the backlink (#14) * PRESS4-88 Install JIT for 3rd party integrations (#12) * Store analytics Component (#11)
- Loading branch information
Showing
11 changed files
with
2,166 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,52 @@ | ||
function updateBacklink() { | ||
let offsets = {}; | ||
const selectors = [ | ||
'#wpadminbar', | ||
'.woocommerce-mobile-app-banner', | ||
'.woocommerce-layout__header-tasks-reminder-bar', | ||
]; | ||
selectors.forEach((selector) => { | ||
const node = document.querySelector(selector); | ||
if (node !== null) { | ||
offsets[selector] = node.getBoundingClientRect().height; | ||
} | ||
}); | ||
let offset = Object.values(offsets).reduce((a, b) => a + b, 0); | ||
let backlink = document.querySelector('.nfd-woocommerce-link'); | ||
if (backlink !== null) { | ||
backlink.style.top = `${offset}px`; | ||
} | ||
} | ||
|
||
function observeAndAdjustBacklink(event) { | ||
updateBacklink(); | ||
const callback = (mutationList, observer) => { | ||
for (const mutation of mutationList) { | ||
if (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0) { | ||
updateBacklink(); | ||
} | ||
} | ||
}; | ||
const layoutContainer = document.querySelector('.woocommerce-layout__header'); | ||
if (layoutContainer !== null) { | ||
new MutationObserver(callback).observe(layoutContainer, { | ||
childList: true, | ||
subtree: true, | ||
}); | ||
} | ||
} | ||
|
||
(function () { | ||
let section = new URLSearchParams(window.location.search); | ||
if (section.has("return_to_nfd")) { | ||
let goBack = document.createElement("a"); | ||
goBack.ariaRoleDescription = "Go Back to Bluehost WordPress Plugin"; | ||
goBack.className = "nfd-woocommerce-link"; | ||
goBack.innerText = "← Back"; | ||
goBack.href = `admin.php?page=bluehost#${section.get("return_to_nfd")}`; | ||
let wcRoot = document.getElementById("wpbody-content"); | ||
wcRoot.insertAdjacentElement("beforebegin", goBack); | ||
if (section.has('return_to_nfd')) { | ||
let goBack = document.createElement('a'); | ||
goBack.ariaRoleDescription = 'Go Back to Bluehost WordPress Plugin'; | ||
goBack.className = 'nfd-woocommerce-link'; | ||
goBack.innerText = '← Back'; | ||
goBack.href = `admin.php?page=bluehost#${section.get('return_to_nfd')}`; | ||
let wcRoot = document.getElementById('wpbody-content'); | ||
wcRoot.insertAdjacentElement('beforebegin', goBack); | ||
updateBacklink(); | ||
window.addEventListener('DOMContentLoaded', observeAndAdjustBacklink); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.