/hippo/src/main/webapp/ext/src/dd/DragZone.js

http://hdbc.googlecode.com/ · JavaScript · 133 lines · 25 code · 5 blank · 103 comment · 3 complexity · dc6d95a9920df69061e09dbb089a1806 MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.dd.DragZone
  9. * @extends Ext.dd.DragSource
  10. * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
  11. * <p>This class does not move the drag target nodes, but a proxy element which may contain
  12. * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
  13. * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
  14. * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
  15. * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
  16. * is the most efficient way to "activate" those nodes.</p>
  17. * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
  18. * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
  19. * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
  20. * mouse event to see if it has taken place within an element, or class of elements. This is easily done
  21. * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
  22. * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
  23. * technique. Knowledge of the use of the DataView is required:</p><pre><code>
  24. myDataView.on('render', function() {
  25. myDataView.dragZone = new Ext.dd.DragZone(myDataView.getEl(), {
  26. // On receipt of a mousedown event, see if it is within a DataView node.
  27. // Return a drag data object if so.
  28. getDragData: function(e) {
  29. // Use the DataView's own itemSelector (a mandatory property) to
  30. // test if the mousedown is within one of the DataView's nodes.
  31. var sourceEl = e.getTarget(myDataView.itemSelector, 10);
  32. // If the mousedown is within a DataView node, clone the node to produce
  33. // a ddel element for use by the drag proxy. Also add application data
  34. // to the returned data object.
  35. if (sourceEl) {
  36. d = sourceEl.cloneNode(true);
  37. d.id = Ext.id();
  38. return {
  39. ddel: d,
  40. sourceEl: sourceEl,
  41. repairXY: Ext.fly(sourceEl).getXY(),
  42. sourceStore: myDataView.store,
  43. draggedRecord: v.getRecord(sourceEl)
  44. }
  45. }
  46. },
  47. // Provide coordinates for the proxy to slide back to on failed drag.
  48. // This is the original XY coordinates of the draggable element captured
  49. // in the getDragData method.
  50. getRepairXY: function() {
  51. return this.dragData.repairXY;
  52. }
  53. });
  54. });</code></pre>
  55. * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
  56. * cooperates with this DragZone.
  57. * @constructor
  58. * @param {Mixed} el The container element
  59. * @param {Object} config
  60. */
  61. Ext.dd.DragZone = function(el, config){
  62. Ext.dd.DragZone.superclass.constructor.call(this, el, config);
  63. if(this.containerScroll){
  64. Ext.dd.ScrollManager.register(this.el);
  65. }
  66. };
  67. Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
  68. /**
  69. * This property contains the data representing the dragged object. This data is set up by the implementation
  70. * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
  71. * any other data according to the application's needs.
  72. * @type Object
  73. * @property dragData
  74. */
  75. /**
  76. * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
  77. * for auto scrolling during drag operations.
  78. */
  79. /**
  80. * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
  81. * method after a failed drop (defaults to "c3daf9" - light blue)
  82. */
  83. /**
  84. * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
  85. * for a valid target to drag based on the mouse down. Override this method
  86. * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
  87. * object has a "ddel" attribute (with an HTML Element) for other functions to work.
  88. * @param {EventObject} e The mouse down event
  89. * @return {Object} The dragData
  90. */
  91. getDragData : function(e){
  92. return Ext.dd.Registry.getHandleFromEvent(e);
  93. },
  94. /**
  95. * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
  96. * this.dragData.ddel
  97. * @param {Number} x The x position of the click on the dragged object
  98. * @param {Number} y The y position of the click on the dragged object
  99. * @return {Boolean} true to continue the drag, false to cancel
  100. */
  101. onInitDrag : function(x, y){
  102. this.proxy.update(this.dragData.ddel.cloneNode(true));
  103. this.onStartDrag(x, y);
  104. return true;
  105. },
  106. /**
  107. * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
  108. */
  109. afterRepair : function(){
  110. if(Ext.enableFx){
  111. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
  112. }
  113. this.dragging = false;
  114. },
  115. /**
  116. * Called before a repair of an invalid drop to get the XY to animate to. By default returns
  117. * the XY of this.dragData.ddel
  118. * @param {EventObject} e The mouse up event
  119. * @return {Array} The xy location (e.g. [100, 200])
  120. */
  121. getRepairXY : function(e){
  122. return Ext.Element.fly(this.dragData.ddel).getXY();
  123. }
  124. });