Skip to content

Commit

Permalink
Fixed selectBoxPosition error on window resize if no element is selec…
Browse files Browse the repository at this point in the history
…ted #360
  • Loading branch information
givanz committed Jun 27, 2024
1 parent 6d56c92 commit 86f9757
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions libs/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,24 +1083,19 @@ Vvveb.Builder = {

selectBoxPosition = function(event) {
let pos;
let target;
let target = self.selectedEl;// ?? self.highlightEl;

highlightBox.style.display = "none";

if (target) {
pos = offset(target);

if (self.selectedEl) {
pos = offset(self.selectedEl);
target = self.selectedEl;
} else
if (self.highlightEl) {
pos = offset(self.highlightEl);
target = self.highlightEl;
}

SelectBox.style.top = (pos.top - (self.frameDoc.scrollTop ?? 0) - self.selectPadding) + "px";
SelectBox.style.left = (pos.left - (self.frameDoc.scrollLeft ?? 0) - self.selectPadding) + "px";
SelectBox.style.top = (pos.top - (self.frameDoc.scrollTop ?? 0) - self.selectPadding) + "px";
SelectBox.style.left = (pos.left - (self.frameDoc.scrollLeft ?? 0) - self.selectPadding) + "px";

SelectBox.style.width = ((target.offsetWidth ?? target.clientWidth) + self.selectPadding * 2) + "px";
SelectBox.style.height = ((target.offsetHeight ?? target.clientHeight) + self.selectPadding * 2) + "px";
SelectBox.style.width = ((target.offsetWidth ?? target.clientWidth) + self.selectPadding * 2) + "px";
SelectBox.style.height = ((target.offsetHeight ?? target.clientHeight) + self.selectPadding * 2) + "px";
}
}

window.FrameWindow.addEventListener("scroll", selectBoxPosition);
Expand Down Expand Up @@ -2197,13 +2192,13 @@ Vvveb.Builder = {
})
.catch((err) => {
if (error) error(err);
let message = error.statusText ?? "Error saving!";
let message = error?.statusText ?? "Error saving!";
displayToast("bg-danger", "Error", message);

err.text().then( errorMessage => {
if (err.hasOwnProperty('text')) err.text().then( errorMessage => {
let message = errorMessage.substr(0, 200);
displayToast("bg-danger", "Error", message);
})
});
});
},

Expand Down Expand Up @@ -2345,7 +2340,7 @@ Vvveb.CssEditor = {
}

function displayToast(bg, title, message, id = "top-toast") {
document.querySelector("#" + id + " .toast-body .message").innerHTML = message;
document.querySelector("#" + id + " .toast-body .message").innerHTML = message.replace(/(?:\r\n|\r|\n)/g, '<br>');
let header = document.querySelector("#" + id + " .toast-header");
header.classList.remove("bg-danger", "bg-success")
header.classList.add(bg);
Expand Down Expand Up @@ -2425,13 +2420,8 @@ Vvveb.Gui = {
}, (error) => {
document.querySelector(".loading", btn).classList.toggle("d-none");
document.querySelector(".button-text", btn).classList.toggle("d-none");
let message = error.statusText ?? "Error saving!";
let message = error?.statusText ?? "Error saving!";
displayToast("bg-danger", "Error", message);

error.text().then( errorMessage => {
let message = errorMessage.substr(0, 200);
displayToast("bg-danger", "Error", message);
})
});
},

Expand Down Expand Up @@ -3577,6 +3567,7 @@ Vvveb.FileManager = {
bg = "bg-danger";
}

newfile = data.newfile ?? newfile;
displayToast(bg, "Rename", data.message ?? data);
let baseName = newfile.replace('.html', '');
let newName = friendlyName(newfile.replace(/.*[\/\\]+/, '')).replace('.html', '');
Expand All @@ -3589,9 +3580,10 @@ Vvveb.FileManager = {
} else {
_self.pages[page.page]["file"] = newfile;
_self.pages[page.page]["title"] = newName;
document.querySelector(":scope > label span", element).innerHTML = newName;
page.url = page.url.replace(page.file, newfile);
page.url = data.url ?? page.url.replace(page.file, newfile);
page.file = newfile;
element.querySelector(":scope > label span").innerHTML = newName;
element.querySelector(":scope > label a.view").setAttribute("href", page.url);
_self.pages[page.page]["url"] = page.url;
_self.pages[page.page]["file"] = page.file;
}
Expand Down

0 comments on commit 86f9757

Please sign in to comment.