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.

383 lines
14 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-DragSource-method-constructor'><span id='Ext-dd-DragSource'>/**
  19. </span></span> * @class Ext.dd.DragSource
  20. * @extends Ext.dd.DDProxy
  21. * A simple class that provides the basic implementation needed to make any element draggable.
  22. * @constructor
  23. * @param {Mixed} el The container element
  24. * @param {Object} config
  25. */
  26. Ext.dd.DragSource = function(el, config){
  27. this.el = Ext.get(el);
  28. if(!this.dragData){
  29. this.dragData = {};
  30. }
  31. Ext.apply(this, config);
  32. if(!this.proxy){
  33. this.proxy = new Ext.dd.StatusProxy();
  34. }
  35. Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
  36. {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
  37. this.dragging = false;
  38. };
  39. Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
  40. <span id='Ext-dd-DragSource-cfg-ddGroup'> /**
  41. </span> * @cfg {String} ddGroup
  42. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  43. * interact with other drag drop objects in the same group (defaults to undefined).
  44. */
  45. <span id='Ext-dd-DragSource-cfg-dropAllowed'> /**
  46. </span> * @cfg {String} dropAllowed
  47. * The CSS class returned to the drag source when drop is allowed (defaults to &quot;x-dd-drop-ok&quot;).
  48. */
  49. dropAllowed : &quot;x-dd-drop-ok&quot;,
  50. <span id='Ext-dd-DragSource-cfg-dropNotAllowed'> /**
  51. </span> * @cfg {String} dropNotAllowed
  52. * The CSS class returned to the drag source when drop is not allowed (defaults to &quot;x-dd-drop-nodrop&quot;).
  53. */
  54. dropNotAllowed : &quot;x-dd-drop-nodrop&quot;,
  55. <span id='Ext-dd-DragSource-method-getDragData'> /**
  56. </span> * Returns the data object associated with this drag source
  57. * @return {Object} data An object containing arbitrary data
  58. */
  59. getDragData : function(e){
  60. return this.dragData;
  61. },
  62. // private
  63. onDragEnter : function(e, id){
  64. var target = Ext.dd.DragDropMgr.getDDById(id);
  65. this.cachedTarget = target;
  66. if(this.beforeDragEnter(target, e, id) !== false){
  67. if(target.isNotifyTarget){
  68. var status = target.notifyEnter(this, e, this.dragData);
  69. this.proxy.setStatus(status);
  70. }else{
  71. this.proxy.setStatus(this.dropAllowed);
  72. }
  73. if(this.afterDragEnter){
  74. <span id='Ext-dd-DragSource-method-afterDragEnter'> /**
  75. </span> * An empty function by default, but provided so that you can perform a custom action
  76. * when the dragged item enters the drop target by providing an implementation.
  77. * @param {Ext.dd.DragDrop} target The drop target
  78. * @param {Event} e The event object
  79. * @param {String} id The id of the dragged element
  80. * @method afterDragEnter
  81. */
  82. this.afterDragEnter(target, e, id);
  83. }
  84. }
  85. },
  86. <span id='Ext-dd-DragSource-method-beforeDragEnter'> /**
  87. </span> * An empty function by default, but provided so that you can perform a custom action
  88. * before the dragged item enters the drop target and optionally cancel the onDragEnter.
  89. * @param {Ext.dd.DragDrop} target The drop target
  90. * @param {Event} e The event object
  91. * @param {String} id The id of the dragged element
  92. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  93. */
  94. beforeDragEnter : function(target, e, id){
  95. return true;
  96. },
  97. // private
  98. alignElWithMouse: function() {
  99. Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
  100. this.proxy.sync();
  101. },
  102. // private
  103. onDragOver : function(e, id){
  104. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  105. if(this.beforeDragOver(target, e, id) !== false){
  106. if(target.isNotifyTarget){
  107. var status = target.notifyOver(this, e, this.dragData);
  108. this.proxy.setStatus(status);
  109. }
  110. if(this.afterDragOver){
  111. <span id='Ext-dd-DragSource-method-afterDragOver'> /**
  112. </span> * An empty function by default, but provided so that you can perform a custom action
  113. * while the dragged item is over the drop target by providing an implementation.
  114. * @param {Ext.dd.DragDrop} target The drop target
  115. * @param {Event} e The event object
  116. * @param {String} id The id of the dragged element
  117. * @method afterDragOver
  118. */
  119. this.afterDragOver(target, e, id);
  120. }
  121. }
  122. },
  123. <span id='Ext-dd-DragSource-method-beforeDragOver'> /**
  124. </span> * An empty function by default, but provided so that you can perform a custom action
  125. * while the dragged item is over the drop target and optionally cancel the onDragOver.
  126. * @param {Ext.dd.DragDrop} target The drop target
  127. * @param {Event} e The event object
  128. * @param {String} id The id of the dragged element
  129. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  130. */
  131. beforeDragOver : function(target, e, id){
  132. return true;
  133. },
  134. // private
  135. onDragOut : function(e, id){
  136. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  137. if(this.beforeDragOut(target, e, id) !== false){
  138. if(target.isNotifyTarget){
  139. target.notifyOut(this, e, this.dragData);
  140. }
  141. this.proxy.reset();
  142. if(this.afterDragOut){
  143. <span id='Ext-dd-DragSource-method-afterDragOut'> /**
  144. </span> * An empty function by default, but provided so that you can perform a custom action
  145. * after the dragged item is dragged out of the target without dropping.
  146. * @param {Ext.dd.DragDrop} target The drop target
  147. * @param {Event} e The event object
  148. * @param {String} id The id of the dragged element
  149. * @method afterDragOut
  150. */
  151. this.afterDragOut(target, e, id);
  152. }
  153. }
  154. this.cachedTarget = null;
  155. },
  156. <span id='Ext-dd-DragSource-method-beforeDragOut'> /**
  157. </span> * An empty function by default, but provided so that you can perform a custom action before the dragged
  158. * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
  159. * @param {Ext.dd.DragDrop} target The drop target
  160. * @param {Event} e The event object
  161. * @param {String} id The id of the dragged element
  162. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  163. */
  164. beforeDragOut : function(target, e, id){
  165. return true;
  166. },
  167. // private
  168. onDragDrop : function(e, id){
  169. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  170. if(this.beforeDragDrop(target, e, id) !== false){
  171. if(target.isNotifyTarget){
  172. if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
  173. this.onValidDrop(target, e, id);
  174. }else{
  175. this.onInvalidDrop(target, e, id);
  176. }
  177. }else{
  178. this.onValidDrop(target, e, id);
  179. }
  180. if(this.afterDragDrop){
  181. <span id='Ext-dd-DragSource-method-afterDragDrop'> /**
  182. </span> * An empty function by default, but provided so that you can perform a custom action
  183. * after a valid drag drop has occurred by providing an implementation.
  184. * @param {Ext.dd.DragDrop} target The drop target
  185. * @param {Event} e The event object
  186. * @param {String} id The id of the dropped element
  187. * @method afterDragDrop
  188. */
  189. this.afterDragDrop(target, e, id);
  190. }
  191. }
  192. delete this.cachedTarget;
  193. },
  194. <span id='Ext-dd-DragSource-method-beforeDragDrop'> /**
  195. </span> * An empty function by default, but provided so that you can perform a custom action before the dragged
  196. * item is dropped onto the target and optionally cancel the onDragDrop.
  197. * @param {Ext.dd.DragDrop} target The drop target
  198. * @param {Event} e The event object
  199. * @param {String} id The id of the dragged element
  200. * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
  201. */
  202. beforeDragDrop : function(target, e, id){
  203. return true;
  204. },
  205. // private
  206. onValidDrop : function(target, e, id){
  207. this.hideProxy();
  208. if(this.afterValidDrop){
  209. <span id='Ext-dd-DragSource-method-afterValidDrop'> /**
  210. </span> * An empty function by default, but provided so that you can perform a custom action
  211. * after a valid drop has occurred by providing an implementation.
  212. * @param {Object} target The target DD
  213. * @param {Event} e The event object
  214. * @param {String} id The id of the dropped element
  215. * @method afterValidDrop
  216. */
  217. this.afterValidDrop(target, e, id);
  218. }
  219. },
  220. // private
  221. getRepairXY : function(e, data){
  222. return this.el.getXY();
  223. },
  224. // private
  225. onInvalidDrop : function(target, e, id){
  226. this.beforeInvalidDrop(target, e, id);
  227. if(this.cachedTarget){
  228. if(this.cachedTarget.isNotifyTarget){
  229. this.cachedTarget.notifyOut(this, e, this.dragData);
  230. }
  231. this.cacheTarget = null;
  232. }
  233. this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
  234. if(this.afterInvalidDrop){
  235. <span id='Ext-dd-DragSource-method-afterInvalidDrop'> /**
  236. </span> * An empty function by default, but provided so that you can perform a custom action
  237. * after an invalid drop has occurred by providing an implementation.
  238. * @param {Event} e The event object
  239. * @param {String} id The id of the dropped element
  240. * @method afterInvalidDrop
  241. */
  242. this.afterInvalidDrop(e, id);
  243. }
  244. },
  245. // private
  246. afterRepair : function(){
  247. if(Ext.enableFx){
  248. this.el.highlight(this.hlColor || &quot;c3daf9&quot;);
  249. }
  250. this.dragging = false;
  251. },
  252. <span id='Ext-dd-DragSource-method-beforeInvalidDrop'> /**
  253. </span> * An empty function by default, but provided so that you can perform a custom action after an invalid
  254. * drop has occurred.
  255. * @param {Ext.dd.DragDrop} target The drop target
  256. * @param {Event} e The event object
  257. * @param {String} id The id of the dragged element
  258. * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
  259. */
  260. beforeInvalidDrop : function(target, e, id){
  261. return true;
  262. },
  263. // private
  264. handleMouseDown : function(e){
  265. if(this.dragging) {
  266. return;
  267. }
  268. var data = this.getDragData(e);
  269. if(data &amp;&amp; this.onBeforeDrag(data, e) !== false){
  270. this.dragData = data;
  271. this.proxy.stop();
  272. Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
  273. }
  274. },
  275. <span id='Ext-dd-DragSource-method-onBeforeDrag'> /**
  276. </span> * An empty function by default, but provided so that you can perform a custom action before the initial
  277. * drag event begins and optionally cancel it.
  278. * @param {Object} data An object containing arbitrary data to be shared with drop targets
  279. * @param {Event} e The event object
  280. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  281. */
  282. onBeforeDrag : function(data, e){
  283. return true;
  284. },
  285. <span id='Ext-dd-DragSource-method-onStartDrag'> /**
  286. </span> * An empty function by default, but provided so that you can perform a custom action once the initial
  287. * drag event has begun. The drag cannot be canceled from this function.
  288. * @param {Number} x The x position of the click on the dragged object
  289. * @param {Number} y The y position of the click on the dragged object
  290. */
  291. onStartDrag : Ext.emptyFn,
  292. // private override
  293. startDrag : function(x, y){
  294. this.proxy.reset();
  295. this.dragging = true;
  296. this.proxy.update(&quot;&quot;);
  297. this.onInitDrag(x, y);
  298. this.proxy.show();
  299. },
  300. // private
  301. onInitDrag : function(x, y){
  302. var clone = this.el.dom.cloneNode(true);
  303. clone.id = Ext.id(); // prevent duplicate ids
  304. this.proxy.update(clone);
  305. this.onStartDrag(x, y);
  306. return true;
  307. },
  308. <span id='Ext-dd-DragSource-method-getProxy'> /**
  309. </span> * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
  310. * @return {Ext.dd.StatusProxy} proxy The StatusProxy
  311. */
  312. getProxy : function(){
  313. return this.proxy;
  314. },
  315. <span id='Ext-dd-DragSource-method-hideProxy'> /**
  316. </span> * Hides the drag source's {@link Ext.dd.StatusProxy}
  317. */
  318. hideProxy : function(){
  319. this.proxy.hide();
  320. this.proxy.reset(true);
  321. this.dragging = false;
  322. },
  323. // private
  324. triggerCacheRefresh : function(){
  325. Ext.dd.DDM.refreshCache(this.groups);
  326. },
  327. // private - override to prevent hiding
  328. b4EndDrag: function(e) {
  329. },
  330. // private - override to prevent moving
  331. endDrag : function(e){
  332. this.onEndDrag(this.dragData, e);
  333. },
  334. // private
  335. onEndDrag : function(data, e){
  336. },
  337. // private - pin to cursor
  338. autoOffset : function(x, y) {
  339. this.setDelta(-12, -20);
  340. },
  341. destroy: function(){
  342. Ext.dd.DragSource.superclass.destroy.call(this);
  343. Ext.destroy(this.proxy);
  344. }
  345. });</pre>
  346. </body>
  347. </html>