DragZone.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.dd.DragZone
  8. * @extends Ext.dd.DragSource This class provides a container DD instance that
  9. * proxies for multiple child node sources.<br />
  10. * By default, this class requires that draggable child nodes are
  11. * registered with {@link Ext.dd.Registry}.
  12. * @constructor
  13. * @param {Mixed}
  14. * el The container element
  15. * @param {Object}
  16. * config
  17. */
  18. Ext.dd.DragZone = function(el, config) {
  19. Ext.dd.DragZone.superclass.constructor.call(this, el, config);
  20. if (this.containerScroll) {
  21. Ext.dd.ScrollManager.register(this.el);
  22. }
  23. };
  24. Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
  25. /**
  26. * @cfg {Boolean} containerScroll True to register this container
  27. * with the Scrollmanager for auto scrolling during drag
  28. * operations.
  29. */
  30. /**
  31. * @cfg {String} hlColor The color to use when visually highlighting
  32. * the drag source in the afterRepair method after a failed
  33. * drop (defaults to "c3daf9" - light blue)
  34. */
  35. /**
  36. * Called when a mousedown occurs in this container. Looks in
  37. * {@link Ext.dd.Registry} for a valid target to drag based on the
  38. * mouse down. Override this method to provide your own lookup logic
  39. * (e.g. finding a child by class name). Make sure your returned
  40. * object has a "ddel" attribute (with an HTML Element) for other
  41. * functions to work.
  42. *
  43. * @param {EventObject}
  44. * e The mouse down event
  45. * @return {Object} The dragData
  46. */
  47. getDragData : function(e) {
  48. return Ext.dd.Registry.getHandleFromEvent(e);
  49. },
  50. /**
  51. * Called once drag threshold has been reached to initialize the
  52. * proxy element. By default, it clones the this.dragData.ddel
  53. *
  54. * @param {Number}
  55. * x The x position of the click on the dragged object
  56. * @param {Number}
  57. * y The y position of the click on the dragged object
  58. * @return {Boolean} true to continue the drag, false to cancel
  59. */
  60. onInitDrag : function(x, y) {
  61. this.proxy.update(this.dragData.ddel.cloneNode(true));
  62. this.onStartDrag(x, y);
  63. return true;
  64. },
  65. /**
  66. * Called after a repair of an invalid drop. By default, highlights
  67. * this.dragData.ddel
  68. */
  69. afterRepair : function() {
  70. if (Ext.enableFx) {
  71. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor
  72. || "c3daf9");
  73. }
  74. this.dragging = false;
  75. },
  76. /**
  77. * Called before a repair of an invalid drop to get the XY to
  78. * animate to. By default returns the XY of this.dragData.ddel
  79. *
  80. * @param {EventObject}
  81. * e The mouse up event
  82. * @return {Array} The xy location (e.g. [100, 200])
  83. */
  84. getRepairXY : function(e) {
  85. return Ext.Element.fly(this.dragData.ddel).getXY();
  86. }
  87. });