DragZone.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-dd-DragZone'>/**
  19. </span> * This class provides a container DD instance that allows dragging of multiple child source nodes.
  20. *
  21. * This class does not move the drag target nodes, but a proxy element which may contain any DOM structure you wish. The
  22. * DOM element to show in the proxy is provided by either a provided implementation of {@link #getDragData}, or by
  23. * registered draggables registered with {@link Ext.dd.Registry}
  24. *
  25. * If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some application
  26. * object (For example nodes in a {@link Ext.view.View DataView}) then use of this class is the most efficient way to
  27. * &quot;activate&quot; those nodes.
  28. *
  29. * By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}. However a
  30. * simpler way to allow a DragZone to manage any number of draggable elements is to configure the DragZone with an
  31. * implementation of the {@link #getDragData} method which interrogates the passed mouse event to see if it has taken
  32. * place within an element, or class of elements. This is easily done by using the event's {@link
  33. * Ext.EventObject#getTarget getTarget} method to identify a node based on a {@link Ext.DomQuery} selector. For example,
  34. * to make the nodes of a DataView draggable, use the following technique. Knowledge of the use of the DataView is
  35. * required:
  36. *
  37. * myDataView.on('render', function(v) {
  38. * myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
  39. *
  40. * // On receipt of a mousedown event, see if it is within a DataView node.
  41. * // Return a drag data object if so.
  42. * getDragData: function(e) {
  43. *
  44. * // Use the DataView's own itemSelector (a mandatory property) to
  45. * // test if the mousedown is within one of the DataView's nodes.
  46. * var sourceEl = e.getTarget(v.itemSelector, 10);
  47. *
  48. * // If the mousedown is within a DataView node, clone the node to produce
  49. * // a ddel element for use by the drag proxy. Also add application data
  50. * // to the returned data object.
  51. * if (sourceEl) {
  52. * d = sourceEl.cloneNode(true);
  53. * d.id = Ext.id();
  54. * return {
  55. * ddel: d,
  56. * sourceEl: sourceEl,
  57. * repairXY: Ext.fly(sourceEl).getXY(),
  58. * sourceStore: v.store,
  59. * draggedRecord: v.{@link Ext.view.View#getRecord getRecord}(sourceEl)
  60. * }
  61. * }
  62. * },
  63. *
  64. * // Provide coordinates for the proxy to slide back to on failed drag.
  65. * // This is the original XY coordinates of the draggable element captured
  66. * // in the getDragData method.
  67. * getRepairXY: function() {
  68. * return this.dragData.repairXY;
  69. * }
  70. * });
  71. * });
  72. *
  73. * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which cooperates with
  74. * this DragZone.
  75. */
  76. Ext.define('Ext.dd.DragZone', {
  77. extend: 'Ext.dd.DragSource',
  78. <span id='Ext-dd-DragZone-method-constructor'> /**
  79. </span> * Creates new DragZone.
  80. * @param {String/HTMLElement/Ext.Element} el The container element or ID of it.
  81. * @param {Object} config
  82. */
  83. constructor : function(el, config){
  84. this.callParent([el, config]);
  85. if (this.containerScroll) {
  86. Ext.dd.ScrollManager.register(this.el);
  87. }
  88. },
  89. <span id='Ext-dd-DragZone-property-dragData'> /**
  90. </span> * @property {Object} dragData
  91. * This property contains the data representing the dragged object. This data is set up by the implementation of the
  92. * {@link #getDragData} method. It must contain a ddel property, but can contain any other data according to the
  93. * application's needs.
  94. */
  95. <span id='Ext-dd-DragZone-cfg-containerScroll'> /**
  96. </span> * @cfg {Boolean} containerScroll
  97. * True to register this container with the Scrollmanager for auto scrolling during drag operations.
  98. */
  99. <span id='Ext-dd-DragZone-method-getDragData'> /**
  100. </span> * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry} for a valid target to drag
  101. * based on the mouse down. Override this method to provide your own lookup logic (e.g. finding a child by class
  102. * name). Make sure your returned object has a &quot;ddel&quot; attribute (with an HTML Element) for other functions to work.
  103. * @param {Event} e The mouse down event
  104. * @return {Object} The dragData
  105. */
  106. getDragData : function(e){
  107. return Ext.dd.Registry.getHandleFromEvent(e);
  108. },
  109. <span id='Ext-dd-DragZone-method-onInitDrag'> /**
  110. </span> * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
  111. * this.dragData.ddel
  112. * @param {Number} x The x position of the click on the dragged object
  113. * @param {Number} y The y position of the click on the dragged object
  114. * @return {Boolean} true to continue the drag, false to cancel
  115. * @template
  116. */
  117. onInitDrag : function(x, y){
  118. this.proxy.update(this.dragData.ddel.cloneNode(true));
  119. this.onStartDrag(x, y);
  120. return true;
  121. },
  122. <span id='Ext-dd-DragZone-method-afterRepair'> /**
  123. </span> * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
  124. * @template
  125. */
  126. afterRepair : function(){
  127. var me = this;
  128. if (Ext.enableFx) {
  129. Ext.fly(me.dragData.ddel).highlight(me.repairHighlightColor);
  130. }
  131. me.dragging = false;
  132. },
  133. <span id='Ext-dd-DragZone-method-getRepairXY'> /**
  134. </span> * Called before a repair of an invalid drop to get the XY to animate to. By default returns the XY of
  135. * this.dragData.ddel
  136. * @param {Event} e The mouse up event
  137. * @return {Number[]} The xy location (e.g. `[100, 200]`)
  138. * @template
  139. */
  140. getRepairXY : function(e){
  141. return Ext.fly(this.dragData.ddel).getXY();
  142. },
  143. destroy : function(){
  144. this.callParent();
  145. if (this.containerScroll) {
  146. Ext.dd.ScrollManager.unregister(this.el);
  147. }
  148. }
  149. });
  150. </pre>
  151. </body>
  152. </html>