@opentiny/vue-renderless
Version:
An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
39 lines (38 loc) • 1.25 kB
JavaScript
import "../../chunk-G2ADBYYC.js";
let isDragging = false;
function draggable(element, options) {
const moveFn = function(event) {
var _a;
(_a = options.drag) == null ? void 0 : _a.call(options, event);
};
const upFn = function(event) {
var _a;
document.removeEventListener("mousemove", moveFn);
document.removeEventListener("mouseup", upFn);
document.removeEventListener("touchmove", moveFn);
document.removeEventListener("touchend", upFn);
document.onselectstart = null;
document.ondragstart = null;
isDragging = false;
(_a = options.end) == null ? void 0 : _a.call(options, event);
};
const downFn = function(event) {
var _a;
if (isDragging)
return;
event.preventDefault();
document.onselectstart = () => false;
document.ondragstart = () => false;
document.addEventListener("mousemove", moveFn);
document.addEventListener("mouseup", upFn);
document.addEventListener("touchmove", moveFn);
document.addEventListener("touchend", upFn);
isDragging = true;
(_a = options.start) == null ? void 0 : _a.call(options, event);
};
element.addEventListener("mousedown", downFn);
element.addEventListener("touchstart", downFn);
}
export {
draggable
};