Skip to content

Commit

Permalink
fix insext popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dufgui committed Apr 16, 2024
1 parent d12ae98 commit 64dda9a
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions addon/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,29 @@ function initButton(sfHost, inInspector) {
}
}

function updateButtonCSSPropertiesFromStorage(rootElement, buttonElement) {
function updateButtonCSSPropertiesFromStorage(rootElement, buttonElement, popupEl) {
let popupArrowOrientation = iFrameLocalStorage.popupArrowOrientation ? iFrameLocalStorage.popupArrowOrientation : "vertical";
let popupArrowPosition = iFrameLocalStorage.popupArrowPosition ? (iFrameLocalStorage.popupArrowPosition + "%") : "122px";
updateButtonCSSPropertiesIfNeeded(rootElement, buttonElement, popupArrowOrientation, popupArrowPosition);
updateButtonCSSPropertiesIfNeeded(rootElement, buttonElement, popupEl, popupArrowOrientation, popupArrowPosition);
}

function updateButtonCSSPropertiesIfNeeded(rootElement, buttonElement, popupArrowOrientation, popupArrowPosition) {
function updateButtonCSSPropertiesIfNeeded(rootElement, buttonElement, popupEl, popupArrowOrientation, popupArrowPosition) {

if (popupArrowOrientation == "vertical") {
rootElement.style.top = popupArrowPosition;

popupEl.classList.remove("insext-popup-horizontal");
popupEl.classList.remove("insext-popup-horizontal-left");
popupEl.classList.remove("insext-popup-horizontal-right");
popupEl.classList.remove("insext-popup-horizontal-centered");

popupEl.classList.add("insext-popup-vertical");
if (popupArrowPosition >= 55) {
popupEl.classList.add("insext-popup-vertical-up");
} else {
popupEl.classList.remove("insext-popup-vertical-up");
}

if (!(buttonElement.classList.contains("insext-btn-vertical"))) {
rootElement.style.right = "0px";
buttonElement.classList.add("insext-btn-vertical");
Expand All @@ -100,7 +114,27 @@ function initButton(sfHost, inInspector) {
buttonElement.appendChild(img);
}
} else {
// horizontal
rootElement.style.right = popupArrowPosition;

if (popupArrowPosition < 8) {
popupEl.classList.add("insext-popup-horizontal-left");
popupEl.classList.remove("insext-popup-horizontal-right");
popupEl.classList.remove("insext-popup-horizontal-centered");
} else if (popupArrowPosition >= 90) {
popupEl.classList.remove("insext-popup-horizontal-left");
popupEl.classList.add("insext-popup-horizontal-right");
popupEl.classList.remove("insext-popup-horizontal-centered");
} else {
popupEl.classList.remove("insext-popup-horizontal-left");
popupEl.classList.remove("insext-popup-horizontal-right");
popupEl.classList.add("insext-popup-horizontal-centered");
}

popupEl.classList.add("insext-popup-horizontal");
popupEl.classList.remove("insext-popup-vertical");
popupEl.classList.remove("insext-popup-vertical-up");

if (!(buttonElement.classList.contains("insext-btn-horizontal"))) {
rootElement.style.bottom = "0px";
rootElement.style.top = "";
Expand All @@ -123,6 +157,8 @@ function initButton(sfHost, inInspector) {
}
});

let popupEl = document.createElement("iframe");

function onbuttonmove(event) {
console.log("move to " + event.clientX + " , " + event.clientY);
//console.log(" on " + rootEl.getBoundingClientRect());
Expand All @@ -139,7 +175,7 @@ function initButton(sfHost, inInspector) {
localStorage.setItem("popupArrowOrientation", popupArrowOrientation);
localStorage.setItem("popupArrowPosition", popupArrowPosition);
popupArrowPosition = popupArrowPosition + "%";
updateButtonCSSPropertiesIfNeeded(rootEl, btn, popupArrowOrientation, popupArrowPosition);
updateButtonCSSPropertiesIfNeeded(rootEl, btn, popupEl, popupArrowOrientation, popupArrowPosition);

}
function endmove(event) {
Expand All @@ -154,7 +190,6 @@ function initButton(sfHost, inInspector) {
});

let popupSrc = chrome.runtime.getURL("popup.html");
let popupEl = document.createElement("iframe");
popupEl.className = "insext-popup";
popupEl.classList.add(localStorage.getItem("popupArrowOrientation") == "horizontal" ? "insext-popup-horizontal" : "insext-popup-vertical");
popupEl.src = popupSrc;
Expand All @@ -165,21 +200,8 @@ function initButton(sfHost, inInspector) {
if (e.data.insextInitRequest) {
// Set CSS classes for arrow button position
iFrameLocalStorage = e.data.iFrameLocalStorage;
popupEl.classList.add(iFrameLocalStorage.popupArrowOrientation == "horizontal" ? "insext-popup-horizontal" : "insext-popup-vertical");
if (iFrameLocalStorage.popupArrowOrientation == "horizontal") {
if (iFrameLocalStorage.popupArrowPosition < 8) {
popupEl.classList.add("insext-popup-horizontal-left");
} else if (iFrameLocalStorage.popupArrowPosition >= 90) {
popupEl.classList.add("insext-popup-horizontal-right");
} else {
popupEl.classList.add("insext-popup-horizontal-centered");
}
} else if (iFrameLocalStorage.popupArrowOrientation == "vertical") {
if (iFrameLocalStorage.popupArrowPosition >= 55) {
popupEl.classList.add("insext-popup-vertical-up");
}
}
updateButtonCSSPropertiesFromStorage(rootEl, btn);

updateButtonCSSPropertiesFromStorage(rootEl, btn, popupEl);
addFlowScrollability(popupEl);
popupEl.contentWindow.postMessage({
insextInitResponse: true,
Expand Down

0 comments on commit 64dda9a

Please sign in to comment.