Skip to content

Commit

Permalink
Merge pull request #32 from obgnail/dev
Browse files Browse the repository at this point in the history
update window_tab
  • Loading branch information
obgnail authored Jul 27, 2023
2 parents 66f05a8 + 2ecf4f7 commit 3876838
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions plugin/window_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,35 +401,17 @@

if (config.ALLOW_DRAG) {
let lastOver = null;
const toggleOver = (ev, f) => {
ev.preventDefault();
const target = ev.target.closest(".tab-container");
if (target) {
if (f === "add") {
target.classList.add("over");
lastOver = target;
} else {
target.classList.remove("over");
}
}
}
const tabBar = $("#plugin-window-tab .tab-bar");

entities.tabBar.addEventListener("dragstart", ev => {
const draggedTab = ev.target.closest(".tab-container");
if (draggedTab) {
draggedTab.style.opacity = 0.5;
lastOver = null;
}
tabBar.on("dragstart", ".tab-container", function (ev) {
ev.originalEvent.dataTransfer.effectAllowed = "move";
ev.originalEvent.dataTransfer.dropEffect = 'move';
this.style.opacity = 0.5;
lastOver = null;
})
entities.tabBar.addEventListener("dragend", ev => {
const from = ev.target.closest(".tab-container");
if (!from) {
return
}

ev.preventDefault();
from.style.opacity = "";
const fromIdx = parseInt(from.getAttribute("idx"));
tabBar.on("dragend", ".tab-container", function (ev) {
this.style.opacity = "";
const fromIdx = parseInt(this.getAttribute("idx"));

const offsetY = Math.abs(ev.offsetY);
const height = entities.tabBar.getBoundingClientRect().height;
Expand All @@ -440,17 +422,36 @@
}

if (lastOver) {
lastOver.classList.remove("over");
const activeIdx = parseInt(entities.tabBar.querySelector(".tab-container.active").getAttribute("idx"));
const activePath = tabUtil.tabs[activeIdx].path;
const toIdx = parseInt(lastOver.getAttribute("idx"));
const ele = tabUtil.tabs.splice(fromIdx, 1)[0];
tabUtil.tabs.splice(toIdx, 0, ele);
openTab(activePath);
}
});
entities.tabBar.addEventListener("dragover", ev => toggleOver(ev, "add"))
entities.tabBar.addEventListener("dragenter", ev => toggleOver(ev, "add"))
entities.tabBar.addEventListener("dragleave", ev => toggleOver(ev, "remove"))
})

const toggleOver = (target, f) => {
if (f === "add") {
target.classList.add("over");
lastOver = target;
} else {
target.classList.remove("over");
}
}

tabBar.on("dragover", ".tab-container", function () {
toggleOver(this, "add");
return false
})
tabBar.on("dragenter", ".tab-container", function () {
toggleOver(this, "add");
return false
})
tabBar.on("dragleave", ".tab-container", function () {
toggleOver(this, "remove");
})
}

console.log("window_tab.js had been injected");
Expand Down

0 comments on commit 3876838

Please sign in to comment.