6f633c04374be3abd3b3ff2d802dc5eb1f24c8e3.svn-base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. if (!dojo._hasResource["dojo.dnd.Mover"]) { // _hasResource checks added by
  2. // build. Do not use _hasResource
  3. // directly in your code.
  4. dojo._hasResource["dojo.dnd.Mover"] = true;
  5. dojo.provide("dojo.dnd.Mover");
  6. dojo.require("dojo.dnd.common");
  7. dojo.require("dojo.dnd.autoscroll");
  8. dojo.declare("dojo.dnd.Mover", null, {
  9. constructor : function(node, e, host) {
  10. // summary: an object, which makes a node follow the mouse,
  11. // used as a default mover, and as a base class for custom
  12. // movers
  13. // node: Node: a node (or node's id) to be moved
  14. // e: Event: a mouse event, which started the move;
  15. // only pageX and pageY properties are used
  16. // host: Object?: object which implements the functionality
  17. // of the move,
  18. // and defines proper events (onMoveStart and onMoveStop)
  19. this.node = dojo.byId(node);
  20. this.marginBox = {
  21. l : e.pageX,
  22. t : e.pageY
  23. };
  24. this.mouseButton = e.button;
  25. var h = this.host = host, d = node.ownerDocument, firstEvent = dojo
  26. .connect(d, "onmousemove", this, "onFirstMove");
  27. this.events = [
  28. dojo.connect(d, "onmousemove", this, "onMouseMove"),
  29. dojo.connect(d, "onmouseup", this, "onMouseUp"),
  30. // cancel text selection and text dragging
  31. dojo.connect(d, "ondragstart", dojo, "stopEvent"),
  32. dojo.connect(d, "onselectstart", dojo, "stopEvent"),
  33. firstEvent];
  34. // notify that the move has started
  35. if (h && h.onMoveStart) {
  36. h.onMoveStart(this);
  37. }
  38. },
  39. // mouse event processors
  40. onMouseMove : function(e) {
  41. // summary: event processor for onmousemove
  42. // e: Event: mouse event
  43. dojo.dnd.autoScroll(e);
  44. var m = this.marginBox;
  45. this.host.onMove(this, {
  46. l : m.l + e.pageX,
  47. t : m.t + e.pageY
  48. });
  49. },
  50. onMouseUp : function(e) {
  51. if (this.mouseButton == e.button) {
  52. this.destroy();
  53. }
  54. },
  55. // utilities
  56. onFirstMove : function() {
  57. // summary: makes the node absolute; it is meant to be
  58. // called only once
  59. this.node.style.position = "absolute"; // enforcing the
  60. // absolute mode
  61. var m = dojo.marginBox(this.node);
  62. m.l -= this.marginBox.l;
  63. m.t -= this.marginBox.t;
  64. this.marginBox = m;
  65. this.host.onFirstMove(this);
  66. dojo.disconnect(this.events.pop());
  67. },
  68. destroy : function() {
  69. // summary: stops the move, deletes all references, so the
  70. // object can be garbage-collected
  71. dojo.forEach(this.events, dojo.disconnect);
  72. // undo global settings
  73. var h = this.host;
  74. if (h && h.onMoveStop) {
  75. h.onMoveStop(this);
  76. }
  77. // destroy objects
  78. this.events = this.node = null;
  79. }
  80. });
  81. }