Skip to content

Commit

Permalink
first try
Browse files Browse the repository at this point in the history
  • Loading branch information
Dufgui committed Apr 14, 2024
1 parent f8afeee commit 5fb5886
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions addon/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function initButton(sfHost, inInspector) {
btn.tabIndex = 0;
btn.accessKey = "i";
btn.title = "Show Salesforce details (Alt+I / Shift+Alt+I)";
rootEl.appendChild(btn);
loadPopup();
rootEl.appendChild(btn);
document.body.appendChild(rootEl);

addFlowScrollability();
Expand Down Expand Up @@ -81,22 +81,34 @@ function initButton(sfHost, inInspector) {
}
}

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

function updateButtonCSSPropertiesIfNeeded(rootElement, buttonElement, popupArrowOrientation, popupArrowPosition) {
if (popupArrowOrientation == "vertical") {
rootElement.style.right = 0;
rootElement.style.top = popupArrowPosition;
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAPCAYAAADd/14OAAAA40lEQVQoz2P4//8/AzpWzGj6L59U/V8urgxMg/g4FUn6J/+X9E38LxWc8V8htR67IpCkuGfMfxCQjSpENRFFkXvk/1+/foGxQloDSD0DVkVfvnyBY7hCdEVv3rxBwXCFIIdKh2WDFT1+/BgDo1qd2fL/1q1bWDFcoW5xz3/Xppn/oycu/X/x4kUMDFeoWdD136R8wn+f9rlgxSdOnEDBKFajK96/fz8coyjEpnj79u1gjKEQXXFE/+L/Gzdu/G9WMfG/am4HZlzDFAf3LPwfOWEJWBPIwwzYUg9MsXXNFDAN4gMAmASShdkS4AcAAAAASUVORK5CYII=";
buttonElement.classList.add("insext-btn-vertical");
if (!(buttonElement.classList.contains("insext-btn-vertical"))) {
rootElement.style.right = "0px";
buttonElement.classList.add("insext-btn-vertical");
buttonElement.classList.remove("insext-btn-horizontal");
let img = document.createElement("img");
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAPCAYAAADd/14OAAAA40lEQVQoz2P4//8/AzpWzGj6L59U/V8urgxMg/g4FUn6J/+X9E38LxWc8V8htR67IpCkuGfMfxCQjSpENRFFkXvk/1+/foGxQloDSD0DVkVfvnyBY7hCdEVv3rxBwXCFIIdKh2WDFT1+/BgDo1qd2fL/1q1bWDFcoW5xz3/Xppn/oycu/X/x4kUMDFeoWdD136R8wn+f9rlgxSdOnEDBKFajK96/fz8coyjEpnj79u1gjKEQXXFE/+L/Gzdu/G9WMfG/am4HZlzDFAf3LPwfOWEJWBPIwwzYUg9MsXXNFDAN4gMAmASShdkS4AcAAAAASUVORK5CYII=";
buttonElement.appendChild(img);
}
} else {
rootElement.style.bottom = "0px";
rootElement.style.right = popupArrowPosition;
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAKCAYAAABrGwT5AAAAAXNSR0IArs4c6QAAAFBlWElmTU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAD6ADAAQAAAABAAAACgAAAADdC3pnAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgoZXuEHAAABKElEQVQoFWNgwAI0C7r+6xb3/AdJKaTW/1fMaAKz0ZUyoguANHKzszEIcnMy3Hn+muHX2+cMLDwCDExs7Az3Z9ShqGdC1gzTKCHAyyDGz8OwszCM4c/Hdwy/P75l+PfrJwO6C+CakTXyc3EwlDnogM09M6eL4e+Xj1gNAGtG15hrrozsIIarSydjNYARXWOKnhQDJycnBubg4GBQDk5lYObhZ2DlFwaHARMocORFBRl4ONgYYtSEUGxE5zzevJDh77cvwEB8AQ4DJnZWFgY2FmaGSCU+dLVY+S+2LWZg+PeP4f+f3wwsP3//Yfj8/SdD6/G3DK/evceqAVkQFHiMwGhjZGFlYPn68xfDwzfvGX78+sPwYFYDSjwia4KxQdHF/JePgZGZmQEASqV1t0W3n+oAAAAASUVORK5CYII=";
buttonElement.classList.add("insext-btn-horizontal");
if (!(buttonElement.classList.contains("insext-btn-horizontal"))) {
rootElement.style.bottom = "0px";
buttonElement.classList.add("insext-btn-horizontal");
buttonElement.classList.remove("insext-btn-vertical");
let img = document.createElement("img");
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAKCAYAAABrGwT5AAAAAXNSR0IArs4c6QAAAFBlWElmTU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAD6ADAAQAAAABAAAACgAAAADdC3pnAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgoZXuEHAAABKElEQVQoFWNgwAI0C7r+6xb3/AdJKaTW/1fMaAKz0ZUyoguANHKzszEIcnMy3Hn+muHX2+cMLDwCDExs7Az3Z9ShqGdC1gzTKCHAyyDGz8OwszCM4c/Hdwy/P75l+PfrJwO6C+CakTXyc3EwlDnogM09M6eL4e+Xj1gNAGtG15hrrozsIIarSydjNYARXWOKnhQDJycnBubg4GBQDk5lYObhZ2DlFwaHARMocORFBRl4ONgYYtSEUGxE5zzevJDh77cvwEB8AQ4DJnZWFgY2FmaGSCU+dLVY+S+2LWZg+PeP4f+f3wwsP3//Yfj8/SdD6/G3DK/evceqAVkQFHiMwGhjZGFlYPn68xfDwzfvGX78+sPwYFYDSjwia4KxQdHF/JePgZGZmQEASqV1t0W3n+oAAAAASUVORK5CYII=";
buttonElement.appendChild(img);
}
}
buttonElement.appendChild(img);
}

function loadPopup() {
Expand All @@ -107,27 +119,35 @@ function initButton(sfHost, inInspector) {
closePopup();
}
});
//manage our self the darg n drop
btn.ondragstart = function() {
return false;
};

function onbuttonmove(event) {
console.log('move to '+event.clientX+' , '+event.clientY);
console.log(' on ' + rootEl.getBoundingClientRect());
//if
//localStorage.setItem("popupArrowOrientation", orientation);
//localStorage.setItem("popupArrowPosition", position);
let popupArrowOrientation;
let popupArrowPosition;
// if above the diagonal
if (event.clientY > (rootEl.getBoundingClientRect().width * event.clientX) * rootEl.getBoundingClientRect().height) {
popupArrowOrientation = "horizontal";
popupArrowPosition = event.clientX / rootEl.getBoundingClientRect().width;
} else {
popupArrowOrientation = "vertical";
popupArrowPosition = event.clientY / rootEl.getBoundingClientRect().height;
}
updateButtonCSSPropertiesIfNeeded(rootEl, btn, popupArrowOrientation, popupArrowPosition)

};
btn.addEventListener("dragstart", (event) => {
event.dataTransfer.dropEffect = "move";
});

btn.addEventListener("drag", (event) => {
onbuttonmove(event);
btn.addEventListener("mousedown", (event) => {
console.log('start');
btn.addEventListener("mousemove", onbuttonmove);
});

btn.addEventListener("drop", (event) => {
onbuttonmove(event);
btn.addEventListener("mouseup", (event) => {
console.log('end');
btn.removeEventListener("mousemove", onbuttonmove);
iFrameLocalStorage.setItem("popupArrowOrientation", popupArrowOrientation);
iFrameLocalStorage.setItem("popupArrowPosition", popupArrowPosition);
updateButtonCSSPropertiesFromStorage(rootEl, btn)
});

let popupSrc = chrome.runtime.getURL("popup.html");
Expand Down Expand Up @@ -156,7 +176,7 @@ function initButton(sfHost, inInspector) {
popupEl.classList.add("insext-popup-vertical-up");
}
}
setRootCSSProperties(rootEl, btn);
updateButtonCSSPropertiesFromStorage(rootEl, btn);
addFlowScrollability(popupEl);
popupEl.contentWindow.postMessage({
insextInitResponse: true,
Expand Down

0 comments on commit 5fb5886

Please sign in to comment.