Requires

Provides

Draggable.js

Drag widget around the screen

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 23
  2. 24
  3. 25
  4. 26
  5. 27
  6. 28
  7. 29
  8. 30
  9. 31
  10. 32
  11. 33
  12. 34
  13. 35
  14. 36
  15. 37
  16. 38
  17. 39
  18. 40
  19. 41
  20. 42
  21. 43
  22. 44
  23. 45
  24. 46
  25. 47
  26. 48
  27. 49
  28. 50
  29. 51
  30. 52
  31. 53
  32. 54
  33. 55
  34. 56
  35. 57
  36. 58
  37. 59
  38. 60
  39. 61
  40. 62
  41. 63
  42. 64
  43. 65
  44. 66
  45. 67
  46. 68
  47. 69
  48. 70
  49. 71
  50. 72
  51. 73
  52. 74
  53. 75
  54. 76
  55. 77
  56. 78
  57. 79
  58. 80
  59. 81
  60. 82
  61. 83
  62. 84
  63. 85
  64. 86
  65. 87
  66. 88
  67. 89
  68. 90
  69. 91
  70. 92
  71. 93
  72. 94
  73. 95
  74. 96
  75. 97
  76. 98
  77. 99
  78. 100
  79. 101
  80. 102
  81. 103
  82. 104
  83. 105
  84. 106
  85. 107
  86. 108
  87. 109
  88. 110
  89. 111
  90. 112
  91. 113
LSD.Mixin.Draggable = new Class({ behaviour: '[draggable][draggable!=false]', options: { dragger: { modifiers: { x: 'left', y: 'top' }, snap: 5, style: false, container: true, limit: { x: [0, 3000], y: [0, 3000] }, handle: [] }, actions: { draggable: { enable: function(handle) { if (this.index++ == 0) { if (this.dragger) this.dragger.attach(); else this.getDragger(); this.onStateChange('draggable', true); } if (!handle) return; this.handles.push(handle); document.id(handle).addEvent('mousedown', this.dragger.bound.start); }, disable: function(handle) { if (!this.dragger) return; if (--this.index == 0) { this.onStateChange('draggable', false); this.dragger.detach(); } if (!handle) return; this.handles.erase(handle) document.id(handle).removeEvent('mousedown', this.dragger.bound.start); } } } }, initialize: function() { this.parent.apply(this, arguments); this.handles = []; this.index = 0; }, unitialize: function() { this.handles.each(this.options.actions.draggable.disable, this); this.onStateChange('draggable', false); delete this.dragger; }, getDragger: Macro.getter('dragger', function() { var element = this.element; this.onDOMInject(function() { var position = element.getPosition(); element.left = position.x - element.getStyle('margin-left').toInt(); element.top = position.y - element.getStyle('margin-top').toInt(); }.create({delay: 50})); var dragger = new Drag(element, Object.append(this.options.dragger, this.options.dragger)); dragger.addEvents(this.events.dragger); dragger.addEvents({ 'start': this.onDragStart.bind(this), 'complete': this.onDragComplete.bind(this), 'cancel': this.onDragComplete.bind(this), 'drag': this.onDrag.bind(this) }, true); return dragger; }), onDragStart: function() { this.onStateChange('dragged', true); }, onDragComplete: function() { this.onStateChange('dragged', false); }, onDrag: function() { this.setStyles({ top: this.dragger.value.now.y, left: this.dragger.value.now.x }); } });