Skip to content

Commit

Permalink
implemnted states of loading for popup.js. Returned lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
EvAzi committed May 6, 2019
1 parent 47e5c50 commit 72273fd
Show file tree
Hide file tree
Showing 2 changed files with 6,081 additions and 6 deletions.
27 changes: 21 additions & 6 deletions addon/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ if (document.querySelector("body.sfdcBody, body.ApexCSIPage, #auraLoadingBox"))
});
}

let sfHost;
let inInspector;
const rootElId = "insext";
const btnElId = "insext-btn";
const popupElId = "insext-popup";
const popupLoadStates = {
NOT_LOADED: 0,
LOADING: 1,
LOADED: 2
};

let sfHost;
let inInspector;
let popupLoadStateCode;

function initButton(host, isInInspector) {
popupLoadStateCode = popupLoadStates.NOT_LOADED;
sfHost = host;
inInspector = isInInspector;
let rootEl = document.createElement("div");
Expand All @@ -45,15 +53,20 @@ function initButton(host, isInInspector) {
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=";
btn.appendChild(img);
document.body.appendChild(rootEl);
loadPopup();

btn.addEventListener("click", () => {
togglePopup();
});
}

function loadPopup() {
if (popupLoadStateCode >= popupLoadStates.LOADING) {
return;
}
popupLoadStateCode = popupLoadStates.LOADING;

const btn = getButton();
const rootEl = getRootEl();
btn.addEventListener("click", () => {
togglePopup();
});

let popupSrc = chrome.extension.getURL("popup.html");
let popupEl = document.createElement("iframe");
Expand All @@ -77,9 +90,11 @@ function loadPopup() {
}
});
rootEl.appendChild(popupEl);
popupLoadStateCode = popupLoadStates.LOADED;
}

function togglePopup() {
loadPopup();
const rootEl = getRootEl();
if (!rootEl.classList.contains("insext-active")) {
openPopup();
Expand Down
Loading

0 comments on commit 72273fd

Please sign in to comment.