File size: 1,468 Bytes
c0bb696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// jshint esversion: 8
// release 24-04-2022


const nodrag_tds = ['input', 'select', 'a'];
const nodrag_cls = "nodrag";

var UaDrag = function (e) {
    const drag = function (element) {
        let pos1 = 0,
            pos2 = 0,
            pos3 = 0,
            pos4 = 0;

        const dragMouseDown = function (e) {
            e = e || window.event;
            let t = e.target;
            t = t || null;
            if (!t) return;
            if (nodrag_tds.includes(t.tagName.toLowerCase())) return;
            if (t.classList.contains(nodrag_cls)) return;
            e.preventDefault();
            //e.stopImmediatePropagation();
            pos3 = e.clientX;
            pos4 = e.clientY;
            document.onmouseup = closeDragElement;
            document.onmousemove = elementDrag;
        };

        const elementDrag = function (e) {
            e = e || window.event;
            //e.stopImmediatePropagation();
            e.preventDefault();
            pos1 = pos3 - e.clientX;
            pos2 = pos4 - e.clientY;
            pos3 = e.clientX;
            pos4 = e.clientY;
            element.style.top = (element.offsetTop - pos2) + "px";
            element.style.left = (element.offsetLeft - pos1) + "px";
        };

        const closeDragElement = function () {
            document.onmouseup = null;
            document.onmousemove = null;
        };

        element.onmousedown = dragMouseDown;
    };
    return drag(e);
};