34fe0039489650b4194035f88cb6c05b11f35420bec2bb6495b9801b6f71110e52cf862b2bf54189216ed626481e48569b39745b12f58227a88ad772f79fd1 915 B

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