Skip to content
Open
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
17 changes: 16 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

<style>
.list-group-item.dragging {
opacity: 0.5;
background: var(--bs-dark);
}
.list-group-item {
transition: background-color 0.2s ease;
}
.drag-handle {
user-select: none;
color: var(--bs-secondary);
}
</style>

<title>PiOSK</title>
</head>
<body>
Expand Down Expand Up @@ -33,7 +47,8 @@ <h1 class="my-1">Pi<span class="bg-danger mx-1 px-1 rounded">OSK</span></h1>
</footer>

<template id="template-url">
<li class="list-group-item text-truncate fs-3">
<li class="list-group-item text-truncate fs-3" draggable="true">
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding ARIA attributes (e.g., aria-grabbed) to this draggable element to improve accessibility for keyboard and assistive technology users.

Suggested change
<li class="list-group-item text-truncate fs-3" draggable="true">
<li class="list-group-item text-truncate fs-3" draggable="true" aria-grabbed="false" role="listitem" aria-dropeffect="move">

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, if you want to add.

<span class="drag-handle mx-2" style="cursor: move;">⋮⋮</span>
<button type="button" class="btn btn-close mx-3" aria-label="Remove"></button>
<a class="link-underline-dark"></a>
</li>
Expand Down
34 changes: 34 additions & 0 deletions web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,38 @@ let piosk = {
tmpErr.html(xhr.responseText)
$('#urls').append(tmpErr)
setTimeout(_ => { $('.alert-danger').remove() }, 5000)
},
initDragAndDrop() {
const list = document.querySelector('#urls .list-group');

Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a check to verify that the 'list' element exists before binding drag event listeners, to prevent potential runtime errors if the element is missing.

Suggested change
if (!list) {
console.warn("Element '#urls .list-group' not found. Drag-and-drop functionality will not be initialized.");
return;
}

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this.

list.addEventListener('dragstart', (e) => {
if (e.target.classList.contains('list-group-item')) {
e.target.classList.add('dragging');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/plain', e.target.dataset.index);
}
});

list.addEventListener('dragend', (e) => {
if (e.target.classList.contains('list-group-item')) {
e.target.classList.remove('dragging');
}
});

list.addEventListener('dragover', (e) => {
e.preventDefault();
const draggingItem = list.querySelector('.dragging');
if (!draggingItem) return;

const siblings = [...list.querySelectorAll('.list-group-item:not(.dragging)')];
const nextSibling = siblings.find(sibling => {
const box = sibling.getBoundingClientRect();
const offset = e.clientY - box.top - box.height / 2;
return offset < 0;
});

list.insertBefore(draggingItem, nextSibling);
});
}
}

Expand All @@ -37,6 +69,8 @@ $(document).ready(() => {
$(e.target).parent().remove()
})

piosk.initDragAndDrop();

$('#execute').on('click', (e) => {
let config = {}
config.urls = []
Expand Down