You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
7.1 KiB

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