Guest User

Untitled

a guest
Jan 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. moveElem(elemID) {
  2. let self = this;
  3. function parseNumber(num) {
  4. return parseFloat(num.replace(/[^d]/)) || 0;
  5. }
  6.  
  7. let moveElemento = (function () {
  8.  
  9. let coords = [];
  10. let startX;
  11. let startY;
  12.  
  13. let currentElemento = null;
  14. let currentWidth = 0;
  15. let currentHeight = 0;
  16. let currentLeft = 0;
  17. let currentTop = 0;
  18. let callMoveOnElemento = null;
  19. let callMoveStopElemento = null;
  20.  
  21. let contentMove = '.circle' + elemID;
  22. let move = false;
  23.  
  24. let marginStop = 30;
  25. let maxWidth = window.innerWidth - marginStop;
  26. let maxHeight = window.innerHeight - marginStop;
  27.  
  28. $(contentMove).on('mousedown', function (e) {
  29. currentElemento = this.parentNode;
  30. currentLeft = parseNumber(currentElemento.style.left);
  31. currentTop = parseNumber(currentElemento.style.top);
  32.  
  33. startX = e.clientX;
  34. startY = e.clientY;
  35. if (typeof (callMoveOnElemento) == 'function')
  36. callMoveOnElemento(currentElemento);
  37. move = true;
  38. });
  39.  
  40. $(document).on('mouseup', function () {
  41. if (currentElemento == null) return;
  42. if (typeof (callMoveStopElemento) == 'function')
  43. callMoveStopElemento(currentElemento);
  44. currentElemento = null;
  45. move = false;
  46. })
  47.  
  48. $(document).on('mousemove', function (e) {
  49. if (move == true) {
  50. let newX = currentLeft + e.clientX - startX;
  51. let newY = currentTop + e.clientY - startY;
  52.  
  53. if (marginStop > e.clientX) return;
  54. if (marginStop > e.clientY) return;
  55. if (maxWidth < e.clientX) return;
  56. if (maxHeight < e.clientY) return;
  57.  
  58. $(currentElemento).css({
  59. 'left': newX,
  60. 'top': newY
  61. });
  62.  
  63. coords = [{ "id": elemID, "latitude": newY, "longitude": newX }];
  64. self.trabalharRespostaFuncao(coords);
  65. }
  66. });
  67.  
  68. return function (func1, func2) {
  69. callMoveOnElemento = func1;
  70. callMoveStopElemento = func2;
  71. }
  72. })();
  73. }
  74.  
  75. private trabalharRespostaFuncao(coords) {
  76. for (var coord of coords) {
  77. this.popularListaCoordenadas(coord);
  78. }
  79. }
  80.  
  81. private popularListaCoordenadas(coord) {
  82. this.coordenadas.push({
  83. id: coord.id, latitude: coord.latitude, longitude: coord.longitude
  84. });
  85.  
  86. }
Add Comment
Please, Sign In to add comment