28 lines
985 B
JavaScript
28 lines
985 B
JavaScript
/**
|
|
* ZDDC Classifier — drag payload bus for Classify & Copy.
|
|
*
|
|
* HTML5 dataTransfer can't be read during `dragover` (only on `drop`), and we
|
|
* need the dragged set to drive drop-target highlighting. So the source keys
|
|
* live in a module variable for the lifetime of a drag; dataTransfer carries a
|
|
* marker so the browser shows a copy cursor and external drops are ignored.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var keys = [];
|
|
|
|
function setDrag(srcKeys, e) {
|
|
keys = (srcKeys || []).slice();
|
|
if (e && e.dataTransfer) {
|
|
e.dataTransfer.effectAllowed = 'copy';
|
|
try { e.dataTransfer.setData('application/x-zddc-keys', keys.join('\n')); } catch (_) { /* ok */ }
|
|
}
|
|
}
|
|
function getDrag() { return keys; }
|
|
function active() { return keys.length > 0; }
|
|
function clearDrag() { keys = []; }
|
|
|
|
window.app.modules.dnd = {
|
|
setDrag: setDrag, getDrag: getDrag, active: active, clearDrag: clearDrag,
|
|
};
|
|
})();
|