1 | import Vue from 'vue';
|
2 | let isDragging = false;
|
3 |
|
4 | export default function(element, options) {
|
5 | if (Vue.prototype.$isServer) return;
|
6 | const moveFn = function(event) {
|
7 | if (options.drag) {
|
8 | options.drag(event);
|
9 | }
|
10 | };
|
11 | const upFn = function(event) {
|
12 | document.removeEventListener('mousemove', moveFn);
|
13 | document.removeEventListener('mouseup', upFn);
|
14 | document.onselectstart = null;
|
15 | document.ondragstart = null;
|
16 |
|
17 | isDragging = false;
|
18 |
|
19 | if (options.end) {
|
20 | options.end(event);
|
21 | }
|
22 | };
|
23 | element.addEventListener('mousedown', function(event) {
|
24 | if (isDragging) return;
|
25 | document.onselectstart = function() { return false; };
|
26 | document.ondragstart = function() { return false; };
|
27 |
|
28 | document.addEventListener('mousemove', moveFn);
|
29 | document.addEventListener('mouseup', upFn);
|
30 | isDragging = true;
|
31 |
|
32 | if (options.start) {
|
33 | options.start(event);
|
34 | }
|
35 | });
|
36 | }
|