stylus/manage/draggable.js

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-12-03 03:06:05 +00:00
/* global UI $$ updateInjectionOrder */
2018-11-25 23:37:08 +00:00
'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');
2018-12-03 03:06:05 +00:00
updateInjectionOrder();
2018-11-25 23:37:08 +00:00
}
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);
})();