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

Features/drag and drop edit #14

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*
11 changes: 11 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,15 @@ a#show-list-form span:nth-child(2), a.show-card-form span:nth-child(2){

.overlay-opacity {
opacity: 0.3;
}


.add-item-form > div,
.list-heading,
.card > p{
user-select: none;
}
.card {
user-select: auto;
z-index: 200;
}
30 changes: 27 additions & 3 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ let menu = {
// add new list submit eventlistener
document.getElementById("add-list-form").addEventListener("submit", addList);

// ------------DRAG AND DROP ------------ /
var dropTarget = document.querySelector(".board-wrapper"); // for drag-and-drop
dropTarget.addEventListener('dragover', function(ev){
ev.preventDefault();
})
dropTarget.addEventListener('drop', function(ev) {
ev.preventDefault();
let target = ev.target;
let droppable = target.classList.contains('dropTarget');
let srcId = ev.dataTransfer.getData("srcId");

if (droppable) {
ev.target.appendChild(document.getElementById(srcId));
}
});

//Declaring index
let listIndex = 0;
let countCard = 0;
Expand All @@ -118,8 +134,8 @@ function addList(e) {
<div class="list-heading" >
<h3 contenteditable="true">` + name + `</h3>
<div class= "ellipsis"><a href="#">&#8230;</a></div>
</div>
<div>
</div class="dropTarget-wrapper">
<div class="dropTarget">
<form class="add-item-form">
<textarea placeholder="Enter a title for this card..."></textarea>
<div>
Expand Down Expand Up @@ -155,7 +171,15 @@ document.addEventListener('submit', function(e) {
//create card
const cardItem = document.createElement('p');
const card = document.createElement('div');
card.setAttribute('class', 'card');

// DRAG AND DROP
card.setAttribute('class', 'card'); // VT - this sets class of card
card.setAttribute('id', Date.now()); // VT - Unique id generator needed for drag-n-drop
card.addEventListener("dragstart", function(ev){
ev.dataTransfer.setData("srcId", ev.target.id);
});
// END DRAG AND DROP

//create pen icon
const pen = document.createElement('a');
pen.innerHTML = '<i class="fas fa-pen"></i>';
Expand Down