Make entries draggable

This commit is contained in:
Rob Garrison 2018-11-25 17:37:08 -06:00
parent 4475a8ad6a
commit ed07cb8460
2 changed files with 50 additions and 1 deletions

44
manage/draggable.js Normal file
View File

@ -0,0 +1,44 @@
/* global UI $$ */
'use strict';
// Polyfill for mobile? - https://caniuse.com/#feat=dragndrop
(() => {
let dragged = null;
function cleanup() {
$$('.entry.dragging').forEach(el => {
el.classList.remove('dragging');
});
$('body').classList.remove('dragging');
}
document.addEventListener('dragstart', event => {
const el = event.target.closest('.entry');
if (el) {
dragged = el;
el.classList.add('dragging');
$('body').classList.add('dragging');
}
}, false);
document.addEventListener('dragend', () => {
cleanup();
});
document.addEventListener('dragenter', event => {
const el = event.target.closest('.entry, .entry-header');
if (el && dragged) {
// Insert after the target; keeps header at top
el.after(dragged);
}
}, false);
document.addEventListener('drop', event => {
event.preventDefault();
cleanup();
if (dragged) {
dragged = null;
}
}, false);
})();

View File

@ -226,8 +226,13 @@ a:hover {
pointer-events: none; pointer-events: none;
} }
body.dragging .entry:not(.dragging) .entry-name:before {
/* hide the sustained hover */
background-image: none !important;
}
.entry.dragging { .entry.dragging {
background: linear-gradient(to right, hsla(180, 50%, 30%, 0.2), hsla(180, 20%, 10%, 0.05) 50%, transparent); background: linear-gradient(to right, hsla(350, 50%, 30%, 0.2), hsla(180, 20%, 10%, 0.05) 50%, transparent);
} }
.entry.enabled .entry-name:hover .style-name { .entry.enabled .entry-name:hover .style-name {