Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag N' Drop #418

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/dropHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function dropHandler(ev) {
console.log("File(s) dropped");

ev.preventDefault();

if (ev.dataTransfer.items) {
[...ev.dataTransfer.items].forEach((item, i) => {
if (item.kind === "file") {
const file = item.getAsFile();
document.querySelector('.current').src = file.path;
}
});
} else {
alert('File type unsupported.')
}
}


function dragOverHandler(ev) {
console.log("File(s) in drop zone");

ev.preventDefault();
}

3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<script src="./tabs.js" defer></script>
<script src="./search.js" defer></script>
<script src="./preferences.js" defer></script>
<script src="./dropHandler.js" defer></script>
<link rel="stylesheet" type="text/css" href="../output/tailwind.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body class="object-contain bg min-w-full bg-gray-200 dark:bg-gray-900 min-h-screen bg-white/0 overflow-hidden">
<body ondrop="dropHandler(event)" ondragover="dragOverHandler(event)"; class="object-contain bg min-w-full bg-gray-200 dark:bg-gray-900 min-h-screen bg-white/0 overflow-hidden">
<div id="loading"
class="fixed z-40 flex items-center justify-center w-full h-full transition duration-500 bg-gray-50 dark:bg-gray-900">
<img src="../assets/icon.png" alt="loading..." class="animate-spin h-1/2 aspect-square">
Expand Down