-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpega_yui_dragdrop_profile.js
3588 lines (3160 loc) · 137 KB
/
pega_yui_dragdrop_profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.5.1
*/
/**
* The drag and drop utility provides a framework for building drag and drop
* applications. In addition to enabling drag and drop for specific elements,
* the drag and drop elements are tracked by the manager class, and the
* interactions between the various elements are tracked during the drag and
* the implementing code is notified about these important moments.
* @module dragdrop
* @title Drag and Drop
* @requires pega,dom,event
* @namespace pega.util
*/
// Only load the library once. Rewriting the manager class would orphan
// existing drag and drop instances.
if (!pega.util.DragDropMgr) {
/**
* DragDropMgr is a singleton that tracks the element interaction for
* all DragDrop items in the window. Generally, you will not call
* this class directly, but it does have helper methods that could
* be useful in your DragDrop implementations.
* @class DragDropMgr
* @static
*/
pega.util.DragDropMgr = function() {
var Event = pega.util.Event;
return {
/**
* Two dimensional Array of registered DragDrop objects. The first
* dimension is the DragDrop item group, the second the DragDrop
* object.
* @property ids
* @type {string: string}
* @private
* @static
*/
ids: {},
/**
* Array of element ids defined as drag handles. Used to determine
* if the element that generated the mousedown event is actually the
* handle and not the html element itself.
* @property handleIds
* @type {string: string}
* @private
* @static
*/
handleIds: {},
/**
* the DragDrop object that is currently being dragged
* @property dragCurrent
* @type DragDrop
* @private
* @static
**/
dragCurrent: null,
/**
* the DragDrop object(s) that are being hovered over
* @property dragOvers
* @type Array
* @private
* @static
*/
dragOvers: {},
/**
* the X distance between the cursor and the object being dragged
* @property deltaX
* @type int
* @private
* @static
*/
deltaX: 0,
/**
* the Y distance between the cursor and the object being dragged
* @property deltaY
* @type int
* @private
* @static
*/
deltaY: 0,
/**
* Flag to determine if we should prevent the default behavior of the
* events we define. By default this is true, but this can be set to
* false if you need the default behavior (not recommended)
* @property preventDefault
* @type boolean
* @static
*/
preventDefault: true,
/**
* Flag to determine if we should stop the propagation of the events
* we generate. This is true by default but you may want to set it to
* false if the html element contains other features that require the
* mouse click.
* @property stopPropagation
* @type boolean
* @static
*/
stopPropagation: true,
/**
* Internal flag that is set to true when drag and drop has been
* initialized
* @property initialized
* @private
* @static
*/
initialized: false,
/**
* All drag and drop can be disabled.
* @property locked
* @private
* @static
*/
locked: false,
/**
* Provides additional information about the the current set of
* interactions. Can be accessed from the event handlers. It
* contains the following properties:
*
* out: onDragOut interactions
* enter: onDragEnter interactions
* over: onDragOver interactions
* drop: onDragDrop interactions
* point: The location of the cursor
* draggedRegion: The location of dragged element at the time
* of the interaction
* sourceRegion: The location of the source elemtn at the time
* of the interaction
* validDrop: boolean
* @property interactionInfo
* @type object
* @static
*/
interactionInfo: null,
/**
* Called the first time an element is registered.
* @method init
* @private
* @static
*/
init: function() {
this.initialized = true;
},
/**
* In point mode, drag and drop interaction is defined by the
* location of the cursor during the drag/drop
* @property POINT
* @type int
* @static
* @final
*/
POINT: 0,
/**
* In intersect mode, drag and drop interaction is defined by the
* cursor position or the amount of overlap of two or more drag and
* drop objects.
* @property INTERSECT
* @type int
* @static
* @final
*/
INTERSECT: 1,
/**
* In intersect mode, drag and drop interaction is defined only by the
* overlap of two or more drag and drop objects.
* @property STRICT_INTERSECT
* @type int
* @static
* @final
*/
STRICT_INTERSECT: 2,
/**
* The current drag and drop mode. Default: POINT
* @property mode
* @type int
* @static
*/
mode: 0,
/**
* Runs method on all drag and drop objects
* @method _execOnAll
* @private
* @static
*/
_execOnAll: function(sMethod, args) {
for (var i in this.ids) {
for (var j in this.ids[i]) {
var oDD = this.ids[i][j];
if (! this.isTypeOfDD(oDD)) {
continue;
}
oDD[sMethod].apply(oDD, args);
}
}
},
/**
* Drag and drop initialization. Sets up the global event handlers
* @method _onLoad
* @private
* @static
*/
_onLoad: function() {
this.init();
pega.log("DragDropMgr onload", "info", "DragDropMgr");
Event.on(document, "mouseup", this.handleMouseUp, this, true);
Event.on(document, "mousemove", this.handleMouseMove, this, true);
Event.on(window, "unload", this._onUnload, this, true);
Event.on(window, "resize", this._onResize, this, true);
// Event.on(window, "mouseout", this._test);
},
/**
* Reset constraints on all drag and drop objs
* @method _onResize
* @private
* @static
*/
_onResize: function(e) {
pega.log("window resize", "info", "DragDropMgr");
this._execOnAll("resetConstraints", []);
},
/**
* Lock all drag and drop functionality
* @method lock
* @static
*/
lock: function() { this.locked = true; },
/**
* Unlock all drag and drop functionality
* @method unlock
* @static
*/
unlock: function() { this.locked = false; },
/**
* Is drag and drop locked?
* @method isLocked
* @return {boolean} True if drag and drop is locked, false otherwise.
* @static
*/
isLocked: function() { return this.locked; },
/**
* Location cache that is set for all drag drop objects when a drag is
* initiated, cleared when the drag is finished.
* @property locationCache
* @private
* @static
*/
locationCache: {},
/**
* Set useCache to false if you want to force object the lookup of each
* drag and drop linked element constantly during a drag.
* @property useCache
* @type boolean
* @static
*/
useCache: true,
/**
* The number of pixels that the mouse needs to move after the
* mousedown before the drag is initiated. Default=3;
* @property clickPixelThresh
* @type int
* @static
*/
clickPixelThresh: 3,
/**
* The number of milliseconds after the mousedown event to initiate the
* drag if we don't get a mouseup event. Default=1000
* @property clickTimeThresh
* @type int
* @static
*/
clickTimeThresh: 1000,
/**
* Flag that indicates that either the drag pixel threshold or the
* mousdown time threshold has been met
* @property dragThreshMet
* @type boolean
* @private
* @static
*/
dragThreshMet: false,
/**
* Timeout used for the click time threshold
* @property clickTimeout
* @type Object
* @private
* @static
*/
clickTimeout: null,
/**
* The X position of the mousedown event stored for later use when a
* drag threshold is met.
* @property startX
* @type int
* @private
* @static
*/
startX: 0,
/**
* The Y position of the mousedown event stored for later use when a
* drag threshold is met.
* @property startY
* @type int
* @private
* @static
*/
startY: 0,
/**
* Flag to determine if the drag event was fired from the click timeout and
* not the mouse move threshold.
* @property fromTimeout
* @type boolean
* @private
* @static
*/
fromTimeout: false,
/**
* Each DragDrop instance must be registered with the DragDropMgr.
* This is executed in DragDrop.init()
* @method regDragDrop
* @param {DragDrop} oDD the DragDrop object to register
* @param {String} sGroup the name of the group this element belongs to
* @static
*/
regDragDrop: function(oDD, sGroup) {
if (!this.initialized) { this.init(); }
if (!this.ids[sGroup]) {
this.ids[sGroup] = {};
}
this.ids[sGroup][oDD.id] = oDD;
},
/**
* Removes the supplied dd instance from the supplied group. Executed
* by DragDrop.removeFromGroup, so don't call this function directly.
* @method removeDDFromGroup
* @private
* @static
*/
removeDDFromGroup: function(oDD, sGroup) {
if (!this.ids[sGroup]) {
this.ids[sGroup] = {};
}
var obj = this.ids[sGroup];
if (obj && obj[oDD.id]) {
delete obj[oDD.id];
}
},
/**
* Unregisters a drag and drop item. This is executed in
* DragDrop.unreg, use that method instead of calling this directly.
* @method _remove
* @private
* @static
*/
_remove: function(oDD) {
for (var g in oDD.groups) {
if (g && this.ids[g][oDD.id]) {
delete this.ids[g][oDD.id];
//pega.log("NEW LEN " + this.ids.length, "warn");
}
}
delete this.handleIds[oDD.id];
},
/**
* Each DragDrop handle element must be registered. This is done
* automatically when executing DragDrop.setHandleElId()
* @method regHandle
* @param {String} sDDId the DragDrop id this element is a handle for
* @param {String} sHandleId the id of the element that is the drag
* handle
* @static
*/
regHandle: function(sDDId, sHandleId) {
if (!this.handleIds[sDDId]) {
this.handleIds[sDDId] = {};
}
this.handleIds[sDDId][sHandleId] = sHandleId;
},
/**
* Utility function to determine if a given element has been
* registered as a drag drop item.
* @method isDragDrop
* @param {String} id the element id to check
* @return {boolean} true if this element is a DragDrop item,
* false otherwise
* @static
*/
isDragDrop: function(id) {
return ( this.getDDById(id) ) ? true : false;
},
/**
* Returns the drag and drop instances that are in all groups the
* passed in instance belongs to.
* @method getRelated
* @param {DragDrop} p_oDD the obj to get related data for
* @param {boolean} bTargetsOnly if true, only return targetable objs
* @return {DragDrop[]} the related instances
* @static
*/
getRelated: function(p_oDD, bTargetsOnly) {
var oDDs = [];
for (var i in p_oDD.groups) {
for (var j in this.ids[i]) {
var dd = this.ids[i][j];
if (! this.isTypeOfDD(dd)) {
continue;
}
if (!bTargetsOnly || dd.isTarget) {
oDDs[oDDs.length] = dd;
}
}
}
return oDDs;
},
/**
* Returns true if the specified dd target is a legal target for
* the specifice drag obj
* @method isLegalTarget
* @param {DragDrop} the drag obj
* @param {DragDrop} the target
* @return {boolean} true if the target is a legal target for the
* dd obj
* @static
*/
isLegalTarget: function (oDD, oTargetDD) {
var targets = this.getRelated(oDD, true);
for (var i=0, len=targets.length;i<len;++i) {
if (targets[i].id == oTargetDD.id) {
return true;
}
}
return false;
},
/**
* My goal is to be able to transparently determine if an object is
* typeof DragDrop, and the exact subclass of DragDrop. typeof
* returns "object", oDD.constructor.toString() always returns
* "DragDrop" and not the name of the subclass. So for now it just
* evaluates a well-known variable in DragDrop.
* @method isTypeOfDD
* @param {Object} the object to evaluate
* @return {boolean} true if typeof oDD = DragDrop
* @static
*/
isTypeOfDD: function (oDD) {
return (oDD && oDD.__ygDragDrop);
},
/**
* Utility function to determine if a given element has been
* registered as a drag drop handle for the given Drag Drop object.
* @method isHandle
* @param {String} id the element id to check
* @return {boolean} true if this element is a DragDrop handle, false
* otherwise
* @static
*/
isHandle: function(sDDId, sHandleId) {
return ( this.handleIds[sDDId] &&
this.handleIds[sDDId][sHandleId] );
},
/**
* Returns the DragDrop instance for a given id
* @method getDDById
* @param {String} id the id of the DragDrop object
* @return {DragDrop} the drag drop object, null if it is not found
* @static
*/
getDDById: function(id) {
for (var i in this.ids) {
if (this.ids[i][id]) {
return this.ids[i][id];
}
}
return null;
},
/**
* Fired after a registered DragDrop object gets the mousedown event.
* Sets up the events required to track the object being dragged
* @method handleMouseDown
* @param {Event} e the event
* @param oDD the DragDrop object being dragged
* @private
* @static
*/
handleMouseDown: function(e, oDD) {
this.currentTarget = pega.util.Event.getTarget(e);
this.dragCurrent = oDD;
var el = oDD.getEl();
// track start position
this.startX = pega.util.Event.getPageX(e);
this.startY = pega.util.Event.getPageY(e);
this.deltaX = this.startX - el.offsetLeft;
this.deltaY = this.startY - el.offsetTop;
this.dragThreshMet = false;
this.clickTimeout = setTimeout(
function() {
var DDM = pega.util.DDM;
DDM.startDrag(DDM.startX, DDM.startY);
DDM.fromTimeout = true;
},
this.clickTimeThresh );
},
/**
* Fired when either the drag pixel threshol or the mousedown hold
* time threshold has been met.
* @method startDrag
* @param x {int} the X position of the original mousedown
* @param y {int} the Y position of the original mousedown
* @static
*/
startDrag: function(x, y) {
pega.log("firing drag start events", "info", "DragDropMgr");
clearTimeout(this.clickTimeout);
var dc = this.dragCurrent;
if (dc && dc.events.b4StartDrag) {
dc.b4StartDrag(x, y);
dc.fireEvent('b4StartDragEvent', { x: x, y: y });
}
if (dc && dc.events.startDrag) {
dc.startDrag(x, y);
dc.fireEvent('startDragEvent', { x: x, y: y });
}
this.dragThreshMet = true;
},
/**
* Internal function to handle the mouseup event. Will be invoked
* from the context of the document.
* @method handleMouseUp
* @param {Event} e the event
* @private
* @static
*/
handleMouseUp: function(e) {
if (this.dragCurrent) {
clearTimeout(this.clickTimeout);
if (this.dragThreshMet) {
pega.log("mouseup detected - completing drag", "info", "DragDropMgr");
if (this.fromTimeout) {
pega.log('fromTimeout is true (mouse didn\'t move), call handleMouseMove so we can get the dragOver event', 'info', 'DragDropMgr');
this.handleMouseMove(e);
}
this.fromTimeout = false;
this.fireEvents(e, true);
} else {
pega.log("drag threshold not met", "info", "DragDropMgr");
}
this.stopDrag(e);
this.stopEvent(e);
}
},
/**
* Utility to stop event propagation and event default, if these
* features are turned on.
* @method stopEvent
* @param {Event} e the event as returned by this.getEvent()
* @static
*/
stopEvent: function(e) {
if (this.stopPropagation) {
pega.util.Event.stopPropagation(e);
}
if (this.preventDefault) {
pega.util.Event.preventDefault(e);
}
},
/**
* Ends the current drag, cleans up the state, and fires the endDrag
* and mouseUp events. Called internally when a mouseup is detected
* during the drag. Can be fired manually during the drag by passing
* either another event (such as the mousemove event received in onDrag)
* or a fake event with pageX and pageY defined (so that endDrag and
* onMouseUp have usable position data.). Alternatively, pass true
* for the silent parameter so that the endDrag and onMouseUp events
* are skipped (so no event data is needed.)
*
* @method stopDrag
* @param {Event} e the mouseup event, another event (or a fake event)
* with pageX and pageY defined, or nothing if the
* silent parameter is true
* @param {boolean} silent skips the enddrag and mouseup events if true
* @static
*/
stopDrag: function(e, silent) {
// pega.log("mouseup - removing event handlers");
var dc = this.dragCurrent;
// Fire the drag end event for the item that was dragged
if (dc && !silent) {
if (this.dragThreshMet) {
pega.log("firing endDrag events", "info", "DragDropMgr");
if (dc.events.b4EndDrag) {
dc.b4EndDrag(e);
dc.fireEvent('b4EndDragEvent', { e: e });
}
if (dc.events.endDrag) {
dc.endDrag(e);
dc.fireEvent('endDragEvent', { e: e });
}
}
if (dc.events.mouseUp) {
pega.log("firing dragdrop onMouseUp event", "info", "DragDropMgr");
dc.onMouseUp(e);
dc.fireEvent('mouseUpEvent', { e: e });
}
}
this.dragCurrent = null;
this.dragOvers = {};
},
/**
* Internal function to handle the mousemove event. Will be invoked
* from the context of the html element.
*
* @TODO figure out what we can do about mouse events lost when the
* user drags objects beyond the window boundary. Currently we can
* detect this in internet explorer by verifying that the mouse is
* down during the mousemove event. Firefox doesn't give us the
* button state on the mousemove event.
* @method handleMouseMove
* @param {Event} e the event
* @private
* @static
*/
handleMouseMove: function(e) {
//pega.log("handlemousemove");
var dc = this.dragCurrent;
if (dc) {
// pega.log("no current drag obj");
// var button = e.which || e.button;
// pega.log("which: " + e.which + ", button: "+ e.button);
// check for IE mouseup outside of page boundary
if (pega.util.Event.isIE && !e.button) {
pega.log("button failure", "info", "DragDropMgr");
this.stopEvent(e);
return this.handleMouseUp(e);
} else {
if (e.clientX < 0 || e.clientY < 0) {
//This will stop the element from leaving the viewport in FF, Opera & Safari
//Not turned on yet
//pega.log("Either clientX or clientY is negative, stop the event.", "info", "DragDropMgr");
//this.stopEvent(e);
//return false;
}
}
if (!this.dragThreshMet) {
var diffX = Math.abs(this.startX - pega.util.Event.getPageX(e));
var diffY = Math.abs(this.startY - pega.util.Event.getPageY(e));
// pega.log("diffX: " + diffX + "diffY: " + diffY);
if (diffX > this.clickPixelThresh ||
diffY > this.clickPixelThresh) {
pega.log("pixel threshold met", "info", "DragDropMgr");
this.startDrag(this.startX, this.startY);
}
}
if (this.dragThreshMet) {
if (dc && dc.events.b4Drag) {
dc.b4Drag(e);
dc.fireEvent('b4DragEvent', { e: e});
}
if (dc && dc.events.drag) {
dc.onDrag(e);
dc.fireEvent('dragEvent', { e: e});
}
if (dc) {
this.fireEvents(e, false);
}
}
this.stopEvent(e);
}
},
/**
* Iterates over all of the DragDrop elements to find ones we are
* hovering over or dropping on
* @method fireEvents
* @param {Event} e the event
* @param {boolean} isDrop is this a drop op or a mouseover op?
* @private
* @static
*/
fireEvents: function(e, isDrop) {
var dc = this.dragCurrent;
// If the user did the mouse up outside of the window, we could
// get here even though we have ended the drag.
// If the config option dragOnly is true, bail out and don't fire the events
if (!dc || dc.isLocked() || dc.dragOnly) {
return;
}
var x = pega.util.Event.getPageX(e),
y = pega.util.Event.getPageY(e),
pt = new pega.util.Point(x,y),
pos = dc.getTargetCoord(pt.x, pt.y),
el = dc.getDragEl(),
events = ['out', 'over', 'drop', 'enter'],
curRegion = new pega.util.Region( pos.y,
pos.x + el.offsetWidth,
pos.y + el.offsetHeight,
pos.x ),
oldOvers = [], // cache the previous dragOver array
inGroupsObj = {},
inGroups = [],
data = {
outEvts: [],
overEvts: [],
dropEvts: [],
enterEvts: []
};
// Check to see if the object(s) we were hovering over is no longer
// being hovered over so we can fire the onDragOut event
for (var i in this.dragOvers) {
var ddo = this.dragOvers[i];
if (! this.isTypeOfDD(ddo)) {
continue;
}
if (! this.isOverTarget(pt, ddo, this.mode, curRegion)) {
data.outEvts.push( ddo );
}
oldOvers[i] = true;
delete this.dragOvers[i];
}
for (var sGroup in dc.groups) {
// pega.log("Processing group " + sGroup);
if ("string" != typeof sGroup) {
continue;
}
for (i in this.ids[sGroup]) {
var oDD = this.ids[sGroup][i];
if (! this.isTypeOfDD(oDD)) {
continue;
}
if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
if (this.isOverTarget(pt, oDD, this.mode, curRegion)) {
inGroupsObj[sGroup] = true;
// look for drop interactions
if (isDrop) {
data.dropEvts.push( oDD );
// look for drag enter and drag over interactions
} else {
// initial drag over: dragEnter fires
if (!oldOvers[oDD.id]) {
data.enterEvts.push( oDD );
// subsequent drag overs: dragOver fires
} else {
data.overEvts.push( oDD );
}
this.dragOvers[oDD.id] = oDD;
}
}
}
}
}
this.interactionInfo = {
out: data.outEvts,
enter: data.enterEvts,
over: data.overEvts,
drop: data.dropEvts,
point: pt,
draggedRegion: curRegion,
sourceRegion: this.locationCache[dc.id],
validDrop: isDrop
};
for (var inG in inGroupsObj) {
inGroups.push(inG);
}
// notify about a drop that did not find a target
if (isDrop && !data.dropEvts.length) {
pega.log(dc.id + " dropped, but not on a target", "info", "DragDropMgr");
this.interactionInfo.validDrop = false;
if (dc.events.invalidDrop) {
dc.onInvalidDrop(e);
dc.fireEvent('invalidDropEvent', { e: e });
}
}
for (i = 0; i < events.length; i++) {
var tmp = null;
if (data[events[i] + 'Evts']) {
tmp = data[events[i] + 'Evts'];
}
if (tmp && tmp.length) {
var type = events[i].charAt(0).toUpperCase() + events[i].substr(1),
ev = 'onDrag' + type,
b4 = 'b4Drag' + type,
cev = 'drag' + type + 'Event',
check = 'drag' + type;
if (this.mode) {
pega.log(dc.id + ' ' + ev + ': ' + tmp, "info", "DragDropMgr");
if (dc.events[b4]) {
dc[b4](e, tmp, inGroups);
dc.fireEvent(b4 + 'Event', { event: e, info: tmp, group: inGroups });
}
if (dc.events[check]) {
dc[ev](e, tmp, inGroups);
dc.fireEvent(cev, { event: e, info: tmp, group: inGroups });
}
} else {
for (var b = 0, len = tmp.length; b < len; ++b) {
pega.log(dc.id + ' ' + ev + ': ' + tmp[b].id, "info", "DragDropMgr");
if (dc.events[b4]) {
dc[b4](e, tmp[b].id, inGroups[0]);
dc.fireEvent(b4 + 'Event', { event: e, info: tmp[b].id, group: inGroups[0] });
}
if (dc.events[check]) {
dc[ev](e, tmp[b].id, inGroups[0]);
dc.fireEvent(cev, { event: e, info: tmp[b].id, group: inGroups[0] });
}
}
}
}
}
},
/**
* Helper function for getting the best match from the list of drag
* and drop objects returned by the drag and drop events when we are
* in INTERSECT mode. It returns either the first object that the
* cursor is over, or the object that has the greatest overlap with
* the dragged element.
* @method getBestMatch
* @param {DragDrop[]} dds The array of drag and drop objects
* targeted
* @return {DragDrop} The best single match
* @static
*/
getBestMatch: function(dds) {
var winner = null;
var len = dds.length;
if (len == 1) {
winner = dds[0];
} else {
// Loop through the targeted items
for (var i=0; i<len; ++i) {
var dd = dds[i];
// If the cursor is over the object, it wins. If the
// cursor is over multiple matches, the first one we come
// to wins.
if (this.mode == this.INTERSECT && dd.cursorIsOver) {
winner = dd;
break;
// Otherwise the object with the most overlap wins
} else {
if (!winner || !winner.overlap || (dd.overlap &&
winner.overlap.getArea() < dd.overlap.getArea())) {
winner = dd;
}
}
}
}
return winner;
},
/**
* Refreshes the cache of the top-left and bottom-right points of the
* drag and drop objects in the specified group(s). This is in the
* format that is stored in the drag and drop instance, so typical
* usage is:
* <code>
* pega.util.DragDropMgr.refreshCache(ddinstance.groups);
* </code>
* Alternatively:
* <code>
* pega.util.DragDropMgr.refreshCache({group1:true, group2:true});
* </code>
* @TODO this really should be an indexed array. Alternatively this
* method could accept both.
* @method refreshCache
* @param {Object} groups an associative array of groups to refresh
* @static
*/
refreshCache: function(groups) {
pega.log("refreshing element location cache", "info", "DragDropMgr");
// refresh everything if group array is not provided
var g = groups || this.ids;
for (var sGroup in g) {
if ("string" != typeof sGroup) {
continue;
}
for (var i in this.ids[sGroup]) {
var oDD = this.ids[sGroup][i];
if (this.isTypeOfDD(oDD)) {
var loc = this.getLocation(oDD);
if (loc) {
this.locationCache[oDD.id] = loc;
} else {
delete this.locationCache[oDD.id];
pega.log("Could not get the loc for " + oDD.id, "warn", "DragDropMgr");
}
}
}
}
},
/**
* This checks to make sure an element exists and is in the DOM. The
* main purpose is to handle cases where innerHTML is used to remove
* drag and drop objects from the DOM. IE provides an 'unspecified
* error' when trying to access the offsetParent of such an element
* @method verifyEl
* @param {HTMLElement} el the element to check