1 | /*! |
---|
2 | * Ext JS Library 3.4.0 |
---|
3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
4 | * licensing@sencha.com |
---|
5 | * http://www.sencha.com/license |
---|
6 | */ |
---|
7 | /* |
---|
8 | * These classes are derivatives of the similarly named classes in the YUI Library. |
---|
9 | * The original license: |
---|
10 | * Copyright (c) 2006, Yahoo! Inc. All rights reserved. |
---|
11 | * Code licensed under the BSD License: |
---|
12 | * http://developer.yahoo.net/yui/license.txt |
---|
13 | */ |
---|
14 | |
---|
15 | (function() { |
---|
16 | |
---|
17 | var Event=Ext.EventManager; |
---|
18 | var Dom=Ext.lib.Dom; |
---|
19 | |
---|
20 | /** |
---|
21 | * @class Ext.dd.DragDrop |
---|
22 | * Defines the interface and base operation of items that that can be |
---|
23 | * dragged or can be drop targets. It was designed to be extended, overriding |
---|
24 | * the event handlers for startDrag, onDrag, onDragOver and onDragOut. |
---|
25 | * Up to three html elements can be associated with a DragDrop instance: |
---|
26 | * <ul> |
---|
27 | * <li>linked element: the element that is passed into the constructor. |
---|
28 | * This is the element which defines the boundaries for interaction with |
---|
29 | * other DragDrop objects.</li> |
---|
30 | * <li>handle element(s): The drag operation only occurs if the element that |
---|
31 | * was clicked matches a handle element. By default this is the linked |
---|
32 | * element, but there are times that you will want only a portion of the |
---|
33 | * linked element to initiate the drag operation, and the setHandleElId() |
---|
34 | * method provides a way to define this.</li> |
---|
35 | * <li>drag element: this represents the element that would be moved along |
---|
36 | * with the cursor during a drag operation. By default, this is the linked |
---|
37 | * element itself as in {@link Ext.dd.DD}. setDragElId() lets you define |
---|
38 | * a separate element that would be moved, as in {@link Ext.dd.DDProxy}. |
---|
39 | * </li> |
---|
40 | * </ul> |
---|
41 | * This class should not be instantiated until the onload event to ensure that |
---|
42 | * the associated elements are available. |
---|
43 | * The following would define a DragDrop obj that would interact with any |
---|
44 | * other DragDrop obj in the "group1" group: |
---|
45 | * <pre> |
---|
46 | * dd = new Ext.dd.DragDrop("div1", "group1"); |
---|
47 | * </pre> |
---|
48 | * Since none of the event handlers have been implemented, nothing would |
---|
49 | * actually happen if you were to run the code above. Normally you would |
---|
50 | * override this class or one of the default implementations, but you can |
---|
51 | * also override the methods you want on an instance of the class... |
---|
52 | * <pre> |
---|
53 | * dd.onDragDrop = function(e, id) { |
---|
54 | * alert("dd was dropped on " + id); |
---|
55 | * } |
---|
56 | * </pre> |
---|
57 | * @constructor |
---|
58 | * @param {String} id of the element that is linked to this instance |
---|
59 | * @param {String} sGroup the group of related DragDrop objects |
---|
60 | * @param {object} config an object containing configurable attributes |
---|
61 | * Valid properties for DragDrop: |
---|
62 | * padding, isTarget, maintainOffset, primaryButtonOnly |
---|
63 | */ |
---|
64 | Ext.dd.DragDrop = function(id, sGroup, config) { |
---|
65 | if(id) { |
---|
66 | this.init(id, sGroup, config); |
---|
67 | } |
---|
68 | }; |
---|
69 | |
---|
70 | Ext.dd.DragDrop.prototype = { |
---|
71 | |
---|
72 | /** |
---|
73 | * Set to false to enable a DragDrop object to fire drag events while dragging |
---|
74 | * over its own Element. Defaults to true - DragDrop objects do not by default |
---|
75 | * fire drag events to themselves. |
---|
76 | * @property ignoreSelf |
---|
77 | * @type Boolean |
---|
78 | */ |
---|
79 | |
---|
80 | /** |
---|
81 | * The id of the element associated with this object. This is what we |
---|
82 | * refer to as the "linked element" because the size and position of |
---|
83 | * this element is used to determine when the drag and drop objects have |
---|
84 | * interacted. |
---|
85 | * @property id |
---|
86 | * @type String |
---|
87 | */ |
---|
88 | id: null, |
---|
89 | |
---|
90 | /** |
---|
91 | * Configuration attributes passed into the constructor |
---|
92 | * @property config |
---|
93 | * @type object |
---|
94 | */ |
---|
95 | config: null, |
---|
96 | |
---|
97 | /** |
---|
98 | * The id of the element that will be dragged. By default this is same |
---|
99 | * as the linked element, but could be changed to another element. Ex: |
---|
100 | * Ext.dd.DDProxy |
---|
101 | * @property dragElId |
---|
102 | * @type String |
---|
103 | * @private |
---|
104 | */ |
---|
105 | dragElId: null, |
---|
106 | |
---|
107 | /** |
---|
108 | * The ID of the element that initiates the drag operation. By default |
---|
109 | * this is the linked element, but could be changed to be a child of this |
---|
110 | * element. This lets us do things like only starting the drag when the |
---|
111 | * header element within the linked html element is clicked. |
---|
112 | * @property handleElId |
---|
113 | * @type String |
---|
114 | * @private |
---|
115 | */ |
---|
116 | handleElId: null, |
---|
117 | |
---|
118 | /** |
---|
119 | * An object who's property names identify HTML tags to be considered invalid as drag handles. |
---|
120 | * A non-null property value identifies the tag as invalid. Defaults to the |
---|
121 | * following value which prevents drag operations from being initiated by <a> elements:<pre><code> |
---|
122 | { |
---|
123 | A: "A" |
---|
124 | }</code></pre> |
---|
125 | * @property invalidHandleTypes |
---|
126 | * @type Object |
---|
127 | */ |
---|
128 | invalidHandleTypes: null, |
---|
129 | |
---|
130 | /** |
---|
131 | * An object who's property names identify the IDs of elements to be considered invalid as drag handles. |
---|
132 | * A non-null property value identifies the ID as invalid. For example, to prevent |
---|
133 | * dragging from being initiated on element ID "foo", use:<pre><code> |
---|
134 | { |
---|
135 | foo: true |
---|
136 | }</code></pre> |
---|
137 | * @property invalidHandleIds |
---|
138 | * @type Object |
---|
139 | */ |
---|
140 | invalidHandleIds: null, |
---|
141 | |
---|
142 | /** |
---|
143 | * An Array of CSS class names for elements to be considered in valid as drag handles. |
---|
144 | * @property invalidHandleClasses |
---|
145 | * @type Array |
---|
146 | */ |
---|
147 | invalidHandleClasses: null, |
---|
148 | |
---|
149 | /** |
---|
150 | * The linked element's absolute X position at the time the drag was |
---|
151 | * started |
---|
152 | * @property startPageX |
---|
153 | * @type int |
---|
154 | * @private |
---|
155 | */ |
---|
156 | startPageX: 0, |
---|
157 | |
---|
158 | /** |
---|
159 | * The linked element's absolute X position at the time the drag was |
---|
160 | * started |
---|
161 | * @property startPageY |
---|
162 | * @type int |
---|
163 | * @private |
---|
164 | */ |
---|
165 | startPageY: 0, |
---|
166 | |
---|
167 | /** |
---|
168 | * The group defines a logical collection of DragDrop objects that are |
---|
169 | * related. Instances only get events when interacting with other |
---|
170 | * DragDrop object in the same group. This lets us define multiple |
---|
171 | * groups using a single DragDrop subclass if we want. |
---|
172 | * @property groups |
---|
173 | * @type object An object in the format {'group1':true, 'group2':true} |
---|
174 | */ |
---|
175 | groups: null, |
---|
176 | |
---|
177 | /** |
---|
178 | * Individual drag/drop instances can be locked. This will prevent |
---|
179 | * onmousedown start drag. |
---|
180 | * @property locked |
---|
181 | * @type boolean |
---|
182 | * @private |
---|
183 | */ |
---|
184 | locked: false, |
---|
185 | |
---|
186 | /** |
---|
187 | * Lock this instance |
---|
188 | * @method lock |
---|
189 | */ |
---|
190 | lock: function() { |
---|
191 | this.locked = true; |
---|
192 | }, |
---|
193 | |
---|
194 | /** |
---|
195 | * When set to true, other DD objects in cooperating DDGroups do not receive |
---|
196 | * notification events when this DD object is dragged over them. Defaults to false. |
---|
197 | * @property moveOnly |
---|
198 | * @type boolean |
---|
199 | */ |
---|
200 | moveOnly: false, |
---|
201 | |
---|
202 | /** |
---|
203 | * Unlock this instace |
---|
204 | * @method unlock |
---|
205 | */ |
---|
206 | unlock: function() { |
---|
207 | this.locked = false; |
---|
208 | }, |
---|
209 | |
---|
210 | /** |
---|
211 | * By default, all instances can be a drop target. This can be disabled by |
---|
212 | * setting isTarget to false. |
---|
213 | * @property isTarget |
---|
214 | * @type boolean |
---|
215 | */ |
---|
216 | isTarget: true, |
---|
217 | |
---|
218 | /** |
---|
219 | * The padding configured for this drag and drop object for calculating |
---|
220 | * the drop zone intersection with this object. |
---|
221 | * @property padding |
---|
222 | * @type int[] An array containing the 4 padding values: [top, right, bottom, left] |
---|
223 | */ |
---|
224 | padding: null, |
---|
225 | |
---|
226 | /** |
---|
227 | * Cached reference to the linked element |
---|
228 | * @property _domRef |
---|
229 | * @private |
---|
230 | */ |
---|
231 | _domRef: null, |
---|
232 | |
---|
233 | /** |
---|
234 | * Internal typeof flag |
---|
235 | * @property __ygDragDrop |
---|
236 | * @private |
---|
237 | */ |
---|
238 | __ygDragDrop: true, |
---|
239 | |
---|
240 | /** |
---|
241 | * Set to true when horizontal contraints are applied |
---|
242 | * @property constrainX |
---|
243 | * @type boolean |
---|
244 | * @private |
---|
245 | */ |
---|
246 | constrainX: false, |
---|
247 | |
---|
248 | /** |
---|
249 | * Set to true when vertical contraints are applied |
---|
250 | * @property constrainY |
---|
251 | * @type boolean |
---|
252 | * @private |
---|
253 | */ |
---|
254 | constrainY: false, |
---|
255 | |
---|
256 | /** |
---|
257 | * The left constraint |
---|
258 | * @property minX |
---|
259 | * @type int |
---|
260 | * @private |
---|
261 | */ |
---|
262 | minX: 0, |
---|
263 | |
---|
264 | /** |
---|
265 | * The right constraint |
---|
266 | * @property maxX |
---|
267 | * @type int |
---|
268 | * @private |
---|
269 | */ |
---|
270 | maxX: 0, |
---|
271 | |
---|
272 | /** |
---|
273 | * The up constraint |
---|
274 | * @property minY |
---|
275 | * @type int |
---|
276 | * @private |
---|
277 | */ |
---|
278 | minY: 0, |
---|
279 | |
---|
280 | /** |
---|
281 | * The down constraint |
---|
282 | * @property maxY |
---|
283 | * @type int |
---|
284 | * @private |
---|
285 | */ |
---|
286 | maxY: 0, |
---|
287 | |
---|
288 | /** |
---|
289 | * Maintain offsets when we resetconstraints. Set to true when you want |
---|
290 | * the position of the element relative to its parent to stay the same |
---|
291 | * when the page changes |
---|
292 | * |
---|
293 | * @property maintainOffset |
---|
294 | * @type boolean |
---|
295 | */ |
---|
296 | maintainOffset: false, |
---|
297 | |
---|
298 | /** |
---|
299 | * Array of pixel locations the element will snap to if we specified a |
---|
300 | * horizontal graduation/interval. This array is generated automatically |
---|
301 | * when you define a tick interval. |
---|
302 | * @property xTicks |
---|
303 | * @type int[] |
---|
304 | */ |
---|
305 | xTicks: null, |
---|
306 | |
---|
307 | /** |
---|
308 | * Array of pixel locations the element will snap to if we specified a |
---|
309 | * vertical graduation/interval. This array is generated automatically |
---|
310 | * when you define a tick interval. |
---|
311 | * @property yTicks |
---|
312 | * @type int[] |
---|
313 | */ |
---|
314 | yTicks: null, |
---|
315 | |
---|
316 | /** |
---|
317 | * By default the drag and drop instance will only respond to the primary |
---|
318 | * button click (left button for a right-handed mouse). Set to true to |
---|
319 | * allow drag and drop to start with any mouse click that is propogated |
---|
320 | * by the browser |
---|
321 | * @property primaryButtonOnly |
---|
322 | * @type boolean |
---|
323 | */ |
---|
324 | primaryButtonOnly: true, |
---|
325 | |
---|
326 | /** |
---|
327 | * The available property is false until the linked dom element is accessible. |
---|
328 | * @property available |
---|
329 | * @type boolean |
---|
330 | */ |
---|
331 | available: false, |
---|
332 | |
---|
333 | /** |
---|
334 | * By default, drags can only be initiated if the mousedown occurs in the |
---|
335 | * region the linked element is. This is done in part to work around a |
---|
336 | * bug in some browsers that mis-report the mousedown if the previous |
---|
337 | * mouseup happened outside of the window. This property is set to true |
---|
338 | * if outer handles are defined. |
---|
339 | * |
---|
340 | * @property hasOuterHandles |
---|
341 | * @type boolean |
---|
342 | * @default false |
---|
343 | */ |
---|
344 | hasOuterHandles: false, |
---|
345 | |
---|
346 | /** |
---|
347 | * Code that executes immediately before the startDrag event |
---|
348 | * @method b4StartDrag |
---|
349 | * @private |
---|
350 | */ |
---|
351 | b4StartDrag: function(x, y) { }, |
---|
352 | |
---|
353 | /** |
---|
354 | * Abstract method called after a drag/drop object is clicked |
---|
355 | * and the drag or mousedown time thresholds have beeen met. |
---|
356 | * @method startDrag |
---|
357 | * @param {int} X click location |
---|
358 | * @param {int} Y click location |
---|
359 | */ |
---|
360 | startDrag: function(x, y) { /* override this */ }, |
---|
361 | |
---|
362 | /** |
---|
363 | * Code that executes immediately before the onDrag event |
---|
364 | * @method b4Drag |
---|
365 | * @private |
---|
366 | */ |
---|
367 | b4Drag: function(e) { }, |
---|
368 | |
---|
369 | /** |
---|
370 | * Abstract method called during the onMouseMove event while dragging an |
---|
371 | * object. |
---|
372 | * @method onDrag |
---|
373 | * @param {Event} e the mousemove event |
---|
374 | */ |
---|
375 | onDrag: function(e) { /* override this */ }, |
---|
376 | |
---|
377 | /** |
---|
378 | * Abstract method called when this element fist begins hovering over |
---|
379 | * another DragDrop obj |
---|
380 | * @method onDragEnter |
---|
381 | * @param {Event} e the mousemove event |
---|
382 | * @param {String|DragDrop[]} id In POINT mode, the element |
---|
383 | * id this is hovering over. In INTERSECT mode, an array of one or more |
---|
384 | * dragdrop items being hovered over. |
---|
385 | */ |
---|
386 | onDragEnter: function(e, id) { /* override this */ }, |
---|
387 | |
---|
388 | /** |
---|
389 | * Code that executes immediately before the onDragOver event |
---|
390 | * @method b4DragOver |
---|
391 | * @private |
---|
392 | */ |
---|
393 | b4DragOver: function(e) { }, |
---|
394 | |
---|
395 | /** |
---|
396 | * Abstract method called when this element is hovering over another |
---|
397 | * DragDrop obj |
---|
398 | * @method onDragOver |
---|
399 | * @param {Event} e the mousemove event |
---|
400 | * @param {String|DragDrop[]} id In POINT mode, the element |
---|
401 | * id this is hovering over. In INTERSECT mode, an array of dd items |
---|
402 | * being hovered over. |
---|
403 | */ |
---|
404 | onDragOver: function(e, id) { /* override this */ }, |
---|
405 | |
---|
406 | /** |
---|
407 | * Code that executes immediately before the onDragOut event |
---|
408 | * @method b4DragOut |
---|
409 | * @private |
---|
410 | */ |
---|
411 | b4DragOut: function(e) { }, |
---|
412 | |
---|
413 | /** |
---|
414 | * Abstract method called when we are no longer hovering over an element |
---|
415 | * @method onDragOut |
---|
416 | * @param {Event} e the mousemove event |
---|
417 | * @param {String|DragDrop[]} id In POINT mode, the element |
---|
418 | * id this was hovering over. In INTERSECT mode, an array of dd items |
---|
419 | * that the mouse is no longer over. |
---|
420 | */ |
---|
421 | onDragOut: function(e, id) { /* override this */ }, |
---|
422 | |
---|
423 | /** |
---|
424 | * Code that executes immediately before the onDragDrop event |
---|
425 | * @method b4DragDrop |
---|
426 | * @private |
---|
427 | */ |
---|
428 | b4DragDrop: function(e) { }, |
---|
429 | |
---|
430 | /** |
---|
431 | * Abstract method called when this item is dropped on another DragDrop |
---|
432 | * obj |
---|
433 | * @method onDragDrop |
---|
434 | * @param {Event} e the mouseup event |
---|
435 | * @param {String|DragDrop[]} id In POINT mode, the element |
---|
436 | * id this was dropped on. In INTERSECT mode, an array of dd items this |
---|
437 | * was dropped on. |
---|
438 | */ |
---|
439 | onDragDrop: function(e, id) { /* override this */ }, |
---|
440 | |
---|
441 | /** |
---|
442 | * Abstract method called when this item is dropped on an area with no |
---|
443 | * drop target |
---|
444 | * @method onInvalidDrop |
---|
445 | * @param {Event} e the mouseup event |
---|
446 | */ |
---|
447 | onInvalidDrop: function(e) { /* override this */ }, |
---|
448 | |
---|
449 | /** |
---|
450 | * Code that executes immediately before the endDrag event |
---|
451 | * @method b4EndDrag |
---|
452 | * @private |
---|
453 | */ |
---|
454 | b4EndDrag: function(e) { }, |
---|
455 | |
---|
456 | /** |
---|
457 | * Fired when we are done dragging the object |
---|
458 | * @method endDrag |
---|
459 | * @param {Event} e the mouseup event |
---|
460 | */ |
---|
461 | endDrag: function(e) { /* override this */ }, |
---|
462 | |
---|
463 | /** |
---|
464 | * Code executed immediately before the onMouseDown event |
---|
465 | * @method b4MouseDown |
---|
466 | * @param {Event} e the mousedown event |
---|
467 | * @private |
---|
468 | */ |
---|
469 | b4MouseDown: function(e) { }, |
---|
470 | |
---|
471 | /** |
---|
472 | * Event handler that fires when a drag/drop obj gets a mousedown |
---|
473 | * @method onMouseDown |
---|
474 | * @param {Event} e the mousedown event |
---|
475 | */ |
---|
476 | onMouseDown: function(e) { /* override this */ }, |
---|
477 | |
---|
478 | /** |
---|
479 | * Event handler that fires when a drag/drop obj gets a mouseup |
---|
480 | * @method onMouseUp |
---|
481 | * @param {Event} e the mouseup event |
---|
482 | */ |
---|
483 | onMouseUp: function(e) { /* override this */ }, |
---|
484 | |
---|
485 | /** |
---|
486 | * Override the onAvailable method to do what is needed after the initial |
---|
487 | * position was determined. |
---|
488 | * @method onAvailable |
---|
489 | */ |
---|
490 | onAvailable: function () { |
---|
491 | }, |
---|
492 | |
---|
493 | /** |
---|
494 | * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}). |
---|
495 | * @type Object |
---|
496 | */ |
---|
497 | defaultPadding : {left:0, right:0, top:0, bottom:0}, |
---|
498 | |
---|
499 | /** |
---|
500 | * Initializes the drag drop object's constraints to restrict movement to a certain element. |
---|
501 | * |
---|
502 | * Usage: |
---|
503 | <pre><code> |
---|
504 | var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest", |
---|
505 | { dragElId: "existingProxyDiv" }); |
---|
506 | dd.startDrag = function(){ |
---|
507 | this.constrainTo("parent-id"); |
---|
508 | }; |
---|
509 | </code></pre> |
---|
510 | * Or you can initalize it using the {@link Ext.Element} object: |
---|
511 | <pre><code> |
---|
512 | Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, { |
---|
513 | startDrag : function(){ |
---|
514 | this.constrainTo("parent-id"); |
---|
515 | } |
---|
516 | }); |
---|
517 | </code></pre> |
---|
518 | * @param {Mixed} constrainTo The element to constrain to. |
---|
519 | * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints, |
---|
520 | * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or |
---|
521 | * an object containing the sides to pad. For example: {right:10, bottom:10} |
---|
522 | * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders) |
---|
523 | */ |
---|
524 | constrainTo : function(constrainTo, pad, inContent){ |
---|
525 | if(Ext.isNumber(pad)){ |
---|
526 | pad = {left: pad, right:pad, top:pad, bottom:pad}; |
---|
527 | } |
---|
528 | pad = pad || this.defaultPadding; |
---|
529 | var b = Ext.get(this.getEl()).getBox(), |
---|
530 | ce = Ext.get(constrainTo), |
---|
531 | s = ce.getScroll(), |
---|
532 | c, |
---|
533 | cd = ce.dom; |
---|
534 | if(cd == document.body){ |
---|
535 | c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()}; |
---|
536 | }else{ |
---|
537 | var xy = ce.getXY(); |
---|
538 | c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight}; |
---|
539 | } |
---|
540 | |
---|
541 | |
---|
542 | var topSpace = b.y - c.y, |
---|
543 | leftSpace = b.x - c.x; |
---|
544 | |
---|
545 | this.resetConstraints(); |
---|
546 | this.setXConstraint(leftSpace - (pad.left||0), // left |
---|
547 | c.width - leftSpace - b.width - (pad.right||0), //right |
---|
548 | this.xTickSize |
---|
549 | ); |
---|
550 | this.setYConstraint(topSpace - (pad.top||0), //top |
---|
551 | c.height - topSpace - b.height - (pad.bottom||0), //bottom |
---|
552 | this.yTickSize |
---|
553 | ); |
---|
554 | }, |
---|
555 | |
---|
556 | /** |
---|
557 | * Returns a reference to the linked element |
---|
558 | * @method getEl |
---|
559 | * @return {HTMLElement} the html element |
---|
560 | */ |
---|
561 | getEl: function() { |
---|
562 | if (!this._domRef) { |
---|
563 | this._domRef = Ext.getDom(this.id); |
---|
564 | } |
---|
565 | |
---|
566 | return this._domRef; |
---|
567 | }, |
---|
568 | |
---|
569 | /** |
---|
570 | * Returns a reference to the actual element to drag. By default this is |
---|
571 | * the same as the html element, but it can be assigned to another |
---|
572 | * element. An example of this can be found in Ext.dd.DDProxy |
---|
573 | * @method getDragEl |
---|
574 | * @return {HTMLElement} the html element |
---|
575 | */ |
---|
576 | getDragEl: function() { |
---|
577 | return Ext.getDom(this.dragElId); |
---|
578 | }, |
---|
579 | |
---|
580 | /** |
---|
581 | * Sets up the DragDrop object. Must be called in the constructor of any |
---|
582 | * Ext.dd.DragDrop subclass |
---|
583 | * @method init |
---|
584 | * @param id the id of the linked element |
---|
585 | * @param {String} sGroup the group of related items |
---|
586 | * @param {object} config configuration attributes |
---|
587 | */ |
---|
588 | init: function(id, sGroup, config) { |
---|
589 | this.initTarget(id, sGroup, config); |
---|
590 | Event.on(this.id, "mousedown", this.handleMouseDown, this); |
---|
591 | // Event.on(this.id, "selectstart", Event.preventDefault); |
---|
592 | }, |
---|
593 | |
---|
594 | /** |
---|
595 | * Initializes Targeting functionality only... the object does not |
---|
596 | * get a mousedown handler. |
---|
597 | * @method initTarget |
---|
598 | * @param id the id of the linked element |
---|
599 | * @param {String} sGroup the group of related items |
---|
600 | * @param {object} config configuration attributes |
---|
601 | */ |
---|
602 | initTarget: function(id, sGroup, config) { |
---|
603 | |
---|
604 | // configuration attributes |
---|
605 | this.config = config || {}; |
---|
606 | |
---|
607 | // create a local reference to the drag and drop manager |
---|
608 | this.DDM = Ext.dd.DDM; |
---|
609 | // initialize the groups array |
---|
610 | this.groups = {}; |
---|
611 | |
---|
612 | // assume that we have an element reference instead of an id if the |
---|
613 | // parameter is not a string |
---|
614 | if (typeof id !== "string") { |
---|
615 | id = Ext.id(id); |
---|
616 | } |
---|
617 | |
---|
618 | // set the id |
---|
619 | this.id = id; |
---|
620 | |
---|
621 | // add to an interaction group |
---|
622 | this.addToGroup((sGroup) ? sGroup : "default"); |
---|
623 | |
---|
624 | // We don't want to register this as the handle with the manager |
---|
625 | // so we just set the id rather than calling the setter. |
---|
626 | this.handleElId = id; |
---|
627 | |
---|
628 | // the linked element is the element that gets dragged by default |
---|
629 | this.setDragElId(id); |
---|
630 | |
---|
631 | // by default, clicked anchors will not start drag operations. |
---|
632 | this.invalidHandleTypes = { A: "A" }; |
---|
633 | this.invalidHandleIds = {}; |
---|
634 | this.invalidHandleClasses = []; |
---|
635 | |
---|
636 | this.applyConfig(); |
---|
637 | |
---|
638 | this.handleOnAvailable(); |
---|
639 | }, |
---|
640 | |
---|
641 | /** |
---|
642 | * Applies the configuration parameters that were passed into the constructor. |
---|
643 | * This is supposed to happen at each level through the inheritance chain. So |
---|
644 | * a DDProxy implentation will execute apply config on DDProxy, DD, and |
---|
645 | * DragDrop in order to get all of the parameters that are available in |
---|
646 | * each object. |
---|
647 | * @method applyConfig |
---|
648 | */ |
---|
649 | applyConfig: function() { |
---|
650 | |
---|
651 | // configurable properties: |
---|
652 | // padding, isTarget, maintainOffset, primaryButtonOnly |
---|
653 | this.padding = this.config.padding || [0, 0, 0, 0]; |
---|
654 | this.isTarget = (this.config.isTarget !== false); |
---|
655 | this.maintainOffset = (this.config.maintainOffset); |
---|
656 | this.primaryButtonOnly = (this.config.primaryButtonOnly !== false); |
---|
657 | |
---|
658 | }, |
---|
659 | |
---|
660 | /** |
---|
661 | * Executed when the linked element is available |
---|
662 | * @method handleOnAvailable |
---|
663 | * @private |
---|
664 | */ |
---|
665 | handleOnAvailable: function() { |
---|
666 | this.available = true; |
---|
667 | this.resetConstraints(); |
---|
668 | this.onAvailable(); |
---|
669 | }, |
---|
670 | |
---|
671 | /** |
---|
672 | * Configures the padding for the target zone in px. Effectively expands |
---|
673 | * (or reduces) the virtual object size for targeting calculations. |
---|
674 | * Supports css-style shorthand; if only one parameter is passed, all sides |
---|
675 | * will have that padding, and if only two are passed, the top and bottom |
---|
676 | * will have the first param, the left and right the second. |
---|
677 | * @method setPadding |
---|
678 | * @param {int} iTop Top pad |
---|
679 | * @param {int} iRight Right pad |
---|
680 | * @param {int} iBot Bot pad |
---|
681 | * @param {int} iLeft Left pad |
---|
682 | */ |
---|
683 | setPadding: function(iTop, iRight, iBot, iLeft) { |
---|
684 | // this.padding = [iLeft, iRight, iTop, iBot]; |
---|
685 | if (!iRight && 0 !== iRight) { |
---|
686 | this.padding = [iTop, iTop, iTop, iTop]; |
---|
687 | } else if (!iBot && 0 !== iBot) { |
---|
688 | this.padding = [iTop, iRight, iTop, iRight]; |
---|
689 | } else { |
---|
690 | this.padding = [iTop, iRight, iBot, iLeft]; |
---|
691 | } |
---|
692 | }, |
---|
693 | |
---|
694 | /** |
---|
695 | * Stores the initial placement of the linked element. |
---|
696 | * @method setInitPosition |
---|
697 | * @param {int} diffX the X offset, default 0 |
---|
698 | * @param {int} diffY the Y offset, default 0 |
---|
699 | */ |
---|
700 | setInitPosition: function(diffX, diffY) { |
---|
701 | var el = this.getEl(); |
---|
702 | |
---|
703 | if (!this.DDM.verifyEl(el)) { |
---|
704 | return; |
---|
705 | } |
---|
706 | |
---|
707 | var dx = diffX || 0; |
---|
708 | var dy = diffY || 0; |
---|
709 | |
---|
710 | var p = Dom.getXY( el ); |
---|
711 | |
---|
712 | this.initPageX = p[0] - dx; |
---|
713 | this.initPageY = p[1] - dy; |
---|
714 | |
---|
715 | this.lastPageX = p[0]; |
---|
716 | this.lastPageY = p[1]; |
---|
717 | |
---|
718 | this.setStartPosition(p); |
---|
719 | }, |
---|
720 | |
---|
721 | /** |
---|
722 | * Sets the start position of the element. This is set when the obj |
---|
723 | * is initialized, the reset when a drag is started. |
---|
724 | * @method setStartPosition |
---|
725 | * @param pos current position (from previous lookup) |
---|
726 | * @private |
---|
727 | */ |
---|
728 | setStartPosition: function(pos) { |
---|
729 | var p = pos || Dom.getXY( this.getEl() ); |
---|
730 | this.deltaSetXY = null; |
---|
731 | |
---|
732 | this.startPageX = p[0]; |
---|
733 | this.startPageY = p[1]; |
---|
734 | }, |
---|
735 | |
---|
736 | /** |
---|
737 | * Add this instance to a group of related drag/drop objects. All |
---|
738 | * instances belong to at least one group, and can belong to as many |
---|
739 | * groups as needed. |
---|
740 | * @method addToGroup |
---|
741 | * @param sGroup {string} the name of the group |
---|
742 | */ |
---|
743 | addToGroup: function(sGroup) { |
---|
744 | this.groups[sGroup] = true; |
---|
745 | this.DDM.regDragDrop(this, sGroup); |
---|
746 | }, |
---|
747 | |
---|
748 | /** |
---|
749 | * Remove's this instance from the supplied interaction group |
---|
750 | * @method removeFromGroup |
---|
751 | * @param {string} sGroup The group to drop |
---|
752 | */ |
---|
753 | removeFromGroup: function(sGroup) { |
---|
754 | if (this.groups[sGroup]) { |
---|
755 | delete this.groups[sGroup]; |
---|
756 | } |
---|
757 | |
---|
758 | this.DDM.removeDDFromGroup(this, sGroup); |
---|
759 | }, |
---|
760 | |
---|
761 | /** |
---|
762 | * Allows you to specify that an element other than the linked element |
---|
763 | * will be moved with the cursor during a drag |
---|
764 | * @method setDragElId |
---|
765 | * @param id {string} the id of the element that will be used to initiate the drag |
---|
766 | */ |
---|
767 | setDragElId: function(id) { |
---|
768 | this.dragElId = id; |
---|
769 | }, |
---|
770 | |
---|
771 | /** |
---|
772 | * Allows you to specify a child of the linked element that should be |
---|
773 | * used to initiate the drag operation. An example of this would be if |
---|
774 | * you have a content div with text and links. Clicking anywhere in the |
---|
775 | * content area would normally start the drag operation. Use this method |
---|
776 | * to specify that an element inside of the content div is the element |
---|
777 | * that starts the drag operation. |
---|
778 | * @method setHandleElId |
---|
779 | * @param id {string} the id of the element that will be used to |
---|
780 | * initiate the drag. |
---|
781 | */ |
---|
782 | setHandleElId: function(id) { |
---|
783 | if (typeof id !== "string") { |
---|
784 | id = Ext.id(id); |
---|
785 | } |
---|
786 | this.handleElId = id; |
---|
787 | this.DDM.regHandle(this.id, id); |
---|
788 | }, |
---|
789 | |
---|
790 | /** |
---|
791 | * Allows you to set an element outside of the linked element as a drag |
---|
792 | * handle |
---|
793 | * @method setOuterHandleElId |
---|
794 | * @param id the id of the element that will be used to initiate the drag |
---|
795 | */ |
---|
796 | setOuterHandleElId: function(id) { |
---|
797 | if (typeof id !== "string") { |
---|
798 | id = Ext.id(id); |
---|
799 | } |
---|
800 | Event.on(id, "mousedown", |
---|
801 | this.handleMouseDown, this); |
---|
802 | this.setHandleElId(id); |
---|
803 | |
---|
804 | this.hasOuterHandles = true; |
---|
805 | }, |
---|
806 | |
---|
807 | /** |
---|
808 | * Remove all drag and drop hooks for this element |
---|
809 | * @method unreg |
---|
810 | */ |
---|
811 | unreg: function() { |
---|
812 | Event.un(this.id, "mousedown", |
---|
813 | this.handleMouseDown); |
---|
814 | this._domRef = null; |
---|
815 | this.DDM._remove(this); |
---|
816 | }, |
---|
817 | |
---|
818 | destroy : function(){ |
---|
819 | this.unreg(); |
---|
820 | }, |
---|
821 | |
---|
822 | /** |
---|
823 | * Returns true if this instance is locked, or the drag drop mgr is locked |
---|
824 | * (meaning that all drag/drop is disabled on the page.) |
---|
825 | * @method isLocked |
---|
826 | * @return {boolean} true if this obj or all drag/drop is locked, else |
---|
827 | * false |
---|
828 | */ |
---|
829 | isLocked: function() { |
---|
830 | return (this.DDM.isLocked() || this.locked); |
---|
831 | }, |
---|
832 | |
---|
833 | /** |
---|
834 | * Fired when this object is clicked |
---|
835 | * @method handleMouseDown |
---|
836 | * @param {Event} e |
---|
837 | * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj) |
---|
838 | * @private |
---|
839 | */ |
---|
840 | handleMouseDown: function(e, oDD){ |
---|
841 | if (this.primaryButtonOnly && e.button != 0) { |
---|
842 | return; |
---|
843 | } |
---|
844 | |
---|
845 | if (this.isLocked()) { |
---|
846 | return; |
---|
847 | } |
---|
848 | |
---|
849 | this.DDM.refreshCache(this.groups); |
---|
850 | |
---|
851 | var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e)); |
---|
852 | if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) { |
---|
853 | } else { |
---|
854 | if (this.clickValidator(e)) { |
---|
855 | |
---|
856 | // set the initial element position |
---|
857 | this.setStartPosition(); |
---|
858 | |
---|
859 | this.b4MouseDown(e); |
---|
860 | this.onMouseDown(e); |
---|
861 | |
---|
862 | this.DDM.handleMouseDown(e, this); |
---|
863 | |
---|
864 | this.DDM.stopEvent(e); |
---|
865 | } else { |
---|
866 | |
---|
867 | |
---|
868 | } |
---|
869 | } |
---|
870 | }, |
---|
871 | |
---|
872 | clickValidator: function(e) { |
---|
873 | var target = e.getTarget(); |
---|
874 | return ( this.isValidHandleChild(target) && |
---|
875 | (this.id == this.handleElId || |
---|
876 | this.DDM.handleWasClicked(target, this.id)) ); |
---|
877 | }, |
---|
878 | |
---|
879 | /** |
---|
880 | * Allows you to specify a tag name that should not start a drag operation |
---|
881 | * when clicked. This is designed to facilitate embedding links within a |
---|
882 | * drag handle that do something other than start the drag. |
---|
883 | * @method addInvalidHandleType |
---|
884 | * @param {string} tagName the type of element to exclude |
---|
885 | */ |
---|
886 | addInvalidHandleType: function(tagName) { |
---|
887 | var type = tagName.toUpperCase(); |
---|
888 | this.invalidHandleTypes[type] = type; |
---|
889 | }, |
---|
890 | |
---|
891 | /** |
---|
892 | * Lets you to specify an element id for a child of a drag handle |
---|
893 | * that should not initiate a drag |
---|
894 | * @method addInvalidHandleId |
---|
895 | * @param {string} id the element id of the element you wish to ignore |
---|
896 | */ |
---|
897 | addInvalidHandleId: function(id) { |
---|
898 | if (typeof id !== "string") { |
---|
899 | id = Ext.id(id); |
---|
900 | } |
---|
901 | this.invalidHandleIds[id] = id; |
---|
902 | }, |
---|
903 | |
---|
904 | /** |
---|
905 | * Lets you specify a css class of elements that will not initiate a drag |
---|
906 | * @method addInvalidHandleClass |
---|
907 | * @param {string} cssClass the class of the elements you wish to ignore |
---|
908 | */ |
---|
909 | addInvalidHandleClass: function(cssClass) { |
---|
910 | this.invalidHandleClasses.push(cssClass); |
---|
911 | }, |
---|
912 | |
---|
913 | /** |
---|
914 | * Unsets an excluded tag name set by addInvalidHandleType |
---|
915 | * @method removeInvalidHandleType |
---|
916 | * @param {string} tagName the type of element to unexclude |
---|
917 | */ |
---|
918 | removeInvalidHandleType: function(tagName) { |
---|
919 | var type = tagName.toUpperCase(); |
---|
920 | // this.invalidHandleTypes[type] = null; |
---|
921 | delete this.invalidHandleTypes[type]; |
---|
922 | }, |
---|
923 | |
---|
924 | /** |
---|
925 | * Unsets an invalid handle id |
---|
926 | * @method removeInvalidHandleId |
---|
927 | * @param {string} id the id of the element to re-enable |
---|
928 | */ |
---|
929 | removeInvalidHandleId: function(id) { |
---|
930 | if (typeof id !== "string") { |
---|
931 | id = Ext.id(id); |
---|
932 | } |
---|
933 | delete this.invalidHandleIds[id]; |
---|
934 | }, |
---|
935 | |
---|
936 | /** |
---|
937 | * Unsets an invalid css class |
---|
938 | * @method removeInvalidHandleClass |
---|
939 | * @param {string} cssClass the class of the element(s) you wish to |
---|
940 | * re-enable |
---|
941 | */ |
---|
942 | removeInvalidHandleClass: function(cssClass) { |
---|
943 | for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) { |
---|
944 | if (this.invalidHandleClasses[i] == cssClass) { |
---|
945 | delete this.invalidHandleClasses[i]; |
---|
946 | } |
---|
947 | } |
---|
948 | }, |
---|
949 | |
---|
950 | /** |
---|
951 | * Checks the tag exclusion list to see if this click should be ignored |
---|
952 | * @method isValidHandleChild |
---|
953 | * @param {HTMLElement} node the HTMLElement to evaluate |
---|
954 | * @return {boolean} true if this is a valid tag type, false if not |
---|
955 | */ |
---|
956 | isValidHandleChild: function(node) { |
---|
957 | |
---|
958 | var valid = true; |
---|
959 | // var n = (node.nodeName == "#text") ? node.parentNode : node; |
---|
960 | var nodeName; |
---|
961 | try { |
---|
962 | nodeName = node.nodeName.toUpperCase(); |
---|
963 | } catch(e) { |
---|
964 | nodeName = node.nodeName; |
---|
965 | } |
---|
966 | valid = valid && !this.invalidHandleTypes[nodeName]; |
---|
967 | valid = valid && !this.invalidHandleIds[node.id]; |
---|
968 | |
---|
969 | for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) { |
---|
970 | valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]); |
---|
971 | } |
---|
972 | |
---|
973 | |
---|
974 | return valid; |
---|
975 | |
---|
976 | }, |
---|
977 | |
---|
978 | /** |
---|
979 | * Create the array of horizontal tick marks if an interval was specified |
---|
980 | * in setXConstraint(). |
---|
981 | * @method setXTicks |
---|
982 | * @private |
---|
983 | */ |
---|
984 | setXTicks: function(iStartX, iTickSize) { |
---|
985 | this.xTicks = []; |
---|
986 | this.xTickSize = iTickSize; |
---|
987 | |
---|
988 | var tickMap = {}; |
---|
989 | |
---|
990 | for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) { |
---|
991 | if (!tickMap[i]) { |
---|
992 | this.xTicks[this.xTicks.length] = i; |
---|
993 | tickMap[i] = true; |
---|
994 | } |
---|
995 | } |
---|
996 | |
---|
997 | for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) { |
---|
998 | if (!tickMap[i]) { |
---|
999 | this.xTicks[this.xTicks.length] = i; |
---|
1000 | tickMap[i] = true; |
---|
1001 | } |
---|
1002 | } |
---|
1003 | |
---|
1004 | this.xTicks.sort(this.DDM.numericSort) ; |
---|
1005 | }, |
---|
1006 | |
---|
1007 | /** |
---|
1008 | * Create the array of vertical tick marks if an interval was specified in |
---|
1009 | * setYConstraint(). |
---|
1010 | * @method setYTicks |
---|
1011 | * @private |
---|
1012 | */ |
---|
1013 | setYTicks: function(iStartY, iTickSize) { |
---|
1014 | this.yTicks = []; |
---|
1015 | this.yTickSize = iTickSize; |
---|
1016 | |
---|
1017 | var tickMap = {}; |
---|
1018 | |
---|
1019 | for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) { |
---|
1020 | if (!tickMap[i]) { |
---|
1021 | this.yTicks[this.yTicks.length] = i; |
---|
1022 | tickMap[i] = true; |
---|
1023 | } |
---|
1024 | } |
---|
1025 | |
---|
1026 | for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) { |
---|
1027 | if (!tickMap[i]) { |
---|
1028 | this.yTicks[this.yTicks.length] = i; |
---|
1029 | tickMap[i] = true; |
---|
1030 | } |
---|
1031 | } |
---|
1032 | |
---|
1033 | this.yTicks.sort(this.DDM.numericSort) ; |
---|
1034 | }, |
---|
1035 | |
---|
1036 | /** |
---|
1037 | * By default, the element can be dragged any place on the screen. Use |
---|
1038 | * this method to limit the horizontal travel of the element. Pass in |
---|
1039 | * 0,0 for the parameters if you want to lock the drag to the y axis. |
---|
1040 | * @method setXConstraint |
---|
1041 | * @param {int} iLeft the number of pixels the element can move to the left |
---|
1042 | * @param {int} iRight the number of pixels the element can move to the |
---|
1043 | * right |
---|
1044 | * @param {int} iTickSize optional parameter for specifying that the |
---|
1045 | * element |
---|
1046 | * should move iTickSize pixels at a time. |
---|
1047 | */ |
---|
1048 | setXConstraint: function(iLeft, iRight, iTickSize) { |
---|
1049 | this.leftConstraint = iLeft; |
---|
1050 | this.rightConstraint = iRight; |
---|
1051 | |
---|
1052 | this.minX = this.initPageX - iLeft; |
---|
1053 | this.maxX = this.initPageX + iRight; |
---|
1054 | if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); } |
---|
1055 | |
---|
1056 | this.constrainX = true; |
---|
1057 | }, |
---|
1058 | |
---|
1059 | /** |
---|
1060 | * Clears any constraints applied to this instance. Also clears ticks |
---|
1061 | * since they can't exist independent of a constraint at this time. |
---|
1062 | * @method clearConstraints |
---|
1063 | */ |
---|
1064 | clearConstraints: function() { |
---|
1065 | this.constrainX = false; |
---|
1066 | this.constrainY = false; |
---|
1067 | this.clearTicks(); |
---|
1068 | }, |
---|
1069 | |
---|
1070 | /** |
---|
1071 | * Clears any tick interval defined for this instance |
---|
1072 | * @method clearTicks |
---|
1073 | */ |
---|
1074 | clearTicks: function() { |
---|
1075 | this.xTicks = null; |
---|
1076 | this.yTicks = null; |
---|
1077 | this.xTickSize = 0; |
---|
1078 | this.yTickSize = 0; |
---|
1079 | }, |
---|
1080 | |
---|
1081 | /** |
---|
1082 | * By default, the element can be dragged any place on the screen. Set |
---|
1083 | * this to limit the vertical travel of the element. Pass in 0,0 for the |
---|
1084 | * parameters if you want to lock the drag to the x axis. |
---|
1085 | * @method setYConstraint |
---|
1086 | * @param {int} iUp the number of pixels the element can move up |
---|
1087 | * @param {int} iDown the number of pixels the element can move down |
---|
1088 | * @param {int} iTickSize optional parameter for specifying that the |
---|
1089 | * element should move iTickSize pixels at a time. |
---|
1090 | */ |
---|
1091 | setYConstraint: function(iUp, iDown, iTickSize) { |
---|
1092 | this.topConstraint = iUp; |
---|
1093 | this.bottomConstraint = iDown; |
---|
1094 | |
---|
1095 | this.minY = this.initPageY - iUp; |
---|
1096 | this.maxY = this.initPageY + iDown; |
---|
1097 | if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); } |
---|
1098 | |
---|
1099 | this.constrainY = true; |
---|
1100 | |
---|
1101 | }, |
---|
1102 | |
---|
1103 | /** |
---|
1104 | * resetConstraints must be called if you manually reposition a dd element. |
---|
1105 | * @method resetConstraints |
---|
1106 | * @param {boolean} maintainOffset |
---|
1107 | */ |
---|
1108 | resetConstraints: function() { |
---|
1109 | // Maintain offsets if necessary |
---|
1110 | if (this.initPageX || this.initPageX === 0) { |
---|
1111 | // figure out how much this thing has moved |
---|
1112 | var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0; |
---|
1113 | var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0; |
---|
1114 | |
---|
1115 | this.setInitPosition(dx, dy); |
---|
1116 | |
---|
1117 | // This is the first time we have detected the element's position |
---|
1118 | } else { |
---|
1119 | this.setInitPosition(); |
---|
1120 | } |
---|
1121 | |
---|
1122 | if (this.constrainX) { |
---|
1123 | this.setXConstraint( this.leftConstraint, |
---|
1124 | this.rightConstraint, |
---|
1125 | this.xTickSize ); |
---|
1126 | } |
---|
1127 | |
---|
1128 | if (this.constrainY) { |
---|
1129 | this.setYConstraint( this.topConstraint, |
---|
1130 | this.bottomConstraint, |
---|
1131 | this.yTickSize ); |
---|
1132 | } |
---|
1133 | }, |
---|
1134 | |
---|
1135 | /** |
---|
1136 | * Normally the drag element is moved pixel by pixel, but we can specify |
---|
1137 | * that it move a number of pixels at a time. This method resolves the |
---|
1138 | * location when we have it set up like this. |
---|
1139 | * @method getTick |
---|
1140 | * @param {int} val where we want to place the object |
---|
1141 | * @param {int[]} tickArray sorted array of valid points |
---|
1142 | * @return {int} the closest tick |
---|
1143 | * @private |
---|
1144 | */ |
---|
1145 | getTick: function(val, tickArray) { |
---|
1146 | if (!tickArray) { |
---|
1147 | // If tick interval is not defined, it is effectively 1 pixel, |
---|
1148 | // so we return the value passed to us. |
---|
1149 | return val; |
---|
1150 | } else if (tickArray[0] >= val) { |
---|
1151 | // The value is lower than the first tick, so we return the first |
---|
1152 | // tick. |
---|
1153 | return tickArray[0]; |
---|
1154 | } else { |
---|
1155 | for (var i=0, len=tickArray.length; i<len; ++i) { |
---|
1156 | var next = i + 1; |
---|
1157 | if (tickArray[next] && tickArray[next] >= val) { |
---|
1158 | var diff1 = val - tickArray[i]; |
---|
1159 | var diff2 = tickArray[next] - val; |
---|
1160 | return (diff2 > diff1) ? tickArray[i] : tickArray[next]; |
---|
1161 | } |
---|
1162 | } |
---|
1163 | |
---|
1164 | // The value is larger than the last tick, so we return the last |
---|
1165 | // tick. |
---|
1166 | return tickArray[tickArray.length - 1]; |
---|
1167 | } |
---|
1168 | }, |
---|
1169 | |
---|
1170 | /** |
---|
1171 | * toString method |
---|
1172 | * @method toString |
---|
1173 | * @return {string} string representation of the dd obj |
---|
1174 | */ |
---|
1175 | toString: function() { |
---|
1176 | return ("DragDrop " + this.id); |
---|
1177 | } |
---|
1178 | |
---|
1179 | }; |
---|
1180 | |
---|
1181 | })(); |
---|
1182 | /* |
---|
1183 | * The drag and drop utility provides a framework for building drag and drop |
---|
1184 | * applications. In addition to enabling drag and drop for specific elements, |
---|
1185 | * the drag and drop elements are tracked by the manager class, and the |
---|
1186 | * interactions between the various elements are tracked during the drag and |
---|
1187 | * the implementing code is notified about these important moments. |
---|
1188 | */ |
---|
1189 | |
---|
1190 | // Only load the library once. Rewriting the manager class would orphan |
---|
1191 | // existing drag and drop instances. |
---|
1192 | if (!Ext.dd.DragDropMgr) { |
---|
1193 | |
---|
1194 | /** |
---|
1195 | * @class Ext.dd.DragDropMgr |
---|
1196 | * DragDropMgr is a singleton that tracks the element interaction for |
---|
1197 | * all DragDrop items in the window. Generally, you will not call |
---|
1198 | * this class directly, but it does have helper methods that could |
---|
1199 | * be useful in your DragDrop implementations. |
---|
1200 | * @singleton |
---|
1201 | */ |
---|
1202 | Ext.dd.DragDropMgr = function() { |
---|
1203 | |
---|
1204 | var Event = Ext.EventManager; |
---|
1205 | |
---|
1206 | return { |
---|
1207 | |
---|
1208 | /** |
---|
1209 | * Two dimensional Array of registered DragDrop objects. The first |
---|
1210 | * dimension is the DragDrop item group, the second the DragDrop |
---|
1211 | * object. |
---|
1212 | * @property ids |
---|
1213 | * @type String[] |
---|
1214 | * @private |
---|
1215 | * @static |
---|
1216 | */ |
---|
1217 | ids: {}, |
---|
1218 | |
---|
1219 | /** |
---|
1220 | * Array of element ids defined as drag handles. Used to determine |
---|
1221 | * if the element that generated the mousedown event is actually the |
---|
1222 | * handle and not the html element itself. |
---|
1223 | * @property handleIds |
---|
1224 | * @type String[] |
---|
1225 | * @private |
---|
1226 | * @static |
---|
1227 | */ |
---|
1228 | handleIds: {}, |
---|
1229 | |
---|
1230 | /** |
---|
1231 | * the DragDrop object that is currently being dragged |
---|
1232 | * @property dragCurrent |
---|
1233 | * @type DragDrop |
---|
1234 | * @private |
---|
1235 | * @static |
---|
1236 | **/ |
---|
1237 | dragCurrent: null, |
---|
1238 | |
---|
1239 | /** |
---|
1240 | * the DragDrop object(s) that are being hovered over |
---|
1241 | * @property dragOvers |
---|
1242 | * @type Array |
---|
1243 | * @private |
---|
1244 | * @static |
---|
1245 | */ |
---|
1246 | dragOvers: {}, |
---|
1247 | |
---|
1248 | /** |
---|
1249 | * the X distance between the cursor and the object being dragged |
---|
1250 | * @property deltaX |
---|
1251 | * @type int |
---|
1252 | * @private |
---|
1253 | * @static |
---|
1254 | */ |
---|
1255 | deltaX: 0, |
---|
1256 | |
---|
1257 | /** |
---|
1258 | * the Y distance between the cursor and the object being dragged |
---|
1259 | * @property deltaY |
---|
1260 | * @type int |
---|
1261 | * @private |
---|
1262 | * @static |
---|
1263 | */ |
---|
1264 | deltaY: 0, |
---|
1265 | |
---|
1266 | /** |
---|
1267 | * Flag to determine if we should prevent the default behavior of the |
---|
1268 | * events we define. By default this is true, but this can be set to |
---|
1269 | * false if you need the default behavior (not recommended) |
---|
1270 | * @property preventDefault |
---|
1271 | * @type boolean |
---|
1272 | * @static |
---|
1273 | */ |
---|
1274 | preventDefault: true, |
---|
1275 | |
---|
1276 | /** |
---|
1277 | * Flag to determine if we should stop the propagation of the events |
---|
1278 | * we generate. This is true by default but you may want to set it to |
---|
1279 | * false if the html element contains other features that require the |
---|
1280 | * mouse click. |
---|
1281 | * @property stopPropagation |
---|
1282 | * @type boolean |
---|
1283 | * @static |
---|
1284 | */ |
---|
1285 | stopPropagation: true, |
---|
1286 | |
---|
1287 | /** |
---|
1288 | * Internal flag that is set to true when drag and drop has been |
---|
1289 | * intialized |
---|
1290 | * @property initialized |
---|
1291 | * @private |
---|
1292 | * @static |
---|
1293 | */ |
---|
1294 | initialized: false, |
---|
1295 | |
---|
1296 | /** |
---|
1297 | * All drag and drop can be disabled. |
---|
1298 | * @property locked |
---|
1299 | * @private |
---|
1300 | * @static |
---|
1301 | */ |
---|
1302 | locked: false, |
---|
1303 | |
---|
1304 | /** |
---|
1305 | * Called the first time an element is registered. |
---|
1306 | * @method init |
---|
1307 | * @private |
---|
1308 | * @static |
---|
1309 | */ |
---|
1310 | init: function() { |
---|
1311 | this.initialized = true; |
---|
1312 | }, |
---|
1313 | |
---|
1314 | /** |
---|
1315 | * In point mode, drag and drop interaction is defined by the |
---|
1316 | * location of the cursor during the drag/drop |
---|
1317 | * @property POINT |
---|
1318 | * @type int |
---|
1319 | * @static |
---|
1320 | */ |
---|
1321 | POINT: 0, |
---|
1322 | |
---|
1323 | /** |
---|
1324 | * In intersect mode, drag and drop interaction is defined by the |
---|
1325 | * overlap of two or more drag and drop objects. |
---|
1326 | * @property INTERSECT |
---|
1327 | * @type int |
---|
1328 | * @static |
---|
1329 | */ |
---|
1330 | INTERSECT: 1, |
---|
1331 | |
---|
1332 | /** |
---|
1333 | * The current drag and drop mode. Default: POINT |
---|
1334 | * @property mode |
---|
1335 | * @type int |
---|
1336 | * @static |
---|
1337 | */ |
---|
1338 | mode: 0, |
---|
1339 | |
---|
1340 | /** |
---|
1341 | * Runs method on all drag and drop objects |
---|
1342 | * @method _execOnAll |
---|
1343 | * @private |
---|
1344 | * @static |
---|
1345 | */ |
---|
1346 | _execOnAll: function(sMethod, args) { |
---|
1347 | for (var i in this.ids) { |
---|
1348 | for (var j in this.ids[i]) { |
---|
1349 | var oDD = this.ids[i][j]; |
---|
1350 | if (! this.isTypeOfDD(oDD)) { |
---|
1351 | continue; |
---|
1352 | } |
---|
1353 | oDD[sMethod].apply(oDD, args); |
---|
1354 | } |
---|
1355 | } |
---|
1356 | }, |
---|
1357 | |
---|
1358 | /** |
---|
1359 | * Drag and drop initialization. Sets up the global event handlers |
---|
1360 | * @method _onLoad |
---|
1361 | * @private |
---|
1362 | * @static |
---|
1363 | */ |
---|
1364 | _onLoad: function() { |
---|
1365 | |
---|
1366 | this.init(); |
---|
1367 | |
---|
1368 | |
---|
1369 | Event.on(document, "mouseup", this.handleMouseUp, this, true); |
---|
1370 | Event.on(document, "mousemove", this.handleMouseMove, this, true); |
---|
1371 | Event.on(window, "unload", this._onUnload, this, true); |
---|
1372 | Event.on(window, "resize", this._onResize, this, true); |
---|
1373 | // Event.on(window, "mouseout", this._test); |
---|
1374 | |
---|
1375 | }, |
---|
1376 | |
---|
1377 | /** |
---|
1378 | * Reset constraints on all drag and drop objs |
---|
1379 | * @method _onResize |
---|
1380 | * @private |
---|
1381 | * @static |
---|
1382 | */ |
---|
1383 | _onResize: function(e) { |
---|
1384 | this._execOnAll("resetConstraints", []); |
---|
1385 | }, |
---|
1386 | |
---|
1387 | /** |
---|
1388 | * Lock all drag and drop functionality |
---|
1389 | * @method lock |
---|
1390 | * @static |
---|
1391 | */ |
---|
1392 | lock: function() { this.locked = true; }, |
---|
1393 | |
---|
1394 | /** |
---|
1395 | * Unlock all drag and drop functionality |
---|
1396 | * @method unlock |
---|
1397 | * @static |
---|
1398 | */ |
---|
1399 | unlock: function() { this.locked = false; }, |
---|
1400 | |
---|
1401 | /** |
---|
1402 | * Is drag and drop locked? |
---|
1403 | * @method isLocked |
---|
1404 | * @return {boolean} True if drag and drop is locked, false otherwise. |
---|
1405 | * @static |
---|
1406 | */ |
---|
1407 | isLocked: function() { return this.locked; }, |
---|
1408 | |
---|
1409 | /** |
---|
1410 | * Location cache that is set for all drag drop objects when a drag is |
---|
1411 | * initiated, cleared when the drag is finished. |
---|
1412 | * @property locationCache |
---|
1413 | * @private |
---|
1414 | * @static |
---|
1415 | */ |
---|
1416 | locationCache: {}, |
---|
1417 | |
---|
1418 | /** |
---|
1419 | * Set useCache to false if you want to force object the lookup of each |
---|
1420 | * drag and drop linked element constantly during a drag. |
---|
1421 | * @property useCache |
---|
1422 | * @type boolean |
---|
1423 | * @static |
---|
1424 | */ |
---|
1425 | useCache: true, |
---|
1426 | |
---|
1427 | /** |
---|
1428 | * The number of pixels that the mouse needs to move after the |
---|
1429 | * mousedown before the drag is initiated. Default=3; |
---|
1430 | * @property clickPixelThresh |
---|
1431 | * @type int |
---|
1432 | * @static |
---|
1433 | */ |
---|
1434 | clickPixelThresh: 3, |
---|
1435 | |
---|
1436 | /** |
---|
1437 | * The number of milliseconds after the mousedown event to initiate the |
---|
1438 | * drag if we don't get a mouseup event. Default=350 |
---|
1439 | * @property clickTimeThresh |
---|
1440 | * @type int |
---|
1441 | * @static |
---|
1442 | */ |
---|
1443 | clickTimeThresh: 350, |
---|
1444 | |
---|
1445 | /** |
---|
1446 | * Flag that indicates that either the drag pixel threshold or the |
---|
1447 | * mousdown time threshold has been met |
---|
1448 | * @property dragThreshMet |
---|
1449 | * @type boolean |
---|
1450 | * @private |
---|
1451 | * @static |
---|
1452 | */ |
---|
1453 | dragThreshMet: false, |
---|
1454 | |
---|
1455 | /** |
---|
1456 | * Timeout used for the click time threshold |
---|
1457 | * @property clickTimeout |
---|
1458 | * @type Object |
---|
1459 | * @private |
---|
1460 | * @static |
---|
1461 | */ |
---|
1462 | clickTimeout: null, |
---|
1463 | |
---|
1464 | /** |
---|
1465 | * The X position of the mousedown event stored for later use when a |
---|
1466 | * drag threshold is met. |
---|
1467 | * @property startX |
---|
1468 | * @type int |
---|
1469 | * @private |
---|
1470 | * @static |
---|
1471 | */ |
---|
1472 | startX: 0, |
---|
1473 | |
---|
1474 | /** |
---|
1475 | * The Y position of the mousedown event stored for later use when a |
---|
1476 | * drag threshold is met. |
---|
1477 | * @property startY |
---|
1478 | * @type int |
---|
1479 | * @private |
---|
1480 | * @static |
---|
1481 | */ |
---|
1482 | startY: 0, |
---|
1483 | |
---|
1484 | /** |
---|
1485 | * Each DragDrop instance must be registered with the DragDropMgr. |
---|
1486 | * This is executed in DragDrop.init() |
---|
1487 | * @method regDragDrop |
---|
1488 | * @param {DragDrop} oDD the DragDrop object to register |
---|
1489 | * @param {String} sGroup the name of the group this element belongs to |
---|
1490 | * @static |
---|
1491 | */ |
---|
1492 | regDragDrop: function(oDD, sGroup) { |
---|
1493 | if (!this.initialized) { this.init(); } |
---|
1494 | |
---|
1495 | if (!this.ids[sGroup]) { |
---|
1496 | this.ids[sGroup] = {}; |
---|
1497 | } |
---|
1498 | this.ids[sGroup][oDD.id] = oDD; |
---|
1499 | }, |
---|
1500 | |
---|
1501 | /** |
---|
1502 | * Removes the supplied dd instance from the supplied group. Executed |
---|
1503 | * by DragDrop.removeFromGroup, so don't call this function directly. |
---|
1504 | * @method removeDDFromGroup |
---|
1505 | * @private |
---|
1506 | * @static |
---|
1507 | */ |
---|
1508 | removeDDFromGroup: function(oDD, sGroup) { |
---|
1509 | if (!this.ids[sGroup]) { |
---|
1510 | this.ids[sGroup] = {}; |
---|
1511 | } |
---|
1512 | |
---|
1513 | var obj = this.ids[sGroup]; |
---|
1514 | if (obj && obj[oDD.id]) { |
---|
1515 | delete obj[oDD.id]; |
---|
1516 | } |
---|
1517 | }, |
---|
1518 | |
---|
1519 | /** |
---|
1520 | * Unregisters a drag and drop item. This is executed in |
---|
1521 | * DragDrop.unreg, use that method instead of calling this directly. |
---|
1522 | * @method _remove |
---|
1523 | * @private |
---|
1524 | * @static |
---|
1525 | */ |
---|
1526 | _remove: function(oDD) { |
---|
1527 | for (var g in oDD.groups) { |
---|
1528 | if (g && this.ids[g] && this.ids[g][oDD.id]) { |
---|
1529 | delete this.ids[g][oDD.id]; |
---|
1530 | } |
---|
1531 | } |
---|
1532 | delete this.handleIds[oDD.id]; |
---|
1533 | }, |
---|
1534 | |
---|
1535 | /** |
---|
1536 | * Each DragDrop handle element must be registered. This is done |
---|
1537 | * automatically when executing DragDrop.setHandleElId() |
---|
1538 | * @method regHandle |
---|
1539 | * @param {String} sDDId the DragDrop id this element is a handle for |
---|
1540 | * @param {String} sHandleId the id of the element that is the drag |
---|
1541 | * handle |
---|
1542 | * @static |
---|
1543 | */ |
---|
1544 | regHandle: function(sDDId, sHandleId) { |
---|
1545 | if (!this.handleIds[sDDId]) { |
---|
1546 | this.handleIds[sDDId] = {}; |
---|
1547 | } |
---|
1548 | this.handleIds[sDDId][sHandleId] = sHandleId; |
---|
1549 | }, |
---|
1550 | |
---|
1551 | /** |
---|
1552 | * Utility function to determine if a given element has been |
---|
1553 | * registered as a drag drop item. |
---|
1554 | * @method isDragDrop |
---|
1555 | * @param {String} id the element id to check |
---|
1556 | * @return {boolean} true if this element is a DragDrop item, |
---|
1557 | * false otherwise |
---|
1558 | * @static |
---|
1559 | */ |
---|
1560 | isDragDrop: function(id) { |
---|
1561 | return ( this.getDDById(id) ) ? true : false; |
---|
1562 | }, |
---|
1563 | |
---|
1564 | /** |
---|
1565 | * Returns the drag and drop instances that are in all groups the |
---|
1566 | * passed in instance belongs to. |
---|
1567 | * @method getRelated |
---|
1568 | * @param {DragDrop} p_oDD the obj to get related data for |
---|
1569 | * @param {boolean} bTargetsOnly if true, only return targetable objs |
---|
1570 | * @return {DragDrop[]} the related instances |
---|
1571 | * @static |
---|
1572 | */ |
---|
1573 | getRelated: function(p_oDD, bTargetsOnly) { |
---|
1574 | var oDDs = []; |
---|
1575 | for (var i in p_oDD.groups) { |
---|
1576 | for (var j in this.ids[i]) { |
---|
1577 | var dd = this.ids[i][j]; |
---|
1578 | if (! this.isTypeOfDD(dd)) { |
---|
1579 | continue; |
---|
1580 | } |
---|
1581 | if (!bTargetsOnly || dd.isTarget) { |
---|
1582 | oDDs[oDDs.length] = dd; |
---|
1583 | } |
---|
1584 | } |
---|
1585 | } |
---|
1586 | |
---|
1587 | return oDDs; |
---|
1588 | }, |
---|
1589 | |
---|
1590 | /** |
---|
1591 | * Returns true if the specified dd target is a legal target for |
---|
1592 | * the specifice drag obj |
---|
1593 | * @method isLegalTarget |
---|
1594 | * @param {DragDrop} oDD the drag obj |
---|
1595 | * @param {DragDrop} oTargetDD the target |
---|
1596 | * @return {boolean} true if the target is a legal target for the |
---|
1597 | * dd obj |
---|
1598 | * @static |
---|
1599 | */ |
---|
1600 | isLegalTarget: function (oDD, oTargetDD) { |
---|
1601 | var targets = this.getRelated(oDD, true); |
---|
1602 | for (var i=0, len=targets.length;i<len;++i) { |
---|
1603 | if (targets[i].id == oTargetDD.id) { |
---|
1604 | return true; |
---|
1605 | } |
---|
1606 | } |
---|
1607 | |
---|
1608 | return false; |
---|
1609 | }, |
---|
1610 | |
---|
1611 | /** |
---|
1612 | * My goal is to be able to transparently determine if an object is |
---|
1613 | * typeof DragDrop, and the exact subclass of DragDrop. typeof |
---|
1614 | * returns "object", oDD.constructor.toString() always returns |
---|
1615 | * "DragDrop" and not the name of the subclass. So for now it just |
---|
1616 | * evaluates a well-known variable in DragDrop. |
---|
1617 | * @method isTypeOfDD |
---|
1618 | * @param {Object} the object to evaluate |
---|
1619 | * @return {boolean} true if typeof oDD = DragDrop |
---|
1620 | * @static |
---|
1621 | */ |
---|
1622 | isTypeOfDD: function (oDD) { |
---|
1623 | return (oDD && oDD.__ygDragDrop); |
---|
1624 | }, |
---|
1625 | |
---|
1626 | /** |
---|
1627 | * Utility function to determine if a given element has been |
---|
1628 | * registered as a drag drop handle for the given Drag Drop object. |
---|
1629 | * @method isHandle |
---|
1630 | * @param {String} id the element id to check |
---|
1631 | * @return {boolean} true if this element is a DragDrop handle, false |
---|
1632 | * otherwise |
---|
1633 | * @static |
---|
1634 | */ |
---|
1635 | isHandle: function(sDDId, sHandleId) { |
---|
1636 | return ( this.handleIds[sDDId] && |
---|
1637 | this.handleIds[sDDId][sHandleId] ); |
---|
1638 | }, |
---|
1639 | |
---|
1640 | /** |
---|
1641 | * Returns the DragDrop instance for a given id |
---|
1642 | * @method getDDById |
---|
1643 | * @param {String} id the id of the DragDrop object |
---|
1644 | * @return {DragDrop} the drag drop object, null if it is not found |
---|
1645 | * @static |
---|
1646 | */ |
---|
1647 | getDDById: function(id) { |
---|
1648 | for (var i in this.ids) { |
---|
1649 | if (this.ids[i][id]) { |
---|
1650 | return this.ids[i][id]; |
---|
1651 | } |
---|
1652 | } |
---|
1653 | return null; |
---|
1654 | }, |
---|
1655 | |
---|
1656 | /** |
---|
1657 | * Fired after a registered DragDrop object gets the mousedown event. |
---|
1658 | * Sets up the events required to track the object being dragged |
---|
1659 | * @method handleMouseDown |
---|
1660 | * @param {Event} e the event |
---|
1661 | * @param oDD the DragDrop object being dragged |
---|
1662 | * @private |
---|
1663 | * @static |
---|
1664 | */ |
---|
1665 | handleMouseDown: function(e, oDD) { |
---|
1666 | if(Ext.QuickTips){ |
---|
1667 | Ext.QuickTips.ddDisable(); |
---|
1668 | } |
---|
1669 | if(this.dragCurrent){ |
---|
1670 | // the original browser mouseup wasn't handled (e.g. outside FF browser window) |
---|
1671 | // so clean up first to avoid breaking the next drag |
---|
1672 | this.handleMouseUp(e); |
---|
1673 | } |
---|
1674 | |
---|
1675 | this.currentTarget = e.getTarget(); |
---|
1676 | this.dragCurrent = oDD; |
---|
1677 | |
---|
1678 | var el = oDD.getEl(); |
---|
1679 | |
---|
1680 | // track start position |
---|
1681 | this.startX = e.getPageX(); |
---|
1682 | this.startY = e.getPageY(); |
---|
1683 | |
---|
1684 | this.deltaX = this.startX - el.offsetLeft; |
---|
1685 | this.deltaY = this.startY - el.offsetTop; |
---|
1686 | |
---|
1687 | this.dragThreshMet = false; |
---|
1688 | |
---|
1689 | this.clickTimeout = setTimeout( |
---|
1690 | function() { |
---|
1691 | var DDM = Ext.dd.DDM; |
---|
1692 | DDM.startDrag(DDM.startX, DDM.startY); |
---|
1693 | }, |
---|
1694 | this.clickTimeThresh ); |
---|
1695 | }, |
---|
1696 | |
---|
1697 | /** |
---|
1698 | * Fired when either the drag pixel threshol or the mousedown hold |
---|
1699 | * time threshold has been met. |
---|
1700 | * @method startDrag |
---|
1701 | * @param x {int} the X position of the original mousedown |
---|
1702 | * @param y {int} the Y position of the original mousedown |
---|
1703 | * @static |
---|
1704 | */ |
---|
1705 | startDrag: function(x, y) { |
---|
1706 | clearTimeout(this.clickTimeout); |
---|
1707 | if (this.dragCurrent) { |
---|
1708 | this.dragCurrent.b4StartDrag(x, y); |
---|
1709 | this.dragCurrent.startDrag(x, y); |
---|
1710 | } |
---|
1711 | this.dragThreshMet = true; |
---|
1712 | }, |
---|
1713 | |
---|
1714 | /** |
---|
1715 | * Internal function to handle the mouseup event. Will be invoked |
---|
1716 | * from the context of the document. |
---|
1717 | * @method handleMouseUp |
---|
1718 | * @param {Event} e the event |
---|
1719 | * @private |
---|
1720 | * @static |
---|
1721 | */ |
---|
1722 | handleMouseUp: function(e) { |
---|
1723 | |
---|
1724 | if(Ext.QuickTips){ |
---|
1725 | Ext.QuickTips.ddEnable(); |
---|
1726 | } |
---|
1727 | if (! this.dragCurrent) { |
---|
1728 | return; |
---|
1729 | } |
---|
1730 | |
---|
1731 | clearTimeout(this.clickTimeout); |
---|
1732 | |
---|
1733 | if (this.dragThreshMet) { |
---|
1734 | this.fireEvents(e, true); |
---|
1735 | } else { |
---|
1736 | } |
---|
1737 | |
---|
1738 | this.stopDrag(e); |
---|
1739 | |
---|
1740 | this.stopEvent(e); |
---|
1741 | }, |
---|
1742 | |
---|
1743 | /** |
---|
1744 | * Utility to stop event propagation and event default, if these |
---|
1745 | * features are turned on. |
---|
1746 | * @method stopEvent |
---|
1747 | * @param {Event} e the event as returned by this.getEvent() |
---|
1748 | * @static |
---|
1749 | */ |
---|
1750 | stopEvent: function(e){ |
---|
1751 | if(this.stopPropagation) { |
---|
1752 | e.stopPropagation(); |
---|
1753 | } |
---|
1754 | |
---|
1755 | if (this.preventDefault) { |
---|
1756 | e.preventDefault(); |
---|
1757 | } |
---|
1758 | }, |
---|
1759 | |
---|
1760 | /** |
---|
1761 | * Internal function to clean up event handlers after the drag |
---|
1762 | * operation is complete |
---|
1763 | * @method stopDrag |
---|
1764 | * @param {Event} e the event |
---|
1765 | * @private |
---|
1766 | * @static |
---|
1767 | */ |
---|
1768 | stopDrag: function(e) { |
---|
1769 | // Fire the drag end event for the item that was dragged |
---|
1770 | if (this.dragCurrent) { |
---|
1771 | if (this.dragThreshMet) { |
---|
1772 | this.dragCurrent.b4EndDrag(e); |
---|
1773 | this.dragCurrent.endDrag(e); |
---|
1774 | } |
---|
1775 | |
---|
1776 | this.dragCurrent.onMouseUp(e); |
---|
1777 | } |
---|
1778 | |
---|
1779 | this.dragCurrent = null; |
---|
1780 | this.dragOvers = {}; |
---|
1781 | }, |
---|
1782 | |
---|
1783 | /** |
---|
1784 | * Internal function to handle the mousemove event. Will be invoked |
---|
1785 | * from the context of the html element. |
---|
1786 | * |
---|
1787 | * @TODO figure out what we can do about mouse events lost when the |
---|
1788 | * user drags objects beyond the window boundary. Currently we can |
---|
1789 | * detect this in internet explorer by verifying that the mouse is |
---|
1790 | * down during the mousemove event. Firefox doesn't give us the |
---|
1791 | * button state on the mousemove event. |
---|
1792 | * @method handleMouseMove |
---|
1793 | * @param {Event} e the event |
---|
1794 | * @private |
---|
1795 | * @static |
---|
1796 | */ |
---|
1797 | handleMouseMove: function(e) { |
---|
1798 | if (! this.dragCurrent) { |
---|
1799 | return true; |
---|
1800 | } |
---|
1801 | // var button = e.which || e.button; |
---|
1802 | |
---|
1803 | // check for IE mouseup outside of page boundary |
---|
1804 | if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) { |
---|
1805 | this.stopEvent(e); |
---|
1806 | return this.handleMouseUp(e); |
---|
1807 | } |
---|
1808 | |
---|
1809 | if (!this.dragThreshMet) { |
---|
1810 | var diffX = Math.abs(this.startX - e.getPageX()); |
---|
1811 | var diffY = Math.abs(this.startY - e.getPageY()); |
---|
1812 | if (diffX > this.clickPixelThresh || |
---|
1813 | diffY > this.clickPixelThresh) { |
---|
1814 | this.startDrag(this.startX, this.startY); |
---|
1815 | } |
---|
1816 | } |
---|
1817 | |
---|
1818 | if (this.dragThreshMet) { |
---|
1819 | this.dragCurrent.b4Drag(e); |
---|
1820 | this.dragCurrent.onDrag(e); |
---|
1821 | if(!this.dragCurrent.moveOnly){ |
---|
1822 | this.fireEvents(e, false); |
---|
1823 | } |
---|
1824 | } |
---|
1825 | |
---|
1826 | this.stopEvent(e); |
---|
1827 | |
---|
1828 | return true; |
---|
1829 | }, |
---|
1830 | |
---|
1831 | /** |
---|
1832 | * Iterates over all of the DragDrop elements to find ones we are |
---|
1833 | * hovering over or dropping on |
---|
1834 | * @method fireEvents |
---|
1835 | * @param {Event} e the event |
---|
1836 | * @param {boolean} isDrop is this a drop op or a mouseover op? |
---|
1837 | * @private |
---|
1838 | * @static |
---|
1839 | */ |
---|
1840 | fireEvents: function(e, isDrop) { |
---|
1841 | var dc = this.dragCurrent; |
---|
1842 | |
---|
1843 | // If the user did the mouse up outside of the window, we could |
---|
1844 | // get here even though we have ended the drag. |
---|
1845 | if (!dc || dc.isLocked()) { |
---|
1846 | return; |
---|
1847 | } |
---|
1848 | |
---|
1849 | var pt = e.getPoint(); |
---|
1850 | |
---|
1851 | // cache the previous dragOver array |
---|
1852 | var oldOvers = []; |
---|
1853 | |
---|
1854 | var outEvts = []; |
---|
1855 | var overEvts = []; |
---|
1856 | var dropEvts = []; |
---|
1857 | var enterEvts = []; |
---|
1858 | |
---|
1859 | // Check to see if the object(s) we were hovering over is no longer |
---|
1860 | // being hovered over so we can fire the onDragOut event |
---|
1861 | for (var i in this.dragOvers) { |
---|
1862 | |
---|
1863 | var ddo = this.dragOvers[i]; |
---|
1864 | |
---|
1865 | if (! this.isTypeOfDD(ddo)) { |
---|
1866 | continue; |
---|
1867 | } |
---|
1868 | |
---|
1869 | if (! this.isOverTarget(pt, ddo, this.mode)) { |
---|
1870 | outEvts.push( ddo ); |
---|
1871 | } |
---|
1872 | |
---|
1873 | oldOvers[i] = true; |
---|
1874 | delete this.dragOvers[i]; |
---|
1875 | } |
---|
1876 | |
---|
1877 | for (var sGroup in dc.groups) { |
---|
1878 | |
---|
1879 | if ("string" != typeof sGroup) { |
---|
1880 | continue; |
---|
1881 | } |
---|
1882 | |
---|
1883 | for (i in this.ids[sGroup]) { |
---|
1884 | var oDD = this.ids[sGroup][i]; |
---|
1885 | if (! this.isTypeOfDD(oDD)) { |
---|
1886 | continue; |
---|
1887 | } |
---|
1888 | |
---|
1889 | if (oDD.isTarget && !oDD.isLocked() && ((oDD != dc) || (dc.ignoreSelf === false))) { |
---|
1890 | if (this.isOverTarget(pt, oDD, this.mode)) { |
---|
1891 | // look for drop interactions |
---|
1892 | if (isDrop) { |
---|
1893 | dropEvts.push( oDD ); |
---|
1894 | // look for drag enter and drag over interactions |
---|
1895 | } else { |
---|
1896 | |
---|
1897 | // initial drag over: dragEnter fires |
---|
1898 | if (!oldOvers[oDD.id]) { |
---|
1899 | enterEvts.push( oDD ); |
---|
1900 | // subsequent drag overs: dragOver fires |
---|
1901 | } else { |
---|
1902 | overEvts.push( oDD ); |
---|
1903 | } |
---|
1904 | |
---|
1905 | this.dragOvers[oDD.id] = oDD; |
---|
1906 | } |
---|
1907 | } |
---|
1908 | } |
---|
1909 | } |
---|
1910 | } |
---|
1911 | |
---|
1912 | if (this.mode) { |
---|
1913 | if (outEvts.length) { |
---|
1914 | dc.b4DragOut(e, outEvts); |
---|
1915 | dc.onDragOut(e, outEvts); |
---|
1916 | } |
---|
1917 | |
---|
1918 | if (enterEvts.length) { |
---|
1919 | dc.onDragEnter(e, enterEvts); |
---|
1920 | } |
---|
1921 | |
---|
1922 | if (overEvts.length) { |
---|
1923 | dc.b4DragOver(e, overEvts); |
---|
1924 | dc.onDragOver(e, overEvts); |
---|
1925 | } |
---|
1926 | |
---|
1927 | if (dropEvts.length) { |
---|
1928 | dc.b4DragDrop(e, dropEvts); |
---|
1929 | dc.onDragDrop(e, dropEvts); |
---|
1930 | } |
---|
1931 | |
---|
1932 | } else { |
---|
1933 | // fire dragout events |
---|
1934 | var len = 0; |
---|
1935 | for (i=0, len=outEvts.length; i<len; ++i) { |
---|
1936 | dc.b4DragOut(e, outEvts[i].id); |
---|
1937 | dc.onDragOut(e, outEvts[i].id); |
---|
1938 | } |
---|
1939 | |
---|
1940 | // fire enter events |
---|
1941 | for (i=0,len=enterEvts.length; i<len; ++i) { |
---|
1942 | // dc.b4DragEnter(e, oDD.id); |
---|
1943 | dc.onDragEnter(e, enterEvts[i].id); |
---|
1944 | } |
---|
1945 | |
---|
1946 | // fire over events |
---|
1947 | for (i=0,len=overEvts.length; i<len; ++i) { |
---|
1948 | dc.b4DragOver(e, overEvts[i].id); |
---|
1949 | dc.onDragOver(e, overEvts[i].id); |
---|
1950 | } |
---|
1951 | |
---|
1952 | // fire drop events |
---|
1953 | for (i=0, len=dropEvts.length; i<len; ++i) { |
---|
1954 | dc.b4DragDrop(e, dropEvts[i].id); |
---|
1955 | dc.onDragDrop(e, dropEvts[i].id); |
---|
1956 | } |
---|
1957 | |
---|
1958 | } |
---|
1959 | |
---|
1960 | // notify about a drop that did not find a target |
---|
1961 | if (isDrop && !dropEvts.length) { |
---|
1962 | dc.onInvalidDrop(e); |
---|
1963 | } |
---|
1964 | |
---|
1965 | }, |
---|
1966 | |
---|
1967 | /** |
---|
1968 | * Helper function for getting the best match from the list of drag |
---|
1969 | * and drop objects returned by the drag and drop events when we are |
---|
1970 | * in INTERSECT mode. It returns either the first object that the |
---|
1971 | * cursor is over, or the object that has the greatest overlap with |
---|
1972 | * the dragged element. |
---|
1973 | * @method getBestMatch |
---|
1974 | * @param {DragDrop[]} dds The array of drag and drop objects |
---|
1975 | * targeted |
---|
1976 | * @return {DragDrop} The best single match |
---|
1977 | * @static |
---|
1978 | */ |
---|
1979 | getBestMatch: function(dds) { |
---|
1980 | var winner = null; |
---|
1981 | // Return null if the input is not what we expect |
---|
1982 | //if (!dds || !dds.length || dds.length == 0) { |
---|
1983 | // winner = null; |
---|
1984 | // If there is only one item, it wins |
---|
1985 | //} else if (dds.length == 1) { |
---|
1986 | |
---|
1987 | var len = dds.length; |
---|
1988 | |
---|
1989 | if (len == 1) { |
---|
1990 | winner = dds[0]; |
---|
1991 | } else { |
---|
1992 | // Loop through the targeted items |
---|
1993 | for (var i=0; i<len; ++i) { |
---|
1994 | var dd = dds[i]; |
---|
1995 | // If the cursor is over the object, it wins. If the |
---|
1996 | // cursor is over multiple matches, the first one we come |
---|
1997 | // to wins. |
---|
1998 | if (dd.cursorIsOver) { |
---|
1999 | winner = dd; |
---|
2000 | break; |
---|
2001 | // Otherwise the object with the most overlap wins |
---|
2002 | } else { |
---|
2003 | if (!winner || |
---|
2004 | winner.overlap.getArea() < dd.overlap.getArea()) { |
---|
2005 | winner = dd; |
---|
2006 | } |
---|
2007 | } |
---|
2008 | } |
---|
2009 | } |
---|
2010 | |
---|
2011 | return winner; |
---|
2012 | }, |
---|
2013 | |
---|
2014 | /** |
---|
2015 | * Refreshes the cache of the top-left and bottom-right points of the |
---|
2016 | * drag and drop objects in the specified group(s). This is in the |
---|
2017 | * format that is stored in the drag and drop instance, so typical |
---|
2018 | * usage is: |
---|
2019 | * <code> |
---|
2020 | * Ext.dd.DragDropMgr.refreshCache(ddinstance.groups); |
---|
2021 | * </code> |
---|
2022 | * Alternatively: |
---|
2023 | * <code> |
---|
2024 | * Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true}); |
---|
2025 | * </code> |
---|
2026 | * @TODO this really should be an indexed array. Alternatively this |
---|
2027 | * method could accept both. |
---|
2028 | * @method refreshCache |
---|
2029 | * @param {Object} groups an associative array of groups to refresh |
---|
2030 | * @static |
---|
2031 | */ |
---|
2032 | refreshCache: function(groups) { |
---|
2033 | for (var sGroup in groups) { |
---|
2034 | if ("string" != typeof sGroup) { |
---|
2035 | continue; |
---|
2036 | } |
---|
2037 | for (var i in this.ids[sGroup]) { |
---|
2038 | var oDD = this.ids[sGroup][i]; |
---|
2039 | |
---|
2040 | if (this.isTypeOfDD(oDD)) { |
---|
2041 | // if (this.isTypeOfDD(oDD) && oDD.isTarget) { |
---|
2042 | var loc = this.getLocation(oDD); |
---|
2043 | if (loc) { |
---|
2044 | this.locationCache[oDD.id] = loc; |
---|
2045 | } else { |
---|
2046 | delete this.locationCache[oDD.id]; |
---|
2047 | // this will unregister the drag and drop object if |
---|
2048 | // the element is not in a usable state |
---|
2049 | // oDD.unreg(); |
---|
2050 | } |
---|
2051 | } |
---|
2052 | } |
---|
2053 | } |
---|
2054 | }, |
---|
2055 | |
---|
2056 | /** |
---|
2057 | * This checks to make sure an element exists and is in the DOM. The |
---|
2058 | * main purpose is to handle cases where innerHTML is used to remove |
---|
2059 | * drag and drop objects from the DOM. IE provides an 'unspecified |
---|
2060 | * error' when trying to access the offsetParent of such an element |
---|
2061 | * @method verifyEl |
---|
2062 | * @param {HTMLElement} el the element to check |
---|
2063 | * @return {boolean} true if the element looks usable |
---|
2064 | * @static |
---|
2065 | */ |
---|
2066 | verifyEl: function(el) { |
---|
2067 | if (el) { |
---|
2068 | var parent; |
---|
2069 | if(Ext.isIE){ |
---|
2070 | try{ |
---|
2071 | parent = el.offsetParent; |
---|
2072 | }catch(e){} |
---|
2073 | }else{ |
---|
2074 | parent = el.offsetParent; |
---|
2075 | } |
---|
2076 | if (parent) { |
---|
2077 | return true; |
---|
2078 | } |
---|
2079 | } |
---|
2080 | |
---|
2081 | return false; |
---|
2082 | }, |
---|
2083 | |
---|
2084 | /** |
---|
2085 | * Returns a Region object containing the drag and drop element's position |
---|
2086 | * and size, including the padding configured for it |
---|
2087 | * @method getLocation |
---|
2088 | * @param {DragDrop} oDD the drag and drop object to get the |
---|
2089 | * location for |
---|
2090 | * @return {Ext.lib.Region} a Region object representing the total area |
---|
2091 | * the element occupies, including any padding |
---|
2092 | * the instance is configured for. |
---|
2093 | * @static |
---|
2094 | */ |
---|
2095 | getLocation: function(oDD) { |
---|
2096 | if (! this.isTypeOfDD(oDD)) { |
---|
2097 | return null; |
---|
2098 | } |
---|
2099 | |
---|
2100 | var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l, region; |
---|
2101 | |
---|
2102 | try { |
---|
2103 | pos= Ext.lib.Dom.getXY(el); |
---|
2104 | } catch (e) { } |
---|
2105 | |
---|
2106 | if (!pos) { |
---|
2107 | return null; |
---|
2108 | } |
---|
2109 | |
---|
2110 | x1 = pos[0]; |
---|
2111 | x2 = x1 + el.offsetWidth; |
---|
2112 | y1 = pos[1]; |
---|
2113 | y2 = y1 + el.offsetHeight; |
---|
2114 | |
---|
2115 | t = y1 - oDD.padding[0]; |
---|
2116 | r = x2 + oDD.padding[1]; |
---|
2117 | b = y2 + oDD.padding[2]; |
---|
2118 | l = x1 - oDD.padding[3]; |
---|
2119 | |
---|
2120 | region = new Ext.lib.Region( t, r, b, l ); |
---|
2121 | /* |
---|
2122 | * The code below is to ensure that large scrolling elements will |
---|
2123 | * only have their visible area recognized as a drop target, otherwise it |
---|
2124 | * can potentially erronously register as a target when the element scrolls |
---|
2125 | * over the top of something below it. |
---|
2126 | */ |
---|
2127 | el = Ext.get(el.parentNode); |
---|
2128 | while (el && region) { |
---|
2129 | if (el.isScrollable()) { |
---|
2130 | // check whether our element is visible in the view port: |
---|
2131 | region = region.intersect(el.getRegion()); |
---|
2132 | } |
---|
2133 | el = el.parent(); |
---|
2134 | } |
---|
2135 | return region; |
---|
2136 | }, |
---|
2137 | |
---|
2138 | /** |
---|
2139 | * Checks the cursor location to see if it over the target |
---|
2140 | * @method isOverTarget |
---|
2141 | * @param {Ext.lib.Point} pt The point to evaluate |
---|
2142 | * @param {DragDrop} oTarget the DragDrop object we are inspecting |
---|
2143 | * @return {boolean} true if the mouse is over the target |
---|
2144 | * @private |
---|
2145 | * @static |
---|
2146 | */ |
---|
2147 | isOverTarget: function(pt, oTarget, intersect) { |
---|
2148 | // use cache if available |
---|
2149 | var loc = this.locationCache[oTarget.id]; |
---|
2150 | if (!loc || !this.useCache) { |
---|
2151 | loc = this.getLocation(oTarget); |
---|
2152 | this.locationCache[oTarget.id] = loc; |
---|
2153 | |
---|
2154 | } |
---|
2155 | |
---|
2156 | if (!loc) { |
---|
2157 | return false; |
---|
2158 | } |
---|
2159 | |
---|
2160 | oTarget.cursorIsOver = loc.contains( pt ); |
---|
2161 | |
---|
2162 | // DragDrop is using this as a sanity check for the initial mousedown |
---|
2163 | // in this case we are done. In POINT mode, if the drag obj has no |
---|
2164 | // contraints, we are also done. Otherwise we need to evaluate the |
---|
2165 | // location of the target as related to the actual location of the |
---|
2166 | // dragged element. |
---|
2167 | var dc = this.dragCurrent; |
---|
2168 | if (!dc || !dc.getTargetCoord || |
---|
2169 | (!intersect && !dc.constrainX && !dc.constrainY)) { |
---|
2170 | return oTarget.cursorIsOver; |
---|
2171 | } |
---|
2172 | |
---|
2173 | oTarget.overlap = null; |
---|
2174 | |
---|
2175 | // Get the current location of the drag element, this is the |
---|
2176 | // location of the mouse event less the delta that represents |
---|
2177 | // where the original mousedown happened on the element. We |
---|
2178 | // need to consider constraints and ticks as well. |
---|
2179 | var pos = dc.getTargetCoord(pt.x, pt.y); |
---|
2180 | |
---|
2181 | var el = dc.getDragEl(); |
---|
2182 | var curRegion = new Ext.lib.Region( pos.y, |
---|
2183 | pos.x + el.offsetWidth, |
---|
2184 | pos.y + el.offsetHeight, |
---|
2185 | pos.x ); |
---|
2186 | |
---|
2187 | var overlap = curRegion.intersect(loc); |
---|
2188 | |
---|
2189 | if (overlap) { |
---|
2190 | oTarget.overlap = overlap; |
---|
2191 | return (intersect) ? true : oTarget.cursorIsOver; |
---|
2192 | } else { |
---|
2193 | return false; |
---|
2194 | } |
---|
2195 | }, |
---|
2196 | |
---|
2197 | /** |
---|
2198 | * unload event handler |
---|
2199 | * @method _onUnload |
---|
2200 | * @private |
---|
2201 | * @static |
---|
2202 | */ |
---|
2203 | _onUnload: function(e, me) { |
---|
2204 | Event.removeListener(document, "mouseup", this.handleMouseUp, this); |
---|
2205 | Event.removeListener(document, "mousemove", this.handleMouseMove, this); |
---|
2206 | Event.removeListener(window, "resize", this._onResize, this); |
---|
2207 | Ext.dd.DragDropMgr.unregAll(); |
---|
2208 | }, |
---|
2209 | |
---|
2210 | /** |
---|
2211 | * Cleans up the drag and drop events and objects. |
---|
2212 | * @method unregAll |
---|
2213 | * @private |
---|
2214 | * @static |
---|
2215 | */ |
---|
2216 | unregAll: function() { |
---|
2217 | |
---|
2218 | if (this.dragCurrent) { |
---|
2219 | this.stopDrag(); |
---|
2220 | this.dragCurrent = null; |
---|
2221 | } |
---|
2222 | |
---|
2223 | this._execOnAll("unreg", []); |
---|
2224 | |
---|
2225 | for (var i in this.elementCache) { |
---|
2226 | delete this.elementCache[i]; |
---|
2227 | } |
---|
2228 | |
---|
2229 | this.elementCache = {}; |
---|
2230 | this.ids = {}; |
---|
2231 | }, |
---|
2232 | |
---|
2233 | /** |
---|
2234 | * A cache of DOM elements |
---|
2235 | * @property elementCache |
---|
2236 | * @private |
---|
2237 | * @static |
---|
2238 | */ |
---|
2239 | elementCache: {}, |
---|
2240 | |
---|
2241 | /** |
---|
2242 | * Get the wrapper for the DOM element specified |
---|
2243 | * @method getElWrapper |
---|
2244 | * @param {String} id the id of the element to get |
---|
2245 | * @return {Ext.dd.DDM.ElementWrapper} the wrapped element |
---|
2246 | * @private |
---|
2247 | * @deprecated This wrapper isn't that useful |
---|
2248 | * @static |
---|
2249 | */ |
---|
2250 | getElWrapper: function(id) { |
---|
2251 | var oWrapper = this.elementCache[id]; |
---|
2252 | if (!oWrapper || !oWrapper.el) { |
---|
2253 | oWrapper = this.elementCache[id] = |
---|
2254 | new this.ElementWrapper(Ext.getDom(id)); |
---|
2255 | } |
---|
2256 | return oWrapper; |
---|
2257 | }, |
---|
2258 | |
---|
2259 | /** |
---|
2260 | * Returns the actual DOM element |
---|
2261 | * @method getElement |
---|
2262 | * @param {String} id the id of the elment to get |
---|
2263 | * @return {Object} The element |
---|
2264 | * @deprecated use Ext.lib.Ext.getDom instead |
---|
2265 | * @static |
---|
2266 | */ |
---|
2267 | getElement: function(id) { |
---|
2268 | return Ext.getDom(id); |
---|
2269 | }, |
---|
2270 | |
---|
2271 | /** |
---|
2272 | * Returns the style property for the DOM element (i.e., |
---|
2273 | * document.getElById(id).style) |
---|
2274 | * @method getCss |
---|
2275 | * @param {String} id the id of the elment to get |
---|
2276 | * @return {Object} The style property of the element |
---|
2277 | * @deprecated use Ext.lib.Dom instead |
---|
2278 | * @static |
---|
2279 | */ |
---|
2280 | getCss: function(id) { |
---|
2281 | var el = Ext.getDom(id); |
---|
2282 | return (el) ? el.style : null; |
---|
2283 | }, |
---|
2284 | |
---|
2285 | /** |
---|
2286 | * Inner class for cached elements |
---|
2287 | * @class Ext.dd.DragDropMgr.ElementWrapper |
---|
2288 | * @for DragDropMgr |
---|
2289 | * @private |
---|
2290 | * @deprecated |
---|
2291 | */ |
---|
2292 | ElementWrapper: function(el) { |
---|
2293 | /** |
---|
2294 | * The element |
---|
2295 | * @property el |
---|
2296 | */ |
---|
2297 | this.el = el || null; |
---|
2298 | /** |
---|
2299 | * The element id |
---|
2300 | * @property id |
---|
2301 | */ |
---|
2302 | this.id = this.el && el.id; |
---|
2303 | /** |
---|
2304 | * A reference to the style property |
---|
2305 | * @property css |
---|
2306 | */ |
---|
2307 | this.css = this.el && el.style; |
---|
2308 | }, |
---|
2309 | |
---|
2310 | /** |
---|
2311 | * Returns the X position of an html element |
---|
2312 | * @method getPosX |
---|
2313 | * @param el the element for which to get the position |
---|
2314 | * @return {int} the X coordinate |
---|
2315 | * @for DragDropMgr |
---|
2316 | * @deprecated use Ext.lib.Dom.getX instead |
---|
2317 | * @static |
---|
2318 | */ |
---|
2319 | getPosX: function(el) { |
---|
2320 | return Ext.lib.Dom.getX(el); |
---|
2321 | }, |
---|
2322 | |
---|
2323 | /** |
---|
2324 | * Returns the Y position of an html element |
---|
2325 | * @method getPosY |
---|
2326 | * @param el the element for which to get the position |
---|
2327 | * @return {int} the Y coordinate |
---|
2328 | * @deprecated use Ext.lib.Dom.getY instead |
---|
2329 | * @static |
---|
2330 | */ |
---|
2331 | getPosY: function(el) { |
---|
2332 | return Ext.lib.Dom.getY(el); |
---|
2333 | }, |
---|
2334 | |
---|
2335 | /** |
---|
2336 | * Swap two nodes. In IE, we use the native method, for others we |
---|
2337 | * emulate the IE behavior |
---|
2338 | * @method swapNode |
---|
2339 | * @param n1 the first node to swap |
---|
2340 | * @param n2 the other node to swap |
---|
2341 | * @static |
---|
2342 | */ |
---|
2343 | swapNode: function(n1, n2) { |
---|
2344 | if (n1.swapNode) { |
---|
2345 | n1.swapNode(n2); |
---|
2346 | } else { |
---|
2347 | var p = n2.parentNode; |
---|
2348 | var s = n2.nextSibling; |
---|
2349 | |
---|
2350 | if (s == n1) { |
---|
2351 | p.insertBefore(n1, n2); |
---|
2352 | } else if (n2 == n1.nextSibling) { |
---|
2353 | p.insertBefore(n2, n1); |
---|
2354 | } else { |
---|
2355 | n1.parentNode.replaceChild(n2, n1); |
---|
2356 | p.insertBefore(n1, s); |
---|
2357 | } |
---|
2358 | } |
---|
2359 | }, |
---|
2360 | |
---|
2361 | /** |
---|
2362 | * Returns the current scroll position |
---|
2363 | * @method getScroll |
---|
2364 | * @private |
---|
2365 | * @static |
---|
2366 | */ |
---|
2367 | getScroll: function () { |
---|
2368 | var t, l, dde=document.documentElement, db=document.body; |
---|
2369 | if (dde && (dde.scrollTop || dde.scrollLeft)) { |
---|
2370 | t = dde.scrollTop; |
---|
2371 | l = dde.scrollLeft; |
---|
2372 | } else if (db) { |
---|
2373 | t = db.scrollTop; |
---|
2374 | l = db.scrollLeft; |
---|
2375 | } else { |
---|
2376 | |
---|
2377 | } |
---|
2378 | return { top: t, left: l }; |
---|
2379 | }, |
---|
2380 | |
---|
2381 | /** |
---|
2382 | * Returns the specified element style property |
---|
2383 | * @method getStyle |
---|
2384 | * @param {HTMLElement} el the element |
---|
2385 | * @param {string} styleProp the style property |
---|
2386 | * @return {string} The value of the style property |
---|
2387 | * @deprecated use Ext.lib.Dom.getStyle |
---|
2388 | * @static |
---|
2389 | */ |
---|
2390 | getStyle: function(el, styleProp) { |
---|
2391 | return Ext.fly(el).getStyle(styleProp); |
---|
2392 | }, |
---|
2393 | |
---|
2394 | /** |
---|
2395 | * Gets the scrollTop |
---|
2396 | * @method getScrollTop |
---|
2397 | * @return {int} the document's scrollTop |
---|
2398 | * @static |
---|
2399 | */ |
---|
2400 | getScrollTop: function () { |
---|
2401 | return this.getScroll().top; |
---|
2402 | }, |
---|
2403 | |
---|
2404 | /** |
---|
2405 | * Gets the scrollLeft |
---|
2406 | * @method getScrollLeft |
---|
2407 | * @return {int} the document's scrollTop |
---|
2408 | * @static |
---|
2409 | */ |
---|
2410 | getScrollLeft: function () { |
---|
2411 | return this.getScroll().left; |
---|
2412 | }, |
---|
2413 | |
---|
2414 | /** |
---|
2415 | * Sets the x/y position of an element to the location of the |
---|
2416 | * target element. |
---|
2417 | * @method moveToEl |
---|
2418 | * @param {HTMLElement} moveEl The element to move |
---|
2419 | * @param {HTMLElement} targetEl The position reference element |
---|
2420 | * @static |
---|
2421 | */ |
---|
2422 | moveToEl: function (moveEl, targetEl) { |
---|
2423 | var aCoord = Ext.lib.Dom.getXY(targetEl); |
---|
2424 | Ext.lib.Dom.setXY(moveEl, aCoord); |
---|
2425 | }, |
---|
2426 | |
---|
2427 | /** |
---|
2428 | * Numeric array sort function |
---|
2429 | * @method numericSort |
---|
2430 | * @static |
---|
2431 | */ |
---|
2432 | numericSort: function(a, b) { |
---|
2433 | return (a - b); |
---|
2434 | }, |
---|
2435 | |
---|
2436 | /** |
---|
2437 | * Internal counter |
---|
2438 | * @property _timeoutCount |
---|
2439 | * @private |
---|
2440 | * @static |
---|
2441 | */ |
---|
2442 | _timeoutCount: 0, |
---|
2443 | |
---|
2444 | /** |
---|
2445 | * Trying to make the load order less important. Without this we get |
---|
2446 | * an error if this file is loaded before the Event Utility. |
---|
2447 | * @method _addListeners |
---|
2448 | * @private |
---|
2449 | * @static |
---|
2450 | */ |
---|
2451 | _addListeners: function() { |
---|
2452 | var DDM = Ext.dd.DDM; |
---|
2453 | if ( Ext.lib.Event && document ) { |
---|
2454 | DDM._onLoad(); |
---|
2455 | } else { |
---|
2456 | if (DDM._timeoutCount > 2000) { |
---|
2457 | } else { |
---|
2458 | setTimeout(DDM._addListeners, 10); |
---|
2459 | if (document && document.body) { |
---|
2460 | DDM._timeoutCount += 1; |
---|
2461 | } |
---|
2462 | } |
---|
2463 | } |
---|
2464 | }, |
---|
2465 | |
---|
2466 | /** |
---|
2467 | * Recursively searches the immediate parent and all child nodes for |
---|
2468 | * the handle element in order to determine wheter or not it was |
---|
2469 | * clicked. |
---|
2470 | * @method handleWasClicked |
---|
2471 | * @param node the html element to inspect |
---|
2472 | * @static |
---|
2473 | */ |
---|
2474 | handleWasClicked: function(node, id) { |
---|
2475 | if (this.isHandle(id, node.id)) { |
---|
2476 | return true; |
---|
2477 | } else { |
---|
2478 | // check to see if this is a text node child of the one we want |
---|
2479 | var p = node.parentNode; |
---|
2480 | |
---|
2481 | while (p) { |
---|
2482 | if (this.isHandle(id, p.id)) { |
---|
2483 | return true; |
---|
2484 | } else { |
---|
2485 | p = p.parentNode; |
---|
2486 | } |
---|
2487 | } |
---|
2488 | } |
---|
2489 | |
---|
2490 | return false; |
---|
2491 | } |
---|
2492 | |
---|
2493 | }; |
---|
2494 | |
---|
2495 | }(); |
---|
2496 | |
---|
2497 | // shorter alias, save a few bytes |
---|
2498 | Ext.dd.DDM = Ext.dd.DragDropMgr; |
---|
2499 | Ext.dd.DDM._addListeners(); |
---|
2500 | |
---|
2501 | } |
---|
2502 | |
---|
2503 | /** |
---|
2504 | * @class Ext.dd.DD |
---|
2505 | * A DragDrop implementation where the linked element follows the |
---|
2506 | * mouse cursor during a drag. |
---|
2507 | * @extends Ext.dd.DragDrop |
---|
2508 | * @constructor |
---|
2509 | * @param {String} id the id of the linked element |
---|
2510 | * @param {String} sGroup the group of related DragDrop items |
---|
2511 | * @param {object} config an object containing configurable attributes |
---|
2512 | * Valid properties for DD: |
---|
2513 | * scroll |
---|
2514 | */ |
---|
2515 | Ext.dd.DD = function(id, sGroup, config) { |
---|
2516 | if (id) { |
---|
2517 | this.init(id, sGroup, config); |
---|
2518 | } |
---|
2519 | }; |
---|
2520 | |
---|
2521 | Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, { |
---|
2522 | |
---|
2523 | /** |
---|
2524 | * When set to true, the utility automatically tries to scroll the browser |
---|
2525 | * window when a drag and drop element is dragged near the viewport boundary. |
---|
2526 | * Defaults to true. |
---|
2527 | * @property scroll |
---|
2528 | * @type boolean |
---|
2529 | */ |
---|
2530 | scroll: true, |
---|
2531 | |
---|
2532 | /** |
---|
2533 | * Sets the pointer offset to the distance between the linked element's top |
---|
2534 | * left corner and the location the element was clicked |
---|
2535 | * @method autoOffset |
---|
2536 | * @param {int} iPageX the X coordinate of the click |
---|
2537 | * @param {int} iPageY the Y coordinate of the click |
---|
2538 | */ |
---|
2539 | autoOffset: function(iPageX, iPageY) { |
---|
2540 | var x = iPageX - this.startPageX; |
---|
2541 | var y = iPageY - this.startPageY; |
---|
2542 | this.setDelta(x, y); |
---|
2543 | }, |
---|
2544 | |
---|
2545 | /** |
---|
2546 | * Sets the pointer offset. You can call this directly to force the |
---|
2547 | * offset to be in a particular location (e.g., pass in 0,0 to set it |
---|
2548 | * to the center of the object) |
---|
2549 | * @method setDelta |
---|
2550 | * @param {int} iDeltaX the distance from the left |
---|
2551 | * @param {int} iDeltaY the distance from the top |
---|
2552 | */ |
---|
2553 | setDelta: function(iDeltaX, iDeltaY) { |
---|
2554 | this.deltaX = iDeltaX; |
---|
2555 | this.deltaY = iDeltaY; |
---|
2556 | }, |
---|
2557 | |
---|
2558 | /** |
---|
2559 | * Sets the drag element to the location of the mousedown or click event, |
---|
2560 | * maintaining the cursor location relative to the location on the element |
---|
2561 | * that was clicked. Override this if you want to place the element in a |
---|
2562 | * location other than where the cursor is. |
---|
2563 | * @method setDragElPos |
---|
2564 | * @param {int} iPageX the X coordinate of the mousedown or drag event |
---|
2565 | * @param {int} iPageY the Y coordinate of the mousedown or drag event |
---|
2566 | */ |
---|
2567 | setDragElPos: function(iPageX, iPageY) { |
---|
2568 | // the first time we do this, we are going to check to make sure |
---|
2569 | // the element has css positioning |
---|
2570 | |
---|
2571 | var el = this.getDragEl(); |
---|
2572 | this.alignElWithMouse(el, iPageX, iPageY); |
---|
2573 | }, |
---|
2574 | |
---|
2575 | /** |
---|
2576 | * Sets the element to the location of the mousedown or click event, |
---|
2577 | * maintaining the cursor location relative to the location on the element |
---|
2578 | * that was clicked. Override this if you want to place the element in a |
---|
2579 | * location other than where the cursor is. |
---|
2580 | * @method alignElWithMouse |
---|
2581 | * @param {HTMLElement} el the element to move |
---|
2582 | * @param {int} iPageX the X coordinate of the mousedown or drag event |
---|
2583 | * @param {int} iPageY the Y coordinate of the mousedown or drag event |
---|
2584 | */ |
---|
2585 | alignElWithMouse: function(el, iPageX, iPageY) { |
---|
2586 | var oCoord = this.getTargetCoord(iPageX, iPageY); |
---|
2587 | var fly = el.dom ? el : Ext.fly(el, '_dd'); |
---|
2588 | if (!this.deltaSetXY) { |
---|
2589 | var aCoord = [oCoord.x, oCoord.y]; |
---|
2590 | fly.setXY(aCoord); |
---|
2591 | var newLeft = fly.getLeft(true); |
---|
2592 | var newTop = fly.getTop(true); |
---|
2593 | this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ]; |
---|
2594 | } else { |
---|
2595 | fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]); |
---|
2596 | } |
---|
2597 | |
---|
2598 | this.cachePosition(oCoord.x, oCoord.y); |
---|
2599 | this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth); |
---|
2600 | return oCoord; |
---|
2601 | }, |
---|
2602 | |
---|
2603 | /** |
---|
2604 | * Saves the most recent position so that we can reset the constraints and |
---|
2605 | * tick marks on-demand. We need to know this so that we can calculate the |
---|
2606 | * number of pixels the element is offset from its original position. |
---|
2607 | * @method cachePosition |
---|
2608 | * @param iPageX the current x position (optional, this just makes it so we |
---|
2609 | * don't have to look it up again) |
---|
2610 | * @param iPageY the current y position (optional, this just makes it so we |
---|
2611 | * don't have to look it up again) |
---|
2612 | */ |
---|
2613 | cachePosition: function(iPageX, iPageY) { |
---|
2614 | if (iPageX) { |
---|
2615 | this.lastPageX = iPageX; |
---|
2616 | this.lastPageY = iPageY; |
---|
2617 | } else { |
---|
2618 | var aCoord = Ext.lib.Dom.getXY(this.getEl()); |
---|
2619 | this.lastPageX = aCoord[0]; |
---|
2620 | this.lastPageY = aCoord[1]; |
---|
2621 | } |
---|
2622 | }, |
---|
2623 | |
---|
2624 | /** |
---|
2625 | * Auto-scroll the window if the dragged object has been moved beyond the |
---|
2626 | * visible window boundary. |
---|
2627 | * @method autoScroll |
---|
2628 | * @param {int} x the drag element's x position |
---|
2629 | * @param {int} y the drag element's y position |
---|
2630 | * @param {int} h the height of the drag element |
---|
2631 | * @param {int} w the width of the drag element |
---|
2632 | * @private |
---|
2633 | */ |
---|
2634 | autoScroll: function(x, y, h, w) { |
---|
2635 | |
---|
2636 | if (this.scroll) { |
---|
2637 | // The client height |
---|
2638 | var clientH = Ext.lib.Dom.getViewHeight(); |
---|
2639 | |
---|
2640 | // The client width |
---|
2641 | var clientW = Ext.lib.Dom.getViewWidth(); |
---|
2642 | |
---|
2643 | // The amt scrolled down |
---|
2644 | var st = this.DDM.getScrollTop(); |
---|
2645 | |
---|
2646 | // The amt scrolled right |
---|
2647 | var sl = this.DDM.getScrollLeft(); |
---|
2648 | |
---|
2649 | // Location of the bottom of the element |
---|
2650 | var bot = h + y; |
---|
2651 | |
---|
2652 | // Location of the right of the element |
---|
2653 | var right = w + x; |
---|
2654 | |
---|
2655 | // The distance from the cursor to the bottom of the visible area, |
---|
2656 | // adjusted so that we don't scroll if the cursor is beyond the |
---|
2657 | // element drag constraints |
---|
2658 | var toBot = (clientH + st - y - this.deltaY); |
---|
2659 | |
---|
2660 | // The distance from the cursor to the right of the visible area |
---|
2661 | var toRight = (clientW + sl - x - this.deltaX); |
---|
2662 | |
---|
2663 | |
---|
2664 | // How close to the edge the cursor must be before we scroll |
---|
2665 | // var thresh = (document.all) ? 100 : 40; |
---|
2666 | var thresh = 40; |
---|
2667 | |
---|
2668 | // How many pixels to scroll per autoscroll op. This helps to reduce |
---|
2669 | // clunky scrolling. IE is more sensitive about this ... it needs this |
---|
2670 | // value to be higher. |
---|
2671 | var scrAmt = (document.all) ? 80 : 30; |
---|
2672 | |
---|
2673 | // Scroll down if we are near the bottom of the visible page and the |
---|
2674 | // obj extends below the crease |
---|
2675 | if ( bot > clientH && toBot < thresh ) { |
---|
2676 | window.scrollTo(sl, st + scrAmt); |
---|
2677 | } |
---|
2678 | |
---|
2679 | // Scroll up if the window is scrolled down and the top of the object |
---|
2680 | // goes above the top border |
---|
2681 | if ( y < st && st > 0 && y - st < thresh ) { |
---|
2682 | window.scrollTo(sl, st - scrAmt); |
---|
2683 | } |
---|
2684 | |
---|
2685 | // Scroll right if the obj is beyond the right border and the cursor is |
---|
2686 | // near the border. |
---|
2687 | if ( right > clientW && toRight < thresh ) { |
---|
2688 | window.scrollTo(sl + scrAmt, st); |
---|
2689 | } |
---|
2690 | |
---|
2691 | // Scroll left if the window has been scrolled to the right and the obj |
---|
2692 | // extends past the left border |
---|
2693 | if ( x < sl && sl > 0 && x - sl < thresh ) { |
---|
2694 | window.scrollTo(sl - scrAmt, st); |
---|
2695 | } |
---|
2696 | } |
---|
2697 | }, |
---|
2698 | |
---|
2699 | /** |
---|
2700 | * Finds the location the element should be placed if we want to move |
---|
2701 | * it to where the mouse location less the click offset would place us. |
---|
2702 | * @method getTargetCoord |
---|
2703 | * @param {int} iPageX the X coordinate of the click |
---|
2704 | * @param {int} iPageY the Y coordinate of the click |
---|
2705 | * @return an object that contains the coordinates (Object.x and Object.y) |
---|
2706 | * @private |
---|
2707 | */ |
---|
2708 | getTargetCoord: function(iPageX, iPageY) { |
---|
2709 | var x = iPageX - this.deltaX; |
---|
2710 | var y = iPageY - this.deltaY; |
---|
2711 | |
---|
2712 | if (this.constrainX) { |
---|
2713 | if (x < this.minX) { x = this.minX; } |
---|
2714 | if (x > this.maxX) { x = this.maxX; } |
---|
2715 | } |
---|
2716 | |
---|
2717 | if (this.constrainY) { |
---|
2718 | if (y < this.minY) { y = this.minY; } |
---|
2719 | if (y > this.maxY) { y = this.maxY; } |
---|
2720 | } |
---|
2721 | |
---|
2722 | x = this.getTick(x, this.xTicks); |
---|
2723 | y = this.getTick(y, this.yTicks); |
---|
2724 | |
---|
2725 | |
---|
2726 | return {x:x, y:y}; |
---|
2727 | }, |
---|
2728 | |
---|
2729 | /** |
---|
2730 | * Sets up config options specific to this class. Overrides |
---|
2731 | * Ext.dd.DragDrop, but all versions of this method through the |
---|
2732 | * inheritance chain are called |
---|
2733 | */ |
---|
2734 | applyConfig: function() { |
---|
2735 | Ext.dd.DD.superclass.applyConfig.call(this); |
---|
2736 | this.scroll = (this.config.scroll !== false); |
---|
2737 | }, |
---|
2738 | |
---|
2739 | /** |
---|
2740 | * Event that fires prior to the onMouseDown event. Overrides |
---|
2741 | * Ext.dd.DragDrop. |
---|
2742 | */ |
---|
2743 | b4MouseDown: function(e) { |
---|
2744 | // this.resetConstraints(); |
---|
2745 | this.autoOffset(e.getPageX(), |
---|
2746 | e.getPageY()); |
---|
2747 | }, |
---|
2748 | |
---|
2749 | /** |
---|
2750 | * Event that fires prior to the onDrag event. Overrides |
---|
2751 | * Ext.dd.DragDrop. |
---|
2752 | */ |
---|
2753 | b4Drag: function(e) { |
---|
2754 | this.setDragElPos(e.getPageX(), |
---|
2755 | e.getPageY()); |
---|
2756 | }, |
---|
2757 | |
---|
2758 | toString: function() { |
---|
2759 | return ("DD " + this.id); |
---|
2760 | } |
---|
2761 | |
---|
2762 | ////////////////////////////////////////////////////////////////////////// |
---|
2763 | // Debugging ygDragDrop events that can be overridden |
---|
2764 | ////////////////////////////////////////////////////////////////////////// |
---|
2765 | /* |
---|
2766 | startDrag: function(x, y) { |
---|
2767 | }, |
---|
2768 | |
---|
2769 | onDrag: function(e) { |
---|
2770 | }, |
---|
2771 | |
---|
2772 | onDragEnter: function(e, id) { |
---|
2773 | }, |
---|
2774 | |
---|
2775 | onDragOver: function(e, id) { |
---|
2776 | }, |
---|
2777 | |
---|
2778 | onDragOut: function(e, id) { |
---|
2779 | }, |
---|
2780 | |
---|
2781 | onDragDrop: function(e, id) { |
---|
2782 | }, |
---|
2783 | |
---|
2784 | endDrag: function(e) { |
---|
2785 | } |
---|
2786 | |
---|
2787 | */ |
---|
2788 | |
---|
2789 | }); |
---|
2790 | /** |
---|
2791 | * @class Ext.dd.DDProxy |
---|
2792 | * A DragDrop implementation that inserts an empty, bordered div into |
---|
2793 | * the document that follows the cursor during drag operations. At the time of |
---|
2794 | * the click, the frame div is resized to the dimensions of the linked html |
---|
2795 | * element, and moved to the exact location of the linked element. |
---|
2796 | * |
---|
2797 | * References to the "frame" element refer to the single proxy element that |
---|
2798 | * was created to be dragged in place of all DDProxy elements on the |
---|
2799 | * page. |
---|
2800 | * |
---|
2801 | * @extends Ext.dd.DD |
---|
2802 | * @constructor |
---|
2803 | * @param {String} id the id of the linked html element |
---|
2804 | * @param {String} sGroup the group of related DragDrop objects |
---|
2805 | * @param {object} config an object containing configurable attributes |
---|
2806 | * Valid properties for DDProxy in addition to those in DragDrop: |
---|
2807 | * resizeFrame, centerFrame, dragElId |
---|
2808 | */ |
---|
2809 | Ext.dd.DDProxy = function(id, sGroup, config) { |
---|
2810 | if (id) { |
---|
2811 | this.init(id, sGroup, config); |
---|
2812 | this.initFrame(); |
---|
2813 | } |
---|
2814 | }; |
---|
2815 | |
---|
2816 | /** |
---|
2817 | * The default drag frame div id |
---|
2818 | * @property Ext.dd.DDProxy.dragElId |
---|
2819 | * @type String |
---|
2820 | * @static |
---|
2821 | */ |
---|
2822 | Ext.dd.DDProxy.dragElId = "ygddfdiv"; |
---|
2823 | |
---|
2824 | Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, { |
---|
2825 | |
---|
2826 | /** |
---|
2827 | * By default we resize the drag frame to be the same size as the element |
---|
2828 | * we want to drag (this is to get the frame effect). We can turn it off |
---|
2829 | * if we want a different behavior. |
---|
2830 | * @property resizeFrame |
---|
2831 | * @type boolean |
---|
2832 | */ |
---|
2833 | resizeFrame: true, |
---|
2834 | |
---|
2835 | /** |
---|
2836 | * By default the frame is positioned exactly where the drag element is, so |
---|
2837 | * we use the cursor offset provided by Ext.dd.DD. Another option that works only if |
---|
2838 | * you do not have constraints on the obj is to have the drag frame centered |
---|
2839 | * around the cursor. Set centerFrame to true for this effect. |
---|
2840 | * @property centerFrame |
---|
2841 | * @type boolean |
---|
2842 | */ |
---|
2843 | centerFrame: false, |
---|
2844 | |
---|
2845 | /** |
---|
2846 | * Creates the proxy element if it does not yet exist |
---|
2847 | * @method createFrame |
---|
2848 | */ |
---|
2849 | createFrame: function() { |
---|
2850 | var self = this; |
---|
2851 | var body = document.body; |
---|
2852 | |
---|
2853 | if (!body || !body.firstChild) { |
---|
2854 | setTimeout( function() { self.createFrame(); }, 50 ); |
---|
2855 | return; |
---|
2856 | } |
---|
2857 | |
---|
2858 | var div = this.getDragEl(); |
---|
2859 | |
---|
2860 | if (!div) { |
---|
2861 | div = document.createElement("div"); |
---|
2862 | div.id = this.dragElId; |
---|
2863 | var s = div.style; |
---|
2864 | |
---|
2865 | s.position = "absolute"; |
---|
2866 | s.visibility = "hidden"; |
---|
2867 | s.cursor = "move"; |
---|
2868 | s.border = "2px solid #aaa"; |
---|
2869 | s.zIndex = 999; |
---|
2870 | |
---|
2871 | // appendChild can blow up IE if invoked prior to the window load event |
---|
2872 | // while rendering a table. It is possible there are other scenarios |
---|
2873 | // that would cause this to happen as well. |
---|
2874 | body.insertBefore(div, body.firstChild); |
---|
2875 | } |
---|
2876 | }, |
---|
2877 | |
---|
2878 | /** |
---|
2879 | * Initialization for the drag frame element. Must be called in the |
---|
2880 | * constructor of all subclasses |
---|
2881 | * @method initFrame |
---|
2882 | */ |
---|
2883 | initFrame: function() { |
---|
2884 | this.createFrame(); |
---|
2885 | }, |
---|
2886 | |
---|
2887 | applyConfig: function() { |
---|
2888 | Ext.dd.DDProxy.superclass.applyConfig.call(this); |
---|
2889 | |
---|
2890 | this.resizeFrame = (this.config.resizeFrame !== false); |
---|
2891 | this.centerFrame = (this.config.centerFrame); |
---|
2892 | this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId); |
---|
2893 | }, |
---|
2894 | |
---|
2895 | /** |
---|
2896 | * Resizes the drag frame to the dimensions of the clicked object, positions |
---|
2897 | * it over the object, and finally displays it |
---|
2898 | * @method showFrame |
---|
2899 | * @param {int} iPageX X click position |
---|
2900 | * @param {int} iPageY Y click position |
---|
2901 | * @private |
---|
2902 | */ |
---|
2903 | showFrame: function(iPageX, iPageY) { |
---|
2904 | var el = this.getEl(); |
---|
2905 | var dragEl = this.getDragEl(); |
---|
2906 | var s = dragEl.style; |
---|
2907 | |
---|
2908 | this._resizeProxy(); |
---|
2909 | |
---|
2910 | if (this.centerFrame) { |
---|
2911 | this.setDelta( Math.round(parseInt(s.width, 10)/2), |
---|
2912 | Math.round(parseInt(s.height, 10)/2) ); |
---|
2913 | } |
---|
2914 | |
---|
2915 | this.setDragElPos(iPageX, iPageY); |
---|
2916 | |
---|
2917 | Ext.fly(dragEl).show(); |
---|
2918 | }, |
---|
2919 | |
---|
2920 | /** |
---|
2921 | * The proxy is automatically resized to the dimensions of the linked |
---|
2922 | * element when a drag is initiated, unless resizeFrame is set to false |
---|
2923 | * @method _resizeProxy |
---|
2924 | * @private |
---|
2925 | */ |
---|
2926 | _resizeProxy: function() { |
---|
2927 | if (this.resizeFrame) { |
---|
2928 | var el = this.getEl(); |
---|
2929 | Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight); |
---|
2930 | } |
---|
2931 | }, |
---|
2932 | |
---|
2933 | // overrides Ext.dd.DragDrop |
---|
2934 | b4MouseDown: function(e) { |
---|
2935 | var x = e.getPageX(); |
---|
2936 | var y = e.getPageY(); |
---|
2937 | this.autoOffset(x, y); |
---|
2938 | this.setDragElPos(x, y); |
---|
2939 | }, |
---|
2940 | |
---|
2941 | // overrides Ext.dd.DragDrop |
---|
2942 | b4StartDrag: function(x, y) { |
---|
2943 | // show the drag frame |
---|
2944 | this.showFrame(x, y); |
---|
2945 | }, |
---|
2946 | |
---|
2947 | // overrides Ext.dd.DragDrop |
---|
2948 | b4EndDrag: function(e) { |
---|
2949 | Ext.fly(this.getDragEl()).hide(); |
---|
2950 | }, |
---|
2951 | |
---|
2952 | // overrides Ext.dd.DragDrop |
---|
2953 | // By default we try to move the element to the last location of the frame. |
---|
2954 | // This is so that the default behavior mirrors that of Ext.dd.DD. |
---|
2955 | endDrag: function(e) { |
---|
2956 | |
---|
2957 | var lel = this.getEl(); |
---|
2958 | var del = this.getDragEl(); |
---|
2959 | |
---|
2960 | // Show the drag frame briefly so we can get its position |
---|
2961 | del.style.visibility = ""; |
---|
2962 | |
---|
2963 | this.beforeMove(); |
---|
2964 | // Hide the linked element before the move to get around a Safari |
---|
2965 | // rendering bug. |
---|
2966 | lel.style.visibility = "hidden"; |
---|
2967 | Ext.dd.DDM.moveToEl(lel, del); |
---|
2968 | del.style.visibility = "hidden"; |
---|
2969 | lel.style.visibility = ""; |
---|
2970 | |
---|
2971 | this.afterDrag(); |
---|
2972 | }, |
---|
2973 | |
---|
2974 | beforeMove : function(){ |
---|
2975 | |
---|
2976 | }, |
---|
2977 | |
---|
2978 | afterDrag : function(){ |
---|
2979 | |
---|
2980 | }, |
---|
2981 | |
---|
2982 | toString: function() { |
---|
2983 | return ("DDProxy " + this.id); |
---|
2984 | } |
---|
2985 | |
---|
2986 | }); |
---|
2987 | /** |
---|
2988 | * @class Ext.dd.DDTarget |
---|
2989 | * A DragDrop implementation that does not move, but can be a drop |
---|
2990 | * target. You would get the same result by simply omitting implementation |
---|
2991 | * for the event callbacks, but this way we reduce the processing cost of the |
---|
2992 | * event listener and the callbacks. |
---|
2993 | * @extends Ext.dd.DragDrop |
---|
2994 | * @constructor |
---|
2995 | * @param {String} id the id of the element that is a drop target |
---|
2996 | * @param {String} sGroup the group of related DragDrop objects |
---|
2997 | * @param {object} config an object containing configurable attributes |
---|
2998 | * Valid properties for DDTarget in addition to those in |
---|
2999 | * DragDrop: |
---|
3000 | * none |
---|
3001 | */ |
---|
3002 | Ext.dd.DDTarget = function(id, sGroup, config) { |
---|
3003 | if (id) { |
---|
3004 | this.initTarget(id, sGroup, config); |
---|
3005 | } |
---|
3006 | }; |
---|
3007 | |
---|
3008 | // Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop(); |
---|
3009 | Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, { |
---|
3010 | /** |
---|
3011 | * @hide |
---|
3012 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3013 | * @method |
---|
3014 | */ |
---|
3015 | getDragEl: Ext.emptyFn, |
---|
3016 | /** |
---|
3017 | * @hide |
---|
3018 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3019 | * @method |
---|
3020 | */ |
---|
3021 | isValidHandleChild: Ext.emptyFn, |
---|
3022 | /** |
---|
3023 | * @hide |
---|
3024 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3025 | * @method |
---|
3026 | */ |
---|
3027 | startDrag: Ext.emptyFn, |
---|
3028 | /** |
---|
3029 | * @hide |
---|
3030 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3031 | * @method |
---|
3032 | */ |
---|
3033 | endDrag: Ext.emptyFn, |
---|
3034 | /** |
---|
3035 | * @hide |
---|
3036 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3037 | * @method |
---|
3038 | */ |
---|
3039 | onDrag: Ext.emptyFn, |
---|
3040 | /** |
---|
3041 | * @hide |
---|
3042 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3043 | * @method |
---|
3044 | */ |
---|
3045 | onDragDrop: Ext.emptyFn, |
---|
3046 | /** |
---|
3047 | * @hide |
---|
3048 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3049 | * @method |
---|
3050 | */ |
---|
3051 | onDragEnter: Ext.emptyFn, |
---|
3052 | /** |
---|
3053 | * @hide |
---|
3054 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3055 | * @method |
---|
3056 | */ |
---|
3057 | onDragOut: Ext.emptyFn, |
---|
3058 | /** |
---|
3059 | * @hide |
---|
3060 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3061 | * @method |
---|
3062 | */ |
---|
3063 | onDragOver: Ext.emptyFn, |
---|
3064 | /** |
---|
3065 | * @hide |
---|
3066 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3067 | * @method |
---|
3068 | */ |
---|
3069 | onInvalidDrop: Ext.emptyFn, |
---|
3070 | /** |
---|
3071 | * @hide |
---|
3072 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3073 | * @method |
---|
3074 | */ |
---|
3075 | onMouseDown: Ext.emptyFn, |
---|
3076 | /** |
---|
3077 | * @hide |
---|
3078 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3079 | * @method |
---|
3080 | */ |
---|
3081 | onMouseUp: Ext.emptyFn, |
---|
3082 | /** |
---|
3083 | * @hide |
---|
3084 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3085 | * @method |
---|
3086 | */ |
---|
3087 | setXConstraint: Ext.emptyFn, |
---|
3088 | /** |
---|
3089 | * @hide |
---|
3090 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3091 | * @method |
---|
3092 | */ |
---|
3093 | setYConstraint: Ext.emptyFn, |
---|
3094 | /** |
---|
3095 | * @hide |
---|
3096 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3097 | * @method |
---|
3098 | */ |
---|
3099 | resetConstraints: Ext.emptyFn, |
---|
3100 | /** |
---|
3101 | * @hide |
---|
3102 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3103 | * @method |
---|
3104 | */ |
---|
3105 | clearConstraints: Ext.emptyFn, |
---|
3106 | /** |
---|
3107 | * @hide |
---|
3108 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3109 | * @method |
---|
3110 | */ |
---|
3111 | clearTicks: Ext.emptyFn, |
---|
3112 | /** |
---|
3113 | * @hide |
---|
3114 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3115 | * @method |
---|
3116 | */ |
---|
3117 | setInitPosition: Ext.emptyFn, |
---|
3118 | /** |
---|
3119 | * @hide |
---|
3120 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3121 | * @method |
---|
3122 | */ |
---|
3123 | setDragElId: Ext.emptyFn, |
---|
3124 | /** |
---|
3125 | * @hide |
---|
3126 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3127 | * @method |
---|
3128 | */ |
---|
3129 | setHandleElId: Ext.emptyFn, |
---|
3130 | /** |
---|
3131 | * @hide |
---|
3132 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3133 | * @method |
---|
3134 | */ |
---|
3135 | setOuterHandleElId: Ext.emptyFn, |
---|
3136 | /** |
---|
3137 | * @hide |
---|
3138 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3139 | * @method |
---|
3140 | */ |
---|
3141 | addInvalidHandleClass: Ext.emptyFn, |
---|
3142 | /** |
---|
3143 | * @hide |
---|
3144 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3145 | * @method |
---|
3146 | */ |
---|
3147 | addInvalidHandleId: Ext.emptyFn, |
---|
3148 | /** |
---|
3149 | * @hide |
---|
3150 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3151 | * @method |
---|
3152 | */ |
---|
3153 | addInvalidHandleType: Ext.emptyFn, |
---|
3154 | /** |
---|
3155 | * @hide |
---|
3156 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3157 | * @method |
---|
3158 | */ |
---|
3159 | removeInvalidHandleClass: Ext.emptyFn, |
---|
3160 | /** |
---|
3161 | * @hide |
---|
3162 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3163 | * @method |
---|
3164 | */ |
---|
3165 | removeInvalidHandleId: Ext.emptyFn, |
---|
3166 | /** |
---|
3167 | * @hide |
---|
3168 | * Overridden and disabled. A DDTarget does not support being dragged. |
---|
3169 | * @method |
---|
3170 | */ |
---|
3171 | removeInvalidHandleType: Ext.emptyFn, |
---|
3172 | |
---|
3173 | toString: function() { |
---|
3174 | return ("DDTarget " + this.id); |
---|
3175 | } |
---|
3176 | });/** |
---|
3177 | * @class Ext.dd.DragTracker |
---|
3178 | * @extends Ext.util.Observable |
---|
3179 | * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag, |
---|
3180 | * as well as during the drag. This is useful for components such as {@link Ext.slider.MultiSlider}, where there is |
---|
3181 | * an element that can be dragged around to change the Slider's value. |
---|
3182 | * DragTracker provides a series of template methods that should be overridden to provide functionality |
---|
3183 | * in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd. |
---|
3184 | * See {@link Ext.slider.MultiSlider}'s initEvents function for an example implementation. |
---|
3185 | */ |
---|
3186 | Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, { |
---|
3187 | /** |
---|
3188 | * @cfg {Boolean} active |
---|
3189 | * Defaults to <tt>false</tt>. |
---|
3190 | */ |
---|
3191 | active: false, |
---|
3192 | /** |
---|
3193 | * @cfg {Number} tolerance |
---|
3194 | * Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>. |
---|
3195 | */ |
---|
3196 | tolerance: 5, |
---|
3197 | /** |
---|
3198 | * @cfg {Boolean/Number} autoStart |
---|
3199 | * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms. |
---|
3200 | * Specify a Number for the number of milliseconds to defer trigger start. |
---|
3201 | */ |
---|
3202 | autoStart: false, |
---|
3203 | |
---|
3204 | constructor : function(config){ |
---|
3205 | Ext.apply(this, config); |
---|
3206 | this.addEvents( |
---|
3207 | /** |
---|
3208 | * @event mousedown |
---|
3209 | * @param {Object} this |
---|
3210 | * @param {Object} e event object |
---|
3211 | */ |
---|
3212 | 'mousedown', |
---|
3213 | /** |
---|
3214 | * @event mouseup |
---|
3215 | * @param {Object} this |
---|
3216 | * @param {Object} e event object |
---|
3217 | */ |
---|
3218 | 'mouseup', |
---|
3219 | /** |
---|
3220 | * @event mousemove |
---|
3221 | * @param {Object} this |
---|
3222 | * @param {Object} e event object |
---|
3223 | */ |
---|
3224 | 'mousemove', |
---|
3225 | /** |
---|
3226 | * @event dragstart |
---|
3227 | * @param {Object} this |
---|
3228 | * @param {Object} e event object |
---|
3229 | */ |
---|
3230 | 'dragstart', |
---|
3231 | /** |
---|
3232 | * @event dragend |
---|
3233 | * @param {Object} this |
---|
3234 | * @param {Object} e event object |
---|
3235 | */ |
---|
3236 | 'dragend', |
---|
3237 | /** |
---|
3238 | * @event drag |
---|
3239 | * @param {Object} this |
---|
3240 | * @param {Object} e event object |
---|
3241 | */ |
---|
3242 | 'drag' |
---|
3243 | ); |
---|
3244 | |
---|
3245 | this.dragRegion = new Ext.lib.Region(0,0,0,0); |
---|
3246 | |
---|
3247 | if(this.el){ |
---|
3248 | this.initEl(this.el); |
---|
3249 | } |
---|
3250 | Ext.dd.DragTracker.superclass.constructor.call(this, config); |
---|
3251 | }, |
---|
3252 | |
---|
3253 | initEl: function(el){ |
---|
3254 | this.el = Ext.get(el); |
---|
3255 | el.on('mousedown', this.onMouseDown, this, |
---|
3256 | this.delegate ? {delegate: this.delegate} : undefined); |
---|
3257 | }, |
---|
3258 | |
---|
3259 | destroy : function(){ |
---|
3260 | this.el.un('mousedown', this.onMouseDown, this); |
---|
3261 | delete this.el; |
---|
3262 | }, |
---|
3263 | |
---|
3264 | onMouseDown: function(e, target){ |
---|
3265 | if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){ |
---|
3266 | this.startXY = this.lastXY = e.getXY(); |
---|
3267 | this.dragTarget = this.delegate ? target : this.el.dom; |
---|
3268 | if(this.preventDefault !== false){ |
---|
3269 | e.preventDefault(); |
---|
3270 | } |
---|
3271 | Ext.getDoc().on({ |
---|
3272 | scope: this, |
---|
3273 | mouseup: this.onMouseUp, |
---|
3274 | mousemove: this.onMouseMove, |
---|
3275 | selectstart: this.stopSelect |
---|
3276 | }); |
---|
3277 | if(this.autoStart){ |
---|
3278 | this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this, [e]); |
---|
3279 | } |
---|
3280 | } |
---|
3281 | }, |
---|
3282 | |
---|
3283 | onMouseMove: function(e, target){ |
---|
3284 | // HACK: IE hack to see if button was released outside of window. */ |
---|
3285 | if(this.active && Ext.isIE && !e.browserEvent.button){ |
---|
3286 | e.preventDefault(); |
---|
3287 | this.onMouseUp(e); |
---|
3288 | return; |
---|
3289 | } |
---|
3290 | |
---|
3291 | e.preventDefault(); |
---|
3292 | var xy = e.getXY(), s = this.startXY; |
---|
3293 | this.lastXY = xy; |
---|
3294 | if(!this.active){ |
---|
3295 | if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){ |
---|
3296 | this.triggerStart(e); |
---|
3297 | }else{ |
---|
3298 | return; |
---|
3299 | } |
---|
3300 | } |
---|
3301 | this.fireEvent('mousemove', this, e); |
---|
3302 | this.onDrag(e); |
---|
3303 | this.fireEvent('drag', this, e); |
---|
3304 | }, |
---|
3305 | |
---|
3306 | onMouseUp: function(e) { |
---|
3307 | var doc = Ext.getDoc(), |
---|
3308 | wasActive = this.active; |
---|
3309 | |
---|
3310 | doc.un('mousemove', this.onMouseMove, this); |
---|
3311 | doc.un('mouseup', this.onMouseUp, this); |
---|
3312 | doc.un('selectstart', this.stopSelect, this); |
---|
3313 | e.preventDefault(); |
---|
3314 | this.clearStart(); |
---|
3315 | this.active = false; |
---|
3316 | delete this.elRegion; |
---|
3317 | this.fireEvent('mouseup', this, e); |
---|
3318 | if(wasActive){ |
---|
3319 | this.onEnd(e); |
---|
3320 | this.fireEvent('dragend', this, e); |
---|
3321 | } |
---|
3322 | }, |
---|
3323 | |
---|
3324 | triggerStart: function(e) { |
---|
3325 | this.clearStart(); |
---|
3326 | this.active = true; |
---|
3327 | this.onStart(e); |
---|
3328 | this.fireEvent('dragstart', this, e); |
---|
3329 | }, |
---|
3330 | |
---|
3331 | clearStart : function() { |
---|
3332 | if(this.timer){ |
---|
3333 | clearTimeout(this.timer); |
---|
3334 | delete this.timer; |
---|
3335 | } |
---|
3336 | }, |
---|
3337 | |
---|
3338 | stopSelect : function(e) { |
---|
3339 | e.stopEvent(); |
---|
3340 | return false; |
---|
3341 | }, |
---|
3342 | |
---|
3343 | /** |
---|
3344 | * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and |
---|
3345 | * holds the mouse button down. Return false to disallow the drag |
---|
3346 | * @param {Ext.EventObject} e The event object |
---|
3347 | */ |
---|
3348 | onBeforeStart : function(e) { |
---|
3349 | |
---|
3350 | }, |
---|
3351 | |
---|
3352 | /** |
---|
3353 | * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts |
---|
3354 | * (e.g. the user has moved the tracked element beyond the specified tolerance) |
---|
3355 | * @param {Ext.EventObject} e The event object |
---|
3356 | */ |
---|
3357 | onStart : function(xy) { |
---|
3358 | |
---|
3359 | }, |
---|
3360 | |
---|
3361 | /** |
---|
3362 | * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected. |
---|
3363 | * @param {Ext.EventObject} e The event object |
---|
3364 | */ |
---|
3365 | onDrag : function(e) { |
---|
3366 | |
---|
3367 | }, |
---|
3368 | |
---|
3369 | /** |
---|
3370 | * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed |
---|
3371 | * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button) |
---|
3372 | * @param {Ext.EventObject} e The event object |
---|
3373 | */ |
---|
3374 | onEnd : function(e) { |
---|
3375 | |
---|
3376 | }, |
---|
3377 | |
---|
3378 | /** |
---|
3379 | * Returns the drag target |
---|
3380 | * @return {Ext.Element} The element currently being tracked |
---|
3381 | */ |
---|
3382 | getDragTarget : function(){ |
---|
3383 | return this.dragTarget; |
---|
3384 | }, |
---|
3385 | |
---|
3386 | getDragCt : function(){ |
---|
3387 | return this.el; |
---|
3388 | }, |
---|
3389 | |
---|
3390 | getXY : function(constrain){ |
---|
3391 | return constrain ? |
---|
3392 | this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY; |
---|
3393 | }, |
---|
3394 | |
---|
3395 | getOffset : function(constrain){ |
---|
3396 | var xy = this.getXY(constrain), |
---|
3397 | s = this.startXY; |
---|
3398 | return [s[0]-xy[0], s[1]-xy[1]]; |
---|
3399 | }, |
---|
3400 | |
---|
3401 | constrainModes: { |
---|
3402 | 'point' : function(xy){ |
---|
3403 | |
---|
3404 | if(!this.elRegion){ |
---|
3405 | this.elRegion = this.getDragCt().getRegion(); |
---|
3406 | } |
---|
3407 | |
---|
3408 | var dr = this.dragRegion; |
---|
3409 | |
---|
3410 | dr.left = xy[0]; |
---|
3411 | dr.top = xy[1]; |
---|
3412 | dr.right = xy[0]; |
---|
3413 | dr.bottom = xy[1]; |
---|
3414 | |
---|
3415 | dr.constrainTo(this.elRegion); |
---|
3416 | |
---|
3417 | return [dr.left, dr.top]; |
---|
3418 | } |
---|
3419 | } |
---|
3420 | });/** |
---|
3421 | * @class Ext.dd.ScrollManager |
---|
3422 | * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p> |
---|
3423 | * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it, |
---|
3424 | * but you can also override most of the configs per scroll container by adding a |
---|
3425 | * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh}, |
---|
3426 | * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage: |
---|
3427 | * <pre><code> |
---|
3428 | var el = Ext.get('scroll-ct'); |
---|
3429 | el.ddScrollConfig = { |
---|
3430 | vthresh: 50, |
---|
3431 | hthresh: -1, |
---|
3432 | frequency: 100, |
---|
3433 | increment: 200 |
---|
3434 | }; |
---|
3435 | Ext.dd.ScrollManager.register(el); |
---|
3436 | </code></pre> |
---|
3437 | * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b> |
---|
3438 | * @singleton |
---|
3439 | */ |
---|
3440 | Ext.dd.ScrollManager = function(){ |
---|
3441 | var ddm = Ext.dd.DragDropMgr; |
---|
3442 | var els = {}; |
---|
3443 | var dragEl = null; |
---|
3444 | var proc = {}; |
---|
3445 | |
---|
3446 | var onStop = function(e){ |
---|
3447 | dragEl = null; |
---|
3448 | clearProc(); |
---|
3449 | }; |
---|
3450 | |
---|
3451 | var triggerRefresh = function(){ |
---|
3452 | if(ddm.dragCurrent){ |
---|
3453 | ddm.refreshCache(ddm.dragCurrent.groups); |
---|
3454 | } |
---|
3455 | }; |
---|
3456 | |
---|
3457 | var doScroll = function(){ |
---|
3458 | if(ddm.dragCurrent){ |
---|
3459 | var dds = Ext.dd.ScrollManager; |
---|
3460 | var inc = proc.el.ddScrollConfig ? |
---|
3461 | proc.el.ddScrollConfig.increment : dds.increment; |
---|
3462 | if(!dds.animate){ |
---|
3463 | if(proc.el.scroll(proc.dir, inc)){ |
---|
3464 | triggerRefresh(); |
---|
3465 | } |
---|
3466 | }else{ |
---|
3467 | proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh); |
---|
3468 | } |
---|
3469 | } |
---|
3470 | }; |
---|
3471 | |
---|
3472 | var clearProc = function(){ |
---|
3473 | if(proc.id){ |
---|
3474 | clearInterval(proc.id); |
---|
3475 | } |
---|
3476 | proc.id = 0; |
---|
3477 | proc.el = null; |
---|
3478 | proc.dir = ""; |
---|
3479 | }; |
---|
3480 | |
---|
3481 | var startProc = function(el, dir){ |
---|
3482 | clearProc(); |
---|
3483 | proc.el = el; |
---|
3484 | proc.dir = dir; |
---|
3485 | var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined, |
---|
3486 | freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) |
---|
3487 | ? el.ddScrollConfig.frequency |
---|
3488 | : Ext.dd.ScrollManager.frequency; |
---|
3489 | |
---|
3490 | if (group === undefined || ddm.dragCurrent.ddGroup == group) { |
---|
3491 | proc.id = setInterval(doScroll, freq); |
---|
3492 | } |
---|
3493 | }; |
---|
3494 | |
---|
3495 | var onFire = function(e, isDrop){ |
---|
3496 | if(isDrop || !ddm.dragCurrent){ return; } |
---|
3497 | var dds = Ext.dd.ScrollManager; |
---|
3498 | if(!dragEl || dragEl != ddm.dragCurrent){ |
---|
3499 | dragEl = ddm.dragCurrent; |
---|
3500 | // refresh regions on drag start |
---|
3501 | dds.refreshCache(); |
---|
3502 | } |
---|
3503 | |
---|
3504 | var xy = Ext.lib.Event.getXY(e); |
---|
3505 | var pt = new Ext.lib.Point(xy[0], xy[1]); |
---|
3506 | for(var id in els){ |
---|
3507 | var el = els[id], r = el._region; |
---|
3508 | var c = el.ddScrollConfig ? el.ddScrollConfig : dds; |
---|
3509 | if(r && r.contains(pt) && el.isScrollable()){ |
---|
3510 | if(r.bottom - pt.y <= c.vthresh){ |
---|
3511 | if(proc.el != el){ |
---|
3512 | startProc(el, "down"); |
---|
3513 | } |
---|
3514 | return; |
---|
3515 | }else if(r.right - pt.x <= c.hthresh){ |
---|
3516 | if(proc.el != el){ |
---|
3517 | startProc(el, "left"); |
---|
3518 | } |
---|
3519 | return; |
---|
3520 | }else if(pt.y - r.top <= c.vthresh){ |
---|
3521 | if(proc.el != el){ |
---|
3522 | startProc(el, "up"); |
---|
3523 | } |
---|
3524 | return; |
---|
3525 | }else if(pt.x - r.left <= c.hthresh){ |
---|
3526 | if(proc.el != el){ |
---|
3527 | startProc(el, "right"); |
---|
3528 | } |
---|
3529 | return; |
---|
3530 | } |
---|
3531 | } |
---|
3532 | } |
---|
3533 | clearProc(); |
---|
3534 | }; |
---|
3535 | |
---|
3536 | ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm); |
---|
3537 | ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm); |
---|
3538 | |
---|
3539 | return { |
---|
3540 | /** |
---|
3541 | * Registers new overflow element(s) to auto scroll |
---|
3542 | * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either |
---|
3543 | */ |
---|
3544 | register : function(el){ |
---|
3545 | if(Ext.isArray(el)){ |
---|
3546 | for(var i = 0, len = el.length; i < len; i++) { |
---|
3547 | this.register(el[i]); |
---|
3548 | } |
---|
3549 | }else{ |
---|
3550 | el = Ext.get(el); |
---|
3551 | els[el.id] = el; |
---|
3552 | } |
---|
3553 | }, |
---|
3554 | |
---|
3555 | /** |
---|
3556 | * Unregisters overflow element(s) so they are no longer scrolled |
---|
3557 | * @param {Mixed/Array} el The id of or the element to be removed or an array of either |
---|
3558 | */ |
---|
3559 | unregister : function(el){ |
---|
3560 | if(Ext.isArray(el)){ |
---|
3561 | for(var i = 0, len = el.length; i < len; i++) { |
---|
3562 | this.unregister(el[i]); |
---|
3563 | } |
---|
3564 | }else{ |
---|
3565 | el = Ext.get(el); |
---|
3566 | delete els[el.id]; |
---|
3567 | } |
---|
3568 | }, |
---|
3569 | |
---|
3570 | /** |
---|
3571 | * The number of pixels from the top or bottom edge of a container the pointer needs to be to |
---|
3572 | * trigger scrolling (defaults to 25) |
---|
3573 | * @type Number |
---|
3574 | */ |
---|
3575 | vthresh : 25, |
---|
3576 | /** |
---|
3577 | * The number of pixels from the right or left edge of a container the pointer needs to be to |
---|
3578 | * trigger scrolling (defaults to 25) |
---|
3579 | * @type Number |
---|
3580 | */ |
---|
3581 | hthresh : 25, |
---|
3582 | |
---|
3583 | /** |
---|
3584 | * The number of pixels to scroll in each scroll increment (defaults to 100) |
---|
3585 | * @type Number |
---|
3586 | */ |
---|
3587 | increment : 100, |
---|
3588 | |
---|
3589 | /** |
---|
3590 | * The frequency of scrolls in milliseconds (defaults to 500) |
---|
3591 | * @type Number |
---|
3592 | */ |
---|
3593 | frequency : 500, |
---|
3594 | |
---|
3595 | /** |
---|
3596 | * True to animate the scroll (defaults to true) |
---|
3597 | * @type Boolean |
---|
3598 | */ |
---|
3599 | animate: true, |
---|
3600 | |
---|
3601 | /** |
---|
3602 | * The animation duration in seconds - |
---|
3603 | * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4) |
---|
3604 | * @type Number |
---|
3605 | */ |
---|
3606 | animDuration: .4, |
---|
3607 | |
---|
3608 | /** |
---|
3609 | * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined). |
---|
3610 | * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup. |
---|
3611 | * @type String |
---|
3612 | */ |
---|
3613 | ddGroup: undefined, |
---|
3614 | |
---|
3615 | /** |
---|
3616 | * Manually trigger a cache refresh. |
---|
3617 | */ |
---|
3618 | refreshCache : function(){ |
---|
3619 | for(var id in els){ |
---|
3620 | if(typeof els[id] == 'object'){ // for people extending the object prototype |
---|
3621 | els[id]._region = els[id].getRegion(); |
---|
3622 | } |
---|
3623 | } |
---|
3624 | } |
---|
3625 | }; |
---|
3626 | }();/** |
---|
3627 | * @class Ext.dd.Registry |
---|
3628 | * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either |
---|
3629 | * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target. |
---|
3630 | * @singleton |
---|
3631 | */ |
---|
3632 | Ext.dd.Registry = function(){ |
---|
3633 | var elements = {}; |
---|
3634 | var handles = {}; |
---|
3635 | var autoIdSeed = 0; |
---|
3636 | |
---|
3637 | var getId = function(el, autogen){ |
---|
3638 | if(typeof el == "string"){ |
---|
3639 | return el; |
---|
3640 | } |
---|
3641 | var id = el.id; |
---|
3642 | if(!id && autogen !== false){ |
---|
3643 | id = "extdd-" + (++autoIdSeed); |
---|
3644 | el.id = id; |
---|
3645 | } |
---|
3646 | return id; |
---|
3647 | }; |
---|
3648 | |
---|
3649 | return { |
---|
3650 | /** |
---|
3651 | * Resgister a drag drop element |
---|
3652 | * @param {String/HTMLElement} element The id or DOM node to register |
---|
3653 | * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved |
---|
3654 | * in drag drop operations. You can populate this object with any arbitrary properties that your own code |
---|
3655 | * knows how to interpret, plus there are some specific properties known to the Registry that should be |
---|
3656 | * populated in the data object (if applicable): |
---|
3657 | * <pre> |
---|
3658 | Value Description<br /> |
---|
3659 | --------- ------------------------------------------<br /> |
---|
3660 | handles Array of DOM nodes that trigger dragging<br /> |
---|
3661 | for the element being registered<br /> |
---|
3662 | isHandle True if the element passed in triggers<br /> |
---|
3663 | dragging itself, else false |
---|
3664 | </pre> |
---|
3665 | */ |
---|
3666 | register : function(el, data){ |
---|
3667 | data = data || {}; |
---|
3668 | if(typeof el == "string"){ |
---|
3669 | el = document.getElementById(el); |
---|
3670 | } |
---|
3671 | data.ddel = el; |
---|
3672 | elements[getId(el)] = data; |
---|
3673 | if(data.isHandle !== false){ |
---|
3674 | handles[data.ddel.id] = data; |
---|
3675 | } |
---|
3676 | if(data.handles){ |
---|
3677 | var hs = data.handles; |
---|
3678 | for(var i = 0, len = hs.length; i < len; i++){ |
---|
3679 | handles[getId(hs[i])] = data; |
---|
3680 | } |
---|
3681 | } |
---|
3682 | }, |
---|
3683 | |
---|
3684 | /** |
---|
3685 | * Unregister a drag drop element |
---|
3686 | * @param {String/HTMLElement} element The id or DOM node to unregister |
---|
3687 | */ |
---|
3688 | unregister : function(el){ |
---|
3689 | var id = getId(el, false); |
---|
3690 | var data = elements[id]; |
---|
3691 | if(data){ |
---|
3692 | delete elements[id]; |
---|
3693 | if(data.handles){ |
---|
3694 | var hs = data.handles; |
---|
3695 | for(var i = 0, len = hs.length; i < len; i++){ |
---|
3696 | delete handles[getId(hs[i], false)]; |
---|
3697 | } |
---|
3698 | } |
---|
3699 | } |
---|
3700 | }, |
---|
3701 | |
---|
3702 | /** |
---|
3703 | * Returns the handle registered for a DOM Node by id |
---|
3704 | * @param {String/HTMLElement} id The DOM node or id to look up |
---|
3705 | * @return {Object} handle The custom handle data |
---|
3706 | */ |
---|
3707 | getHandle : function(id){ |
---|
3708 | if(typeof id != "string"){ // must be element? |
---|
3709 | id = id.id; |
---|
3710 | } |
---|
3711 | return handles[id]; |
---|
3712 | }, |
---|
3713 | |
---|
3714 | /** |
---|
3715 | * Returns the handle that is registered for the DOM node that is the target of the event |
---|
3716 | * @param {Event} e The event |
---|
3717 | * @return {Object} handle The custom handle data |
---|
3718 | */ |
---|
3719 | getHandleFromEvent : function(e){ |
---|
3720 | var t = Ext.lib.Event.getTarget(e); |
---|
3721 | return t ? handles[t.id] : null; |
---|
3722 | }, |
---|
3723 | |
---|
3724 | /** |
---|
3725 | * Returns a custom data object that is registered for a DOM node by id |
---|
3726 | * @param {String/HTMLElement} id The DOM node or id to look up |
---|
3727 | * @return {Object} data The custom data |
---|
3728 | */ |
---|
3729 | getTarget : function(id){ |
---|
3730 | if(typeof id != "string"){ // must be element? |
---|
3731 | id = id.id; |
---|
3732 | } |
---|
3733 | return elements[id]; |
---|
3734 | }, |
---|
3735 | |
---|
3736 | /** |
---|
3737 | * Returns a custom data object that is registered for the DOM node that is the target of the event |
---|
3738 | * @param {Event} e The event |
---|
3739 | * @return {Object} data The custom data |
---|
3740 | */ |
---|
3741 | getTargetFromEvent : function(e){ |
---|
3742 | var t = Ext.lib.Event.getTarget(e); |
---|
3743 | return t ? elements[t.id] || handles[t.id] : null; |
---|
3744 | } |
---|
3745 | }; |
---|
3746 | }();/** |
---|
3747 | * @class Ext.dd.StatusProxy |
---|
3748 | * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair. This is the |
---|
3749 | * default drag proxy used by all Ext.dd components. |
---|
3750 | * @constructor |
---|
3751 | * @param {Object} config |
---|
3752 | */ |
---|
3753 | Ext.dd.StatusProxy = function(config){ |
---|
3754 | Ext.apply(this, config); |
---|
3755 | this.id = this.id || Ext.id(); |
---|
3756 | this.el = new Ext.Layer({ |
---|
3757 | dh: { |
---|
3758 | id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [ |
---|
3759 | {tag: "div", cls: "x-dd-drop-icon"}, |
---|
3760 | {tag: "div", cls: "x-dd-drag-ghost"} |
---|
3761 | ] |
---|
3762 | }, |
---|
3763 | shadow: !config || config.shadow !== false |
---|
3764 | }); |
---|
3765 | this.ghost = Ext.get(this.el.dom.childNodes[1]); |
---|
3766 | this.dropStatus = this.dropNotAllowed; |
---|
3767 | }; |
---|
3768 | |
---|
3769 | Ext.dd.StatusProxy.prototype = { |
---|
3770 | /** |
---|
3771 | * @cfg {String} dropAllowed |
---|
3772 | * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok"). |
---|
3773 | */ |
---|
3774 | dropAllowed : "x-dd-drop-ok", |
---|
3775 | /** |
---|
3776 | * @cfg {String} dropNotAllowed |
---|
3777 | * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop"). |
---|
3778 | */ |
---|
3779 | dropNotAllowed : "x-dd-drop-nodrop", |
---|
3780 | |
---|
3781 | /** |
---|
3782 | * Updates the proxy's visual element to indicate the status of whether or not drop is allowed |
---|
3783 | * over the current target element. |
---|
3784 | * @param {String} cssClass The css class for the new drop status indicator image |
---|
3785 | */ |
---|
3786 | setStatus : function(cssClass){ |
---|
3787 | cssClass = cssClass || this.dropNotAllowed; |
---|
3788 | if(this.dropStatus != cssClass){ |
---|
3789 | this.el.replaceClass(this.dropStatus, cssClass); |
---|
3790 | this.dropStatus = cssClass; |
---|
3791 | } |
---|
3792 | }, |
---|
3793 | |
---|
3794 | /** |
---|
3795 | * Resets the status indicator to the default dropNotAllowed value |
---|
3796 | * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it |
---|
3797 | */ |
---|
3798 | reset : function(clearGhost){ |
---|
3799 | this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed; |
---|
3800 | this.dropStatus = this.dropNotAllowed; |
---|
3801 | if(clearGhost){ |
---|
3802 | this.ghost.update(""); |
---|
3803 | } |
---|
3804 | }, |
---|
3805 | |
---|
3806 | /** |
---|
3807 | * Updates the contents of the ghost element |
---|
3808 | * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a |
---|
3809 | * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first). |
---|
3810 | */ |
---|
3811 | update : function(html){ |
---|
3812 | if(typeof html == "string"){ |
---|
3813 | this.ghost.update(html); |
---|
3814 | }else{ |
---|
3815 | this.ghost.update(""); |
---|
3816 | html.style.margin = "0"; |
---|
3817 | this.ghost.dom.appendChild(html); |
---|
3818 | } |
---|
3819 | var el = this.ghost.dom.firstChild; |
---|
3820 | if(el){ |
---|
3821 | Ext.fly(el).setStyle('float', 'none'); |
---|
3822 | } |
---|
3823 | }, |
---|
3824 | |
---|
3825 | /** |
---|
3826 | * Returns the underlying proxy {@link Ext.Layer} |
---|
3827 | * @return {Ext.Layer} el |
---|
3828 | */ |
---|
3829 | getEl : function(){ |
---|
3830 | return this.el; |
---|
3831 | }, |
---|
3832 | |
---|
3833 | /** |
---|
3834 | * Returns the ghost element |
---|
3835 | * @return {Ext.Element} el |
---|
3836 | */ |
---|
3837 | getGhost : function(){ |
---|
3838 | return this.ghost; |
---|
3839 | }, |
---|
3840 | |
---|
3841 | /** |
---|
3842 | * Hides the proxy |
---|
3843 | * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them |
---|
3844 | */ |
---|
3845 | hide : function(clear){ |
---|
3846 | this.el.hide(); |
---|
3847 | if(clear){ |
---|
3848 | this.reset(true); |
---|
3849 | } |
---|
3850 | }, |
---|
3851 | |
---|
3852 | /** |
---|
3853 | * Stops the repair animation if it's currently running |
---|
3854 | */ |
---|
3855 | stop : function(){ |
---|
3856 | if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){ |
---|
3857 | this.anim.stop(); |
---|
3858 | } |
---|
3859 | }, |
---|
3860 | |
---|
3861 | /** |
---|
3862 | * Displays this proxy |
---|
3863 | */ |
---|
3864 | show : function(){ |
---|
3865 | this.el.show(); |
---|
3866 | }, |
---|
3867 | |
---|
3868 | /** |
---|
3869 | * Force the Layer to sync its shadow and shim positions to the element |
---|
3870 | */ |
---|
3871 | sync : function(){ |
---|
3872 | this.el.sync(); |
---|
3873 | }, |
---|
3874 | |
---|
3875 | /** |
---|
3876 | * Causes the proxy to return to its position of origin via an animation. Should be called after an |
---|
3877 | * invalid drop operation by the item being dragged. |
---|
3878 | * @param {Array} xy The XY position of the element ([x, y]) |
---|
3879 | * @param {Function} callback The function to call after the repair is complete. |
---|
3880 | * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window. |
---|
3881 | */ |
---|
3882 | repair : function(xy, callback, scope){ |
---|
3883 | this.callback = callback; |
---|
3884 | this.scope = scope; |
---|
3885 | if(xy && this.animRepair !== false){ |
---|
3886 | this.el.addClass("x-dd-drag-repair"); |
---|
3887 | this.el.hideUnders(true); |
---|
3888 | this.anim = this.el.shift({ |
---|
3889 | duration: this.repairDuration || .5, |
---|
3890 | easing: 'easeOut', |
---|
3891 | xy: xy, |
---|
3892 | stopFx: true, |
---|
3893 | callback: this.afterRepair, |
---|
3894 | scope: this |
---|
3895 | }); |
---|
3896 | }else{ |
---|
3897 | this.afterRepair(); |
---|
3898 | } |
---|
3899 | }, |
---|
3900 | |
---|
3901 | // private |
---|
3902 | afterRepair : function(){ |
---|
3903 | this.hide(true); |
---|
3904 | if(typeof this.callback == "function"){ |
---|
3905 | this.callback.call(this.scope || this); |
---|
3906 | } |
---|
3907 | this.callback = null; |
---|
3908 | this.scope = null; |
---|
3909 | }, |
---|
3910 | |
---|
3911 | destroy: function(){ |
---|
3912 | Ext.destroy(this.ghost, this.el); |
---|
3913 | } |
---|
3914 | };/** |
---|
3915 | * @class Ext.dd.DragSource |
---|
3916 | * @extends Ext.dd.DDProxy |
---|
3917 | * A simple class that provides the basic implementation needed to make any element draggable. |
---|
3918 | * @constructor |
---|
3919 | * @param {Mixed} el The container element |
---|
3920 | * @param {Object} config |
---|
3921 | */ |
---|
3922 | Ext.dd.DragSource = function(el, config){ |
---|
3923 | this.el = Ext.get(el); |
---|
3924 | if(!this.dragData){ |
---|
3925 | this.dragData = {}; |
---|
3926 | } |
---|
3927 | |
---|
3928 | Ext.apply(this, config); |
---|
3929 | |
---|
3930 | if(!this.proxy){ |
---|
3931 | this.proxy = new Ext.dd.StatusProxy(); |
---|
3932 | } |
---|
3933 | Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, |
---|
3934 | {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true}); |
---|
3935 | |
---|
3936 | this.dragging = false; |
---|
3937 | }; |
---|
3938 | |
---|
3939 | Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, { |
---|
3940 | /** |
---|
3941 | * @cfg {String} ddGroup |
---|
3942 | * A named drag drop group to which this object belongs. If a group is specified, then this object will only |
---|
3943 | * interact with other drag drop objects in the same group (defaults to undefined). |
---|
3944 | */ |
---|
3945 | /** |
---|
3946 | * @cfg {String} dropAllowed |
---|
3947 | * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok"). |
---|
3948 | */ |
---|
3949 | dropAllowed : "x-dd-drop-ok", |
---|
3950 | /** |
---|
3951 | * @cfg {String} dropNotAllowed |
---|
3952 | * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop"). |
---|
3953 | */ |
---|
3954 | dropNotAllowed : "x-dd-drop-nodrop", |
---|
3955 | |
---|
3956 | /** |
---|
3957 | * Returns the data object associated with this drag source |
---|
3958 | * @return {Object} data An object containing arbitrary data |
---|
3959 | */ |
---|
3960 | getDragData : function(e){ |
---|
3961 | return this.dragData; |
---|
3962 | }, |
---|
3963 | |
---|
3964 | // private |
---|
3965 | onDragEnter : function(e, id){ |
---|
3966 | var target = Ext.dd.DragDropMgr.getDDById(id); |
---|
3967 | this.cachedTarget = target; |
---|
3968 | if(this.beforeDragEnter(target, e, id) !== false){ |
---|
3969 | if(target.isNotifyTarget){ |
---|
3970 | var status = target.notifyEnter(this, e, this.dragData); |
---|
3971 | this.proxy.setStatus(status); |
---|
3972 | }else{ |
---|
3973 | this.proxy.setStatus(this.dropAllowed); |
---|
3974 | } |
---|
3975 | |
---|
3976 | if(this.afterDragEnter){ |
---|
3977 | /** |
---|
3978 | * An empty function by default, but provided so that you can perform a custom action |
---|
3979 | * when the dragged item enters the drop target by providing an implementation. |
---|
3980 | * @param {Ext.dd.DragDrop} target The drop target |
---|
3981 | * @param {Event} e The event object |
---|
3982 | * @param {String} id The id of the dragged element |
---|
3983 | * @method afterDragEnter |
---|
3984 | */ |
---|
3985 | this.afterDragEnter(target, e, id); |
---|
3986 | } |
---|
3987 | } |
---|
3988 | }, |
---|
3989 | |
---|
3990 | /** |
---|
3991 | * An empty function by default, but provided so that you can perform a custom action |
---|
3992 | * before the dragged item enters the drop target and optionally cancel the onDragEnter. |
---|
3993 | * @param {Ext.dd.DragDrop} target The drop target |
---|
3994 | * @param {Event} e The event object |
---|
3995 | * @param {String} id The id of the dragged element |
---|
3996 | * @return {Boolean} isValid True if the drag event is valid, else false to cancel |
---|
3997 | */ |
---|
3998 | beforeDragEnter : function(target, e, id){ |
---|
3999 | return true; |
---|
4000 | }, |
---|
4001 | |
---|
4002 | // private |
---|
4003 | alignElWithMouse: function() { |
---|
4004 | Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments); |
---|
4005 | this.proxy.sync(); |
---|
4006 | }, |
---|
4007 | |
---|
4008 | // private |
---|
4009 | onDragOver : function(e, id){ |
---|
4010 | var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); |
---|
4011 | if(this.beforeDragOver(target, e, id) !== false){ |
---|
4012 | if(target.isNotifyTarget){ |
---|
4013 | var status = target.notifyOver(this, e, this.dragData); |
---|
4014 | this.proxy.setStatus(status); |
---|
4015 | } |
---|
4016 | |
---|
4017 | if(this.afterDragOver){ |
---|
4018 | /** |
---|
4019 | * An empty function by default, but provided so that you can perform a custom action |
---|
4020 | * while the dragged item is over the drop target by providing an implementation. |
---|
4021 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4022 | * @param {Event} e The event object |
---|
4023 | * @param {String} id The id of the dragged element |
---|
4024 | * @method afterDragOver |
---|
4025 | */ |
---|
4026 | this.afterDragOver(target, e, id); |
---|
4027 | } |
---|
4028 | } |
---|
4029 | }, |
---|
4030 | |
---|
4031 | /** |
---|
4032 | * An empty function by default, but provided so that you can perform a custom action |
---|
4033 | * while the dragged item is over the drop target and optionally cancel the onDragOver. |
---|
4034 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4035 | * @param {Event} e The event object |
---|
4036 | * @param {String} id The id of the dragged element |
---|
4037 | * @return {Boolean} isValid True if the drag event is valid, else false to cancel |
---|
4038 | */ |
---|
4039 | beforeDragOver : function(target, e, id){ |
---|
4040 | return true; |
---|
4041 | }, |
---|
4042 | |
---|
4043 | // private |
---|
4044 | onDragOut : function(e, id){ |
---|
4045 | var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); |
---|
4046 | if(this.beforeDragOut(target, e, id) !== false){ |
---|
4047 | if(target.isNotifyTarget){ |
---|
4048 | target.notifyOut(this, e, this.dragData); |
---|
4049 | } |
---|
4050 | this.proxy.reset(); |
---|
4051 | if(this.afterDragOut){ |
---|
4052 | /** |
---|
4053 | * An empty function by default, but provided so that you can perform a custom action |
---|
4054 | * after the dragged item is dragged out of the target without dropping. |
---|
4055 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4056 | * @param {Event} e The event object |
---|
4057 | * @param {String} id The id of the dragged element |
---|
4058 | * @method afterDragOut |
---|
4059 | */ |
---|
4060 | this.afterDragOut(target, e, id); |
---|
4061 | } |
---|
4062 | } |
---|
4063 | this.cachedTarget = null; |
---|
4064 | }, |
---|
4065 | |
---|
4066 | /** |
---|
4067 | * An empty function by default, but provided so that you can perform a custom action before the dragged |
---|
4068 | * item is dragged out of the target without dropping, and optionally cancel the onDragOut. |
---|
4069 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4070 | * @param {Event} e The event object |
---|
4071 | * @param {String} id The id of the dragged element |
---|
4072 | * @return {Boolean} isValid True if the drag event is valid, else false to cancel |
---|
4073 | */ |
---|
4074 | beforeDragOut : function(target, e, id){ |
---|
4075 | return true; |
---|
4076 | }, |
---|
4077 | |
---|
4078 | // private |
---|
4079 | onDragDrop : function(e, id){ |
---|
4080 | var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); |
---|
4081 | if(this.beforeDragDrop(target, e, id) !== false){ |
---|
4082 | if(target.isNotifyTarget){ |
---|
4083 | if(target.notifyDrop(this, e, this.dragData)){ // valid drop? |
---|
4084 | this.onValidDrop(target, e, id); |
---|
4085 | }else{ |
---|
4086 | this.onInvalidDrop(target, e, id); |
---|
4087 | } |
---|
4088 | }else{ |
---|
4089 | this.onValidDrop(target, e, id); |
---|
4090 | } |
---|
4091 | |
---|
4092 | if(this.afterDragDrop){ |
---|
4093 | /** |
---|
4094 | * An empty function by default, but provided so that you can perform a custom action |
---|
4095 | * after a valid drag drop has occurred by providing an implementation. |
---|
4096 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4097 | * @param {Event} e The event object |
---|
4098 | * @param {String} id The id of the dropped element |
---|
4099 | * @method afterDragDrop |
---|
4100 | */ |
---|
4101 | this.afterDragDrop(target, e, id); |
---|
4102 | } |
---|
4103 | } |
---|
4104 | delete this.cachedTarget; |
---|
4105 | }, |
---|
4106 | |
---|
4107 | /** |
---|
4108 | * An empty function by default, but provided so that you can perform a custom action before the dragged |
---|
4109 | * item is dropped onto the target and optionally cancel the onDragDrop. |
---|
4110 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4111 | * @param {Event} e The event object |
---|
4112 | * @param {String} id The id of the dragged element |
---|
4113 | * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel |
---|
4114 | */ |
---|
4115 | beforeDragDrop : function(target, e, id){ |
---|
4116 | return true; |
---|
4117 | }, |
---|
4118 | |
---|
4119 | // private |
---|
4120 | onValidDrop : function(target, e, id){ |
---|
4121 | this.hideProxy(); |
---|
4122 | if(this.afterValidDrop){ |
---|
4123 | /** |
---|
4124 | * An empty function by default, but provided so that you can perform a custom action |
---|
4125 | * after a valid drop has occurred by providing an implementation. |
---|
4126 | * @param {Object} target The target DD |
---|
4127 | * @param {Event} e The event object |
---|
4128 | * @param {String} id The id of the dropped element |
---|
4129 | * @method afterInvalidDrop |
---|
4130 | */ |
---|
4131 | this.afterValidDrop(target, e, id); |
---|
4132 | } |
---|
4133 | }, |
---|
4134 | |
---|
4135 | // private |
---|
4136 | getRepairXY : function(e, data){ |
---|
4137 | return this.el.getXY(); |
---|
4138 | }, |
---|
4139 | |
---|
4140 | // private |
---|
4141 | onInvalidDrop : function(target, e, id){ |
---|
4142 | this.beforeInvalidDrop(target, e, id); |
---|
4143 | if(this.cachedTarget){ |
---|
4144 | if(this.cachedTarget.isNotifyTarget){ |
---|
4145 | this.cachedTarget.notifyOut(this, e, this.dragData); |
---|
4146 | } |
---|
4147 | this.cacheTarget = null; |
---|
4148 | } |
---|
4149 | this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this); |
---|
4150 | |
---|
4151 | if(this.afterInvalidDrop){ |
---|
4152 | /** |
---|
4153 | * An empty function by default, but provided so that you can perform a custom action |
---|
4154 | * after an invalid drop has occurred by providing an implementation. |
---|
4155 | * @param {Event} e The event object |
---|
4156 | * @param {String} id The id of the dropped element |
---|
4157 | * @method afterInvalidDrop |
---|
4158 | */ |
---|
4159 | this.afterInvalidDrop(e, id); |
---|
4160 | } |
---|
4161 | }, |
---|
4162 | |
---|
4163 | // private |
---|
4164 | afterRepair : function(){ |
---|
4165 | if(Ext.enableFx){ |
---|
4166 | this.el.highlight(this.hlColor || "c3daf9"); |
---|
4167 | } |
---|
4168 | this.dragging = false; |
---|
4169 | }, |
---|
4170 | |
---|
4171 | /** |
---|
4172 | * An empty function by default, but provided so that you can perform a custom action after an invalid |
---|
4173 | * drop has occurred. |
---|
4174 | * @param {Ext.dd.DragDrop} target The drop target |
---|
4175 | * @param {Event} e The event object |
---|
4176 | * @param {String} id The id of the dragged element |
---|
4177 | * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel |
---|
4178 | */ |
---|
4179 | beforeInvalidDrop : function(target, e, id){ |
---|
4180 | return true; |
---|
4181 | }, |
---|
4182 | |
---|
4183 | // private |
---|
4184 | handleMouseDown : function(e){ |
---|
4185 | if(this.dragging) { |
---|
4186 | return; |
---|
4187 | } |
---|
4188 | var data = this.getDragData(e); |
---|
4189 | if(data && this.onBeforeDrag(data, e) !== false){ |
---|
4190 | this.dragData = data; |
---|
4191 | this.proxy.stop(); |
---|
4192 | Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments); |
---|
4193 | } |
---|
4194 | }, |
---|
4195 | |
---|
4196 | /** |
---|
4197 | * An empty function by default, but provided so that you can perform a custom action before the initial |
---|
4198 | * drag event begins and optionally cancel it. |
---|
4199 | * @param {Object} data An object containing arbitrary data to be shared with drop targets |
---|
4200 | * @param {Event} e The event object |
---|
4201 | * @return {Boolean} isValid True if the drag event is valid, else false to cancel |
---|
4202 | */ |
---|
4203 | onBeforeDrag : function(data, e){ |
---|
4204 | return true; |
---|
4205 | }, |
---|
4206 | |
---|
4207 | /** |
---|
4208 | * An empty function by default, but provided so that you can perform a custom action once the initial |
---|
4209 | * drag event has begun. The drag cannot be canceled from this function. |
---|
4210 | * @param {Number} x The x position of the click on the dragged object |
---|
4211 | * @param {Number} y The y position of the click on the dragged object |
---|
4212 | */ |
---|
4213 | onStartDrag : Ext.emptyFn, |
---|
4214 | |
---|
4215 | // private override |
---|
4216 | startDrag : function(x, y){ |
---|
4217 | this.proxy.reset(); |
---|
4218 | this.dragging = true; |
---|
4219 | this.proxy.update(""); |
---|
4220 | this.onInitDrag(x, y); |
---|
4221 | this.proxy.show(); |
---|
4222 | }, |
---|
4223 | |
---|
4224 | // private |
---|
4225 | onInitDrag : function(x, y){ |
---|
4226 | var clone = this.el.dom.cloneNode(true); |
---|
4227 | clone.id = Ext.id(); // prevent duplicate ids |
---|
4228 | this.proxy.update(clone); |
---|
4229 | this.onStartDrag(x, y); |
---|
4230 | return true; |
---|
4231 | }, |
---|
4232 | |
---|
4233 | /** |
---|
4234 | * Returns the drag source's underlying {@link Ext.dd.StatusProxy} |
---|
4235 | * @return {Ext.dd.StatusProxy} proxy The StatusProxy |
---|
4236 | */ |
---|
4237 | getProxy : function(){ |
---|
4238 | return this.proxy; |
---|
4239 | }, |
---|
4240 | |
---|
4241 | /** |
---|
4242 | * Hides the drag source's {@link Ext.dd.StatusProxy} |
---|
4243 | */ |
---|
4244 | hideProxy : function(){ |
---|
4245 | this.proxy.hide(); |
---|
4246 | this.proxy.reset(true); |
---|
4247 | this.dragging = false; |
---|
4248 | }, |
---|
4249 | |
---|
4250 | // private |
---|
4251 | triggerCacheRefresh : function(){ |
---|
4252 | Ext.dd.DDM.refreshCache(this.groups); |
---|
4253 | }, |
---|
4254 | |
---|
4255 | // private - override to prevent hiding |
---|
4256 | b4EndDrag: function(e) { |
---|
4257 | }, |
---|
4258 | |
---|
4259 | // private - override to prevent moving |
---|
4260 | endDrag : function(e){ |
---|
4261 | this.onEndDrag(this.dragData, e); |
---|
4262 | }, |
---|
4263 | |
---|
4264 | // private |
---|
4265 | onEndDrag : function(data, e){ |
---|
4266 | }, |
---|
4267 | |
---|
4268 | // private - pin to cursor |
---|
4269 | autoOffset : function(x, y) { |
---|
4270 | this.setDelta(-12, -20); |
---|
4271 | }, |
---|
4272 | |
---|
4273 | destroy: function(){ |
---|
4274 | Ext.dd.DragSource.superclass.destroy.call(this); |
---|
4275 | Ext.destroy(this.proxy); |
---|
4276 | } |
---|
4277 | });/** |
---|
4278 | * @class Ext.dd.DropTarget |
---|
4279 | * @extends Ext.dd.DDTarget |
---|
4280 | * A simple class that provides the basic implementation needed to make any element a drop target that can have |
---|
4281 | * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided. |
---|
4282 | * @constructor |
---|
4283 | * @param {Mixed} el The container element |
---|
4284 | * @param {Object} config |
---|
4285 | */ |
---|
4286 | Ext.dd.DropTarget = Ext.extend(Ext.dd.DDTarget, { |
---|
4287 | |
---|
4288 | constructor : function(el, config){ |
---|
4289 | this.el = Ext.get(el); |
---|
4290 | |
---|
4291 | Ext.apply(this, config); |
---|
4292 | |
---|
4293 | if(this.containerScroll){ |
---|
4294 | Ext.dd.ScrollManager.register(this.el); |
---|
4295 | } |
---|
4296 | |
---|
4297 | Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, |
---|
4298 | {isTarget: true}); |
---|
4299 | }, |
---|
4300 | |
---|
4301 | /** |
---|
4302 | * @cfg {String} ddGroup |
---|
4303 | * A named drag drop group to which this object belongs. If a group is specified, then this object will only |
---|
4304 | * interact with other drag drop objects in the same group (defaults to undefined). |
---|
4305 | */ |
---|
4306 | /** |
---|
4307 | * @cfg {String} overClass |
---|
4308 | * The CSS class applied to the drop target element while the drag source is over it (defaults to ""). |
---|
4309 | */ |
---|
4310 | /** |
---|
4311 | * @cfg {String} dropAllowed |
---|
4312 | * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok"). |
---|
4313 | */ |
---|
4314 | dropAllowed : "x-dd-drop-ok", |
---|
4315 | /** |
---|
4316 | * @cfg {String} dropNotAllowed |
---|
4317 | * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop"). |
---|
4318 | */ |
---|
4319 | dropNotAllowed : "x-dd-drop-nodrop", |
---|
4320 | |
---|
4321 | // private |
---|
4322 | isTarget : true, |
---|
4323 | |
---|
4324 | // private |
---|
4325 | isNotifyTarget : true, |
---|
4326 | |
---|
4327 | /** |
---|
4328 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the |
---|
4329 | * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element |
---|
4330 | * and returns the dropAllowed config value. This method should be overridden if drop validation is required. |
---|
4331 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target |
---|
4332 | * @param {Event} e The event |
---|
4333 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4334 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4335 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4336 | */ |
---|
4337 | notifyEnter : function(dd, e, data){ |
---|
4338 | if(this.overClass){ |
---|
4339 | this.el.addClass(this.overClass); |
---|
4340 | } |
---|
4341 | return this.dropAllowed; |
---|
4342 | }, |
---|
4343 | |
---|
4344 | /** |
---|
4345 | * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target. |
---|
4346 | * This method will be called on every mouse movement while the drag source is over the drop target. |
---|
4347 | * This default implementation simply returns the dropAllowed config value. |
---|
4348 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target |
---|
4349 | * @param {Event} e The event |
---|
4350 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4351 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4352 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4353 | */ |
---|
4354 | notifyOver : function(dd, e, data){ |
---|
4355 | return this.dropAllowed; |
---|
4356 | }, |
---|
4357 | |
---|
4358 | /** |
---|
4359 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged |
---|
4360 | * out of the target without dropping. This default implementation simply removes the CSS class specified by |
---|
4361 | * overClass (if any) from the drop element. |
---|
4362 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target |
---|
4363 | * @param {Event} e The event |
---|
4364 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4365 | */ |
---|
4366 | notifyOut : function(dd, e, data){ |
---|
4367 | if(this.overClass){ |
---|
4368 | this.el.removeClass(this.overClass); |
---|
4369 | } |
---|
4370 | }, |
---|
4371 | |
---|
4372 | /** |
---|
4373 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has |
---|
4374 | * been dropped on it. This method has no default implementation and returns false, so you must provide an |
---|
4375 | * implementation that does something to process the drop event and returns true so that the drag source's |
---|
4376 | * repair action does not run. |
---|
4377 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target |
---|
4378 | * @param {Event} e The event |
---|
4379 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4380 | * @return {Boolean} True if the drop was valid, else false |
---|
4381 | */ |
---|
4382 | notifyDrop : function(dd, e, data){ |
---|
4383 | return false; |
---|
4384 | }, |
---|
4385 | |
---|
4386 | destroy : function(){ |
---|
4387 | Ext.dd.DropTarget.superclass.destroy.call(this); |
---|
4388 | if(this.containerScroll){ |
---|
4389 | Ext.dd.ScrollManager.unregister(this.el); |
---|
4390 | } |
---|
4391 | } |
---|
4392 | });/** |
---|
4393 | * @class Ext.dd.DragZone |
---|
4394 | * @extends Ext.dd.DragSource |
---|
4395 | * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p> |
---|
4396 | * <p>This class does not move the drag target nodes, but a proxy element which may contain |
---|
4397 | * any DOM structure you wish. The DOM element to show in the proxy is provided by either a |
---|
4398 | * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p> |
---|
4399 | * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some |
---|
4400 | * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class |
---|
4401 | * is the most efficient way to "activate" those nodes.</p> |
---|
4402 | * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}. |
---|
4403 | * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure |
---|
4404 | * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed |
---|
4405 | * mouse event to see if it has taken place within an element, or class of elements. This is easily done |
---|
4406 | * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a |
---|
4407 | * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following |
---|
4408 | * technique. Knowledge of the use of the DataView is required:</p><pre><code> |
---|
4409 | myDataView.on('render', function(v) { |
---|
4410 | myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), { |
---|
4411 | |
---|
4412 | // On receipt of a mousedown event, see if it is within a DataView node. |
---|
4413 | // Return a drag data object if so. |
---|
4414 | getDragData: function(e) { |
---|
4415 | |
---|
4416 | // Use the DataView's own itemSelector (a mandatory property) to |
---|
4417 | // test if the mousedown is within one of the DataView's nodes. |
---|
4418 | var sourceEl = e.getTarget(v.itemSelector, 10); |
---|
4419 | |
---|
4420 | // If the mousedown is within a DataView node, clone the node to produce |
---|
4421 | // a ddel element for use by the drag proxy. Also add application data |
---|
4422 | // to the returned data object. |
---|
4423 | if (sourceEl) { |
---|
4424 | d = sourceEl.cloneNode(true); |
---|
4425 | d.id = Ext.id(); |
---|
4426 | return { |
---|
4427 | ddel: d, |
---|
4428 | sourceEl: sourceEl, |
---|
4429 | repairXY: Ext.fly(sourceEl).getXY(), |
---|
4430 | sourceStore: v.store, |
---|
4431 | draggedRecord: v.{@link Ext.DataView#getRecord getRecord}(sourceEl) |
---|
4432 | } |
---|
4433 | } |
---|
4434 | }, |
---|
4435 | |
---|
4436 | // Provide coordinates for the proxy to slide back to on failed drag. |
---|
4437 | // This is the original XY coordinates of the draggable element captured |
---|
4438 | // in the getDragData method. |
---|
4439 | getRepairXY: function() { |
---|
4440 | return this.dragData.repairXY; |
---|
4441 | } |
---|
4442 | }); |
---|
4443 | });</code></pre> |
---|
4444 | * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which |
---|
4445 | * cooperates with this DragZone. |
---|
4446 | * @constructor |
---|
4447 | * @param {Mixed} el The container element |
---|
4448 | * @param {Object} config |
---|
4449 | */ |
---|
4450 | Ext.dd.DragZone = Ext.extend(Ext.dd.DragSource, { |
---|
4451 | |
---|
4452 | constructor : function(el, config){ |
---|
4453 | Ext.dd.DragZone.superclass.constructor.call(this, el, config); |
---|
4454 | if(this.containerScroll){ |
---|
4455 | Ext.dd.ScrollManager.register(this.el); |
---|
4456 | } |
---|
4457 | }, |
---|
4458 | |
---|
4459 | /** |
---|
4460 | * This property contains the data representing the dragged object. This data is set up by the implementation |
---|
4461 | * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain |
---|
4462 | * any other data according to the application's needs. |
---|
4463 | * @type Object |
---|
4464 | * @property dragData |
---|
4465 | */ |
---|
4466 | /** |
---|
4467 | * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager |
---|
4468 | * for auto scrolling during drag operations. |
---|
4469 | */ |
---|
4470 | /** |
---|
4471 | * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair |
---|
4472 | * method after a failed drop (defaults to "c3daf9" - light blue) |
---|
4473 | */ |
---|
4474 | |
---|
4475 | /** |
---|
4476 | * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry} |
---|
4477 | * for a valid target to drag based on the mouse down. Override this method |
---|
4478 | * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned |
---|
4479 | * object has a "ddel" attribute (with an HTML Element) for other functions to work. |
---|
4480 | * @param {EventObject} e The mouse down event |
---|
4481 | * @return {Object} The dragData |
---|
4482 | */ |
---|
4483 | getDragData : function(e){ |
---|
4484 | return Ext.dd.Registry.getHandleFromEvent(e); |
---|
4485 | }, |
---|
4486 | |
---|
4487 | /** |
---|
4488 | * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the |
---|
4489 | * this.dragData.ddel |
---|
4490 | * @param {Number} x The x position of the click on the dragged object |
---|
4491 | * @param {Number} y The y position of the click on the dragged object |
---|
4492 | * @return {Boolean} true to continue the drag, false to cancel |
---|
4493 | */ |
---|
4494 | onInitDrag : function(x, y){ |
---|
4495 | this.proxy.update(this.dragData.ddel.cloneNode(true)); |
---|
4496 | this.onStartDrag(x, y); |
---|
4497 | return true; |
---|
4498 | }, |
---|
4499 | |
---|
4500 | /** |
---|
4501 | * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel |
---|
4502 | */ |
---|
4503 | afterRepair : function(){ |
---|
4504 | if(Ext.enableFx){ |
---|
4505 | Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9"); |
---|
4506 | } |
---|
4507 | this.dragging = false; |
---|
4508 | }, |
---|
4509 | |
---|
4510 | /** |
---|
4511 | * Called before a repair of an invalid drop to get the XY to animate to. By default returns |
---|
4512 | * the XY of this.dragData.ddel |
---|
4513 | * @param {EventObject} e The mouse up event |
---|
4514 | * @return {Array} The xy location (e.g. [100, 200]) |
---|
4515 | */ |
---|
4516 | getRepairXY : function(e){ |
---|
4517 | return Ext.Element.fly(this.dragData.ddel).getXY(); |
---|
4518 | }, |
---|
4519 | |
---|
4520 | destroy : function(){ |
---|
4521 | Ext.dd.DragZone.superclass.destroy.call(this); |
---|
4522 | if(this.containerScroll){ |
---|
4523 | Ext.dd.ScrollManager.unregister(this.el); |
---|
4524 | } |
---|
4525 | } |
---|
4526 | });/** |
---|
4527 | * @class Ext.dd.DropZone |
---|
4528 | * @extends Ext.dd.DropTarget |
---|
4529 | * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p> |
---|
4530 | * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}. |
---|
4531 | * However a simpler way to allow a DropZone to manage any number of target elements is to configure the |
---|
4532 | * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed |
---|
4533 | * mouse event to see if it has taken place within an element, or class of elements. This is easily done |
---|
4534 | * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a |
---|
4535 | * {@link Ext.DomQuery} selector.</p> |
---|
4536 | * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over |
---|
4537 | * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver}, |
---|
4538 | * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations |
---|
4539 | * of these methods to provide application-specific behaviour for these events to update both |
---|
4540 | * application state, and UI state.</p> |
---|
4541 | * <p>For example to make a GridPanel a cooperating target with the example illustrated in |
---|
4542 | * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code> |
---|
4543 | myGridPanel.on('render', function() { |
---|
4544 | myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, { |
---|
4545 | |
---|
4546 | // If the mouse is over a grid row, return that node. This is |
---|
4547 | // provided as the "target" parameter in all "onNodeXXXX" node event handling functions |
---|
4548 | getTargetFromEvent: function(e) { |
---|
4549 | return e.getTarget(myGridPanel.getView().rowSelector); |
---|
4550 | }, |
---|
4551 | |
---|
4552 | // On entry into a target node, highlight that node. |
---|
4553 | onNodeEnter : function(target, dd, e, data){ |
---|
4554 | Ext.fly(target).addClass('my-row-highlight-class'); |
---|
4555 | }, |
---|
4556 | |
---|
4557 | // On exit from a target node, unhighlight that node. |
---|
4558 | onNodeOut : function(target, dd, e, data){ |
---|
4559 | Ext.fly(target).removeClass('my-row-highlight-class'); |
---|
4560 | }, |
---|
4561 | |
---|
4562 | // While over a target node, return the default drop allowed class which |
---|
4563 | // places a "tick" icon into the drag proxy. |
---|
4564 | onNodeOver : function(target, dd, e, data){ |
---|
4565 | return Ext.dd.DropZone.prototype.dropAllowed; |
---|
4566 | }, |
---|
4567 | |
---|
4568 | // On node drop we can interrogate the target to find the underlying |
---|
4569 | // application object that is the real target of the dragged data. |
---|
4570 | // In this case, it is a Record in the GridPanel's Store. |
---|
4571 | // We can use the data set up by the DragZone's getDragData method to read |
---|
4572 | // any data we decided to attach in the DragZone's getDragData method. |
---|
4573 | onNodeDrop : function(target, dd, e, data){ |
---|
4574 | var rowIndex = myGridPanel.getView().findRowIndex(target); |
---|
4575 | var r = myGridPanel.getStore().getAt(rowIndex); |
---|
4576 | Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id + |
---|
4577 | ' on Record id ' + r.id); |
---|
4578 | return true; |
---|
4579 | } |
---|
4580 | }); |
---|
4581 | } |
---|
4582 | </code></pre> |
---|
4583 | * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which |
---|
4584 | * cooperates with this DropZone. |
---|
4585 | * @constructor |
---|
4586 | * @param {Mixed} el The container element |
---|
4587 | * @param {Object} config |
---|
4588 | */ |
---|
4589 | Ext.dd.DropZone = function(el, config){ |
---|
4590 | Ext.dd.DropZone.superclass.constructor.call(this, el, config); |
---|
4591 | }; |
---|
4592 | |
---|
4593 | Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, { |
---|
4594 | /** |
---|
4595 | * Returns a custom data object associated with the DOM node that is the target of the event. By default |
---|
4596 | * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to |
---|
4597 | * provide your own custom lookup. |
---|
4598 | * @param {Event} e The event |
---|
4599 | * @return {Object} data The custom data |
---|
4600 | */ |
---|
4601 | getTargetFromEvent : function(e){ |
---|
4602 | return Ext.dd.Registry.getTargetFromEvent(e); |
---|
4603 | }, |
---|
4604 | |
---|
4605 | /** |
---|
4606 | * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node |
---|
4607 | * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}. |
---|
4608 | * This method has no default implementation and should be overridden to provide |
---|
4609 | * node-specific processing if necessary. |
---|
4610 | * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from |
---|
4611 | * {@link #getTargetFromEvent} for this node) |
---|
4612 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4613 | * @param {Event} e The event |
---|
4614 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4615 | */ |
---|
4616 | onNodeEnter : function(n, dd, e, data){ |
---|
4617 | |
---|
4618 | }, |
---|
4619 | |
---|
4620 | /** |
---|
4621 | * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node |
---|
4622 | * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}. |
---|
4623 | * The default implementation returns this.dropNotAllowed, so it should be |
---|
4624 | * overridden to provide the proper feedback. |
---|
4625 | * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from |
---|
4626 | * {@link #getTargetFromEvent} for this node) |
---|
4627 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4628 | * @param {Event} e The event |
---|
4629 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4630 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4631 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4632 | */ |
---|
4633 | onNodeOver : function(n, dd, e, data){ |
---|
4634 | return this.dropAllowed; |
---|
4635 | }, |
---|
4636 | |
---|
4637 | /** |
---|
4638 | * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of |
---|
4639 | * the drop node without dropping. This method has no default implementation and should be overridden to provide |
---|
4640 | * node-specific processing if necessary. |
---|
4641 | * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from |
---|
4642 | * {@link #getTargetFromEvent} for this node) |
---|
4643 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4644 | * @param {Event} e The event |
---|
4645 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4646 | */ |
---|
4647 | onNodeOut : function(n, dd, e, data){ |
---|
4648 | |
---|
4649 | }, |
---|
4650 | |
---|
4651 | /** |
---|
4652 | * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto |
---|
4653 | * the drop node. The default implementation returns false, so it should be overridden to provide the |
---|
4654 | * appropriate processing of the drop event and return true so that the drag source's repair action does not run. |
---|
4655 | * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from |
---|
4656 | * {@link #getTargetFromEvent} for this node) |
---|
4657 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4658 | * @param {Event} e The event |
---|
4659 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4660 | * @return {Boolean} True if the drop was valid, else false |
---|
4661 | */ |
---|
4662 | onNodeDrop : function(n, dd, e, data){ |
---|
4663 | return false; |
---|
4664 | }, |
---|
4665 | |
---|
4666 | /** |
---|
4667 | * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it, |
---|
4668 | * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so |
---|
4669 | * it should be overridden to provide the proper feedback if necessary. |
---|
4670 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4671 | * @param {Event} e The event |
---|
4672 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4673 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4674 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4675 | */ |
---|
4676 | onContainerOver : function(dd, e, data){ |
---|
4677 | return this.dropNotAllowed; |
---|
4678 | }, |
---|
4679 | |
---|
4680 | /** |
---|
4681 | * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it, |
---|
4682 | * but not on any of its registered drop nodes. The default implementation returns false, so it should be |
---|
4683 | * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to |
---|
4684 | * be able to accept drops. It should return true when valid so that the drag source's repair action does not run. |
---|
4685 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4686 | * @param {Event} e The event |
---|
4687 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4688 | * @return {Boolean} True if the drop was valid, else false |
---|
4689 | */ |
---|
4690 | onContainerDrop : function(dd, e, data){ |
---|
4691 | return false; |
---|
4692 | }, |
---|
4693 | |
---|
4694 | /** |
---|
4695 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over |
---|
4696 | * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop |
---|
4697 | * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops |
---|
4698 | * you should override this method and provide a custom implementation. |
---|
4699 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4700 | * @param {Event} e The event |
---|
4701 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4702 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4703 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4704 | */ |
---|
4705 | notifyEnter : function(dd, e, data){ |
---|
4706 | return this.dropNotAllowed; |
---|
4707 | }, |
---|
4708 | |
---|
4709 | /** |
---|
4710 | * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone. |
---|
4711 | * This method will be called on every mouse movement while the drag source is over the drop zone. |
---|
4712 | * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically |
---|
4713 | * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits |
---|
4714 | * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a |
---|
4715 | * registered node, it will call {@link #onContainerOver}. |
---|
4716 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4717 | * @param {Event} e The event |
---|
4718 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4719 | * @return {String} status The CSS class that communicates the drop status back to the source so that the |
---|
4720 | * underlying {@link Ext.dd.StatusProxy} can be updated |
---|
4721 | */ |
---|
4722 | notifyOver : function(dd, e, data){ |
---|
4723 | var n = this.getTargetFromEvent(e); |
---|
4724 | if(!n){ // not over valid drop target |
---|
4725 | if(this.lastOverNode){ |
---|
4726 | this.onNodeOut(this.lastOverNode, dd, e, data); |
---|
4727 | this.lastOverNode = null; |
---|
4728 | } |
---|
4729 | return this.onContainerOver(dd, e, data); |
---|
4730 | } |
---|
4731 | if(this.lastOverNode != n){ |
---|
4732 | if(this.lastOverNode){ |
---|
4733 | this.onNodeOut(this.lastOverNode, dd, e, data); |
---|
4734 | } |
---|
4735 | this.onNodeEnter(n, dd, e, data); |
---|
4736 | this.lastOverNode = n; |
---|
4737 | } |
---|
4738 | return this.onNodeOver(n, dd, e, data); |
---|
4739 | }, |
---|
4740 | |
---|
4741 | /** |
---|
4742 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged |
---|
4743 | * out of the zone without dropping. If the drag source is currently over a registered node, the notification |
---|
4744 | * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored. |
---|
4745 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target |
---|
4746 | * @param {Event} e The event |
---|
4747 | * @param {Object} data An object containing arbitrary data supplied by the drag zone |
---|
4748 | */ |
---|
4749 | notifyOut : function(dd, e, data){ |
---|
4750 | if(this.lastOverNode){ |
---|
4751 | this.onNodeOut(this.lastOverNode, dd, e, data); |
---|
4752 | this.lastOverNode = null; |
---|
4753 | } |
---|
4754 | }, |
---|
4755 | |
---|
4756 | /** |
---|
4757 | * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has |
---|
4758 | * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there |
---|
4759 | * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling, |
---|
4760 | * otherwise it will call {@link #onContainerDrop}. |
---|
4761 | * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone |
---|
4762 | * @param {Event} e The event |
---|
4763 | * @param {Object} data An object containing arbitrary data supplied by the drag source |
---|
4764 | * @return {Boolean} True if the drop was valid, else false |
---|
4765 | */ |
---|
4766 | notifyDrop : function(dd, e, data){ |
---|
4767 | if(this.lastOverNode){ |
---|
4768 | this.onNodeOut(this.lastOverNode, dd, e, data); |
---|
4769 | this.lastOverNode = null; |
---|
4770 | } |
---|
4771 | var n = this.getTargetFromEvent(e); |
---|
4772 | return n ? |
---|
4773 | this.onNodeDrop(n, dd, e, data) : |
---|
4774 | this.onContainerDrop(dd, e, data); |
---|
4775 | }, |
---|
4776 | |
---|
4777 | // private |
---|
4778 | triggerCacheRefresh : function(){ |
---|
4779 | Ext.dd.DDM.refreshCache(this.groups); |
---|
4780 | } |
---|
4781 | });/** |
---|
4782 | * @class Ext.Element |
---|
4783 | */ |
---|
4784 | Ext.Element.addMethods({ |
---|
4785 | /** |
---|
4786 | * Initializes a {@link Ext.dd.DD} drag drop object for this element. |
---|
4787 | * @param {String} group The group the DD object is member of |
---|
4788 | * @param {Object} config The DD config object |
---|
4789 | * @param {Object} overrides An object containing methods to override/implement on the DD object |
---|
4790 | * @return {Ext.dd.DD} The DD object |
---|
4791 | */ |
---|
4792 | initDD : function(group, config, overrides){ |
---|
4793 | var dd = new Ext.dd.DD(Ext.id(this.dom), group, config); |
---|
4794 | return Ext.apply(dd, overrides); |
---|
4795 | }, |
---|
4796 | |
---|
4797 | /** |
---|
4798 | * Initializes a {@link Ext.dd.DDProxy} object for this element. |
---|
4799 | * @param {String} group The group the DDProxy object is member of |
---|
4800 | * @param {Object} config The DDProxy config object |
---|
4801 | * @param {Object} overrides An object containing methods to override/implement on the DDProxy object |
---|
4802 | * @return {Ext.dd.DDProxy} The DDProxy object |
---|
4803 | */ |
---|
4804 | initDDProxy : function(group, config, overrides){ |
---|
4805 | var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config); |
---|
4806 | return Ext.apply(dd, overrides); |
---|
4807 | }, |
---|
4808 | |
---|
4809 | /** |
---|
4810 | * Initializes a {@link Ext.dd.DDTarget} object for this element. |
---|
4811 | * @param {String} group The group the DDTarget object is member of |
---|
4812 | * @param {Object} config The DDTarget config object |
---|
4813 | * @param {Object} overrides An object containing methods to override/implement on the DDTarget object |
---|
4814 | * @return {Ext.dd.DDTarget} The DDTarget object |
---|
4815 | */ |
---|
4816 | initDDTarget : function(group, config, overrides){ |
---|
4817 | var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config); |
---|
4818 | return Ext.apply(dd, overrides); |
---|
4819 | } |
---|
4820 | }); |
---|