Skip to content

Commit

Permalink
remove drag and drop function
Browse files Browse the repository at this point in the history
  • Loading branch information
dejotb committed Jul 23, 2022
1 parent f428b0a commit f7357a5
Showing 1 changed file with 1 addition and 57 deletions.
58 changes: 1 addition & 57 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class App {
'click',
this._handleSettings.bind(this)
);
listItems.addEventListener('dragstart', this._dragAndDrop.bind(this));
listItems.addEventListener(
'dragend',
this._handleOnDragAndDropEnd.bind(this)
);
listItems.addEventListener('dragover', this._dragOver.bind(this));

// Get data from local storage
this._getLocalStorageNotes();
Expand Down Expand Up @@ -85,7 +79,7 @@ class App {
note.id
}" style='background-color:rgb(${
note.color
}); color: ${this._darkenRandomColor(note.color, 2.5)}' draggable="true">
}); color: ${this._darkenRandomColor(note.color, 2.5)}'>
<h2 style='color: ${this._darkenRandomColor(note.color, 2.3)}'>${
!note.title ? '' : note.title
}</h2>
Expand Down Expand Up @@ -424,56 +418,6 @@ class App {
});
}

_dragAndDrop(e) {
const draggable = e.target.closest('.list__item');
draggable.classList.add('dragging');
}

_dragOver(e) {
e.preventDefault();
const draggable = e.target.closest('.list__item');
const afterElement = this._getDragAfterElement(listItems, e.clientX);
console.log(afterElement);
if (draggable == null) {
return;
}
if (afterElement == null) {
listItems.appendChild(draggable);
} else {
listItems.insertBefore(draggable, afterElement);
}
}

_handleOnDragAndDropEnd(e) {
const draggable = e.target.closest('.list__item');
draggable.classList.remove('dragging');
}

_getDragAfterElement(container, y) {
const draggableElements = [
...container.querySelectorAll('.list__item:not(.dragging)'),
];
console.log(draggableElements);
return draggableElements.reduce(
(closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.bottom - box.height / 2;
console.log(offset);
if (offset < 0 && offset > closest.offset) {
return {
offset,
element: child,
};
}

return closest;
},
{
offset: Number.NEGATIVE_INFINITY,
}
).element;
}

async _generateQuote() {
try {
const data = await fetch(`https://api.goprogram.ai/inspiration`);
Expand Down

0 comments on commit f7357a5

Please sign in to comment.