DropZone.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.DropZone
  8. * @extends Ext.dd.DropTarget This class provides a container DD instance that
  9. * proxies for multiple child node targets.<br />
  10. * By default, this class requires that child nodes accepting drop 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.DropZone = function(el, config) {
  19. Ext.dd.DropZone.superclass.constructor.call(this, el, config);
  20. };
  21. Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {
  22. /**
  23. * Returns a custom data object associated with the DOM node that is
  24. * the target of the event. By default this looks up the event
  25. * target in the {@link Ext.dd.Registry}, although you can override
  26. * this method to provide your own custom lookup.
  27. *
  28. * @param {Event}
  29. * e The event
  30. * @return {Object} data The custom data
  31. */
  32. getTargetFromEvent : function(e) {
  33. return Ext.dd.Registry.getTargetFromEvent(e);
  34. },
  35. /**
  36. * Called internally when the DropZone determines that a
  37. * {@link Ext.dd.DragSource} has entered a drop node that it has
  38. * registered. This method has no default implementation and should
  39. * be overridden to provide node-specific processing if necessary.
  40. *
  41. * @param {Object}
  42. * nodeData The custom data associated with the drop node
  43. * (this is the same value returned from
  44. * {@link #getTargetFromEvent} for this node)
  45. * @param {Ext.dd.DragSource}
  46. * source The drag source that was dragged over this drop
  47. * zone
  48. * @param {Event}
  49. * e The event
  50. * @param {Object}
  51. * data An object containing arbitrary data supplied by
  52. * the drag source
  53. */
  54. onNodeEnter : function(n, dd, e, data) {
  55. },
  56. /**
  57. * Called internally while the DropZone determines that a
  58. * {@link Ext.dd.DragSource} is over a drop node that it has
  59. * registered. The default implementation returns
  60. * this.dropNotAllowed, so it should be overridden to provide the
  61. * proper feedback.
  62. *
  63. * @param {Object}
  64. * nodeData The custom data associated with the drop node
  65. * (this is the same value returned from
  66. * {@link #getTargetFromEvent} for this node)
  67. * @param {Ext.dd.DragSource}
  68. * source The drag source that was dragged over this drop
  69. * zone
  70. * @param {Event}
  71. * e The event
  72. * @param {Object}
  73. * data An object containing arbitrary data supplied by
  74. * the drag source
  75. * @return {String} status The CSS class that communicates the drop
  76. * status back to the source so that the underlying
  77. * {@link Ext.dd.StatusProxy} can be updated
  78. */
  79. onNodeOver : function(n, dd, e, data) {
  80. return this.dropAllowed;
  81. },
  82. /**
  83. * Called internally when the DropZone determines that a
  84. * {@link Ext.dd.DragSource} has been dragged out of the drop node
  85. * without dropping. This method has no default implementation and
  86. * should be overridden to provide node-specific processing if
  87. * necessary.
  88. *
  89. * @param {Object}
  90. * nodeData The custom data associated with the drop node
  91. * (this is the same value returned from
  92. * {@link #getTargetFromEvent} for this node)
  93. * @param {Ext.dd.DragSource}
  94. * source The drag source that was dragged over this drop
  95. * zone
  96. * @param {Event}
  97. * e The event
  98. * @param {Object}
  99. * data An object containing arbitrary data supplied by
  100. * the drag source
  101. */
  102. onNodeOut : function(n, dd, e, data) {
  103. },
  104. /**
  105. * Called internally when the DropZone determines that a
  106. * {@link Ext.dd.DragSource} has been dropped onto the drop node.
  107. * The default implementation returns false, so it should be
  108. * overridden to provide the appropriate processing of the drop
  109. * event and return true so that the drag source's repair action
  110. * does not run.
  111. *
  112. * @param {Object}
  113. * nodeData The custom data associated with the drop node
  114. * (this is the same value returned from
  115. * {@link #getTargetFromEvent} for this node)
  116. * @param {Ext.dd.DragSource}
  117. * source The drag source that was dragged over this drop
  118. * zone
  119. * @param {Event}
  120. * e The event
  121. * @param {Object}
  122. * data An object containing arbitrary data supplied by
  123. * the drag source
  124. * @return {Boolean} True if the drop was valid, else false
  125. */
  126. onNodeDrop : function(n, dd, e, data) {
  127. return false;
  128. },
  129. /**
  130. * Called internally while the DropZone determines that a
  131. * {@link Ext.dd.DragSource} is being dragged over it, but not over
  132. * any of its registered drop nodes. The default implementation
  133. * returns this.dropNotAllowed, so it should be overridden to
  134. * provide the proper feedback if necessary.
  135. *
  136. * @param {Ext.dd.DragSource}
  137. * source The drag source that was dragged over this drop
  138. * zone
  139. * @param {Event}
  140. * e The event
  141. * @param {Object}
  142. * data An object containing arbitrary data supplied by
  143. * the drag source
  144. * @return {String} status The CSS class that communicates the drop
  145. * status back to the source so that the underlying
  146. * {@link Ext.dd.StatusProxy} can be updated
  147. */
  148. onContainerOver : function(dd, e, data) {
  149. return this.dropNotAllowed;
  150. },
  151. /**
  152. * Called internally when the DropZone determines that a
  153. * {@link Ext.dd.DragSource} has been dropped on it, but not on any
  154. * of its registered drop nodes. The default implementation returns
  155. * false, so it should be overridden to provide the appropriate
  156. * processing of the drop event if you need the drop zone itself to
  157. * be able to accept drops. It should return true when valid so that
  158. * the drag source's repair action does not run.
  159. *
  160. * @param {Ext.dd.DragSource}
  161. * source The drag source that was dragged over this drop
  162. * zone
  163. * @param {Event}
  164. * e The event
  165. * @param {Object}
  166. * data An object containing arbitrary data supplied by
  167. * the drag source
  168. * @return {Boolean} True if the drop was valid, else false
  169. */
  170. onContainerDrop : function(dd, e, data) {
  171. return false;
  172. },
  173. /**
  174. * The function a {@link Ext.dd.DragSource} calls once to notify
  175. * this drop zone that the source is now over the zone. The default
  176. * implementation returns this.dropNotAllowed and expects that only
  177. * registered drop nodes can process drag drop operations, so if you
  178. * need the drop zone itself to be able to process drops you should
  179. * override this method and provide a custom implementation.
  180. *
  181. * @param {Ext.dd.DragSource}
  182. * source The drag source that was dragged over this drop
  183. * zone
  184. * @param {Event}
  185. * e The event
  186. * @param {Object}
  187. * data An object containing arbitrary data supplied by
  188. * the drag source
  189. * @return {String} status The CSS class that communicates the drop
  190. * status back to the source so that the underlying
  191. * {@link Ext.dd.StatusProxy} can be updated
  192. */
  193. notifyEnter : function(dd, e, data) {
  194. return this.dropNotAllowed;
  195. },
  196. /**
  197. * The function a {@link Ext.dd.DragSource} calls continuously while
  198. * it is being dragged over the drop zone. This method will be
  199. * called on every mouse movement while the drag source is over the
  200. * drop zone. It will call {@link #onNodeOver} while the drag source
  201. * is over a registered node, and will also automatically delegate
  202. * to the appropriate node-specific methods as necessary when the
  203. * drag source enters and exits registered nodes ({@link #onNodeEnter},
  204. * {@link #onNodeOut}). If the drag source is not currently over a
  205. * registered node, it will call {@link #onContainerOver}.
  206. *
  207. * @param {Ext.dd.DragSource}
  208. * source The drag source that was dragged over this drop
  209. * zone
  210. * @param {Event}
  211. * e The event
  212. * @param {Object}
  213. * data An object containing arbitrary data supplied by
  214. * the drag source
  215. * @return {String} status The CSS class that communicates the drop
  216. * status back to the source so that the underlying
  217. * {@link Ext.dd.StatusProxy} can be updated
  218. */
  219. notifyOver : function(dd, e, data) {
  220. var n = this.getTargetFromEvent(e);
  221. if (!n) { // not over valid drop target
  222. if (this.lastOverNode) {
  223. this.onNodeOut(this.lastOverNode, dd, e, data);
  224. this.lastOverNode = null;
  225. }
  226. return this.onContainerOver(dd, e, data);
  227. }
  228. if (this.lastOverNode != n) {
  229. if (this.lastOverNode) {
  230. this.onNodeOut(this.lastOverNode, dd, e, data);
  231. }
  232. this.onNodeEnter(n, dd, e, data);
  233. this.lastOverNode = n;
  234. }
  235. return this.onNodeOver(n, dd, e, data);
  236. },
  237. /**
  238. * The function a {@link Ext.dd.DragSource} calls once to notify
  239. * this drop zone that the source has been dragged out of the zone
  240. * without dropping. If the drag source is currently over a
  241. * registered node, the notification will be delegated to
  242. * {@link #onNodeOut} for node-specific handling, otherwise it will
  243. * be ignored.
  244. *
  245. * @param {Ext.dd.DragSource}
  246. * source The drag source that was dragged over this drop
  247. * target
  248. * @param {Event}
  249. * e The event
  250. * @param {Object}
  251. * data An object containing arbitrary data supplied by
  252. * the drag zone
  253. */
  254. notifyOut : function(dd, e, data) {
  255. if (this.lastOverNode) {
  256. this.onNodeOut(this.lastOverNode, dd, e, data);
  257. this.lastOverNode = null;
  258. }
  259. },
  260. /**
  261. * The function a {@link Ext.dd.DragSource} calls once to notify
  262. * this drop zone that the dragged item has been dropped on it. The
  263. * drag zone will look up the target node based on the event passed
  264. * in, and if there is a node registered for that event, it will
  265. * delegate to {@link #onNodeDrop} for node-specific handling,
  266. * otherwise it will call {@link #onContainerDrop}.
  267. *
  268. * @param {Ext.dd.DragSource}
  269. * source The drag source that was dragged over this drop
  270. * zone
  271. * @param {Event}
  272. * e The event
  273. * @param {Object}
  274. * data An object containing arbitrary data supplied by
  275. * the drag source
  276. * @return {Boolean} True if the drop was valid, else false
  277. */
  278. notifyDrop : function(dd, e, data) {
  279. if (this.lastOverNode) {
  280. this.onNodeOut(this.lastOverNode, dd, e, data);
  281. this.lastOverNode = null;
  282. }
  283. var n = this.getTargetFromEvent(e);
  284. return n ? this.onNodeDrop(n, dd, e, data) : this
  285. .onContainerDrop(dd, e, data);
  286. },
  287. // private
  288. triggerCacheRefresh : function() {
  289. Ext.dd.DDM.refreshCache(this.groups);
  290. }
  291. });