-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragulaDnd.js
1751 lines (1652 loc) · 84.7 KB
/
dragulaDnd.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
/**
* Filename: dragulaDnd.js
* Author: Yemi Shin
* Description: Implementation of Raheem Clemon's Dragula proof of concept in AvidaED 4.
* Note: Change the legacy "Dojo-" tags later in HTMl, CSS, and JS
* // yemd is a tag for all the legacy code that is getting commented out in development
*/
var av = av || {}; // consistent with the rest of js files
var dijit = dijit || {}; // lets NetBeans know that dijit is defined
// ******************************************************************************************* jQuery(document).ready **
// keep as is since I'm trying to get rid of dojo
jQuery(document).ready(function($) {
// containers are divs that are capable of accepting and intiating drag and drop
var containers = [
$.map($(".freezerContainer"), (value, key) => { return value }),
$.map($("#testConfig"), (value, key) => { return value }),
$.map($("#activeConfig"), (value, key) => { return value }),
$.map($("#trashCan"), (value, key) => { return value }),
$.map($("#gridCanvas"), (value, key) => { return value }),
$.map($("#ancestorBox"), (value, key) => { return value }),
$.map($("#ancestorBoTest"), (value, key) => { return value }),
$.map($("#activeOrgan"), (value, key) => { return value }),
$.map($("#organCanvas"), (value, key) => { return value }),
$.map($("#organIcon"), (value, key) => { return value }),
$.map($("#anlDndChart"), (value, key) => { return value }),
$.map($("#popDish0"), (value, key) => { return value }),
$.map($("#popDish1"), (value, key) => { return value }),
$.map($("#popDish2"), (value, key) => { return value }),
].flat();
if (av.debug.dnd) { console.log('DnD: dragula containters: ', containers); }
// initialize globally availble references to dnd containers
av.dnd.fzConfig = containers[0];
av.dnd.fzOrgan = containers[1];
av.dnd.fzWorld = containers[2];
av.dnd.fzTdish = containers[3];
av.dnd.testConfig = containers[4];
av.dnd.activeConfig = containers[5];
av.dnd.trashCan = containers[6];
av.dnd.gridCanvas = containers[7];
av.dnd.ancestorBox = containers[8];
av.dnd.ancestorBoTest = containers[9];
av.dnd.activeOrgan = containers[10];
av.dnd.organCanvas = containers[11];
av.dnd.organIcon = containers[12];
av.dnd.anlDndChart = containers[13];
av.dnd.popDish0 = containers[14];
av.dnd.popDish1 = containers[15];
av.dnd.popDish2 = containers[16];
// variables necessary to make landGridCanvas work (because dragula and regular JavaScript mouseevents are not compatible)
var dragging = false;
var sourceIsFzOrgan = false;
var sourceIsFzWorld = false;
var sourceIsFzConfig = false;
var sourceIsAncestorBox = false;
var elForGrid = '';
// variable to keep the most recently added domid
// domids are unique for each new item that is drag and dropped
var mostRecentlyAddedDomid = '';
av.dnd.clickedMenu = "";
av.dnd.userDraggedNewConfig = false; // needed to let the modal know whether or not to reset the grid or not
//------------------------------------------------------------------------------------------- Dragula Initialization --
var dra = dragula(containers, {
isContainer: function (el) {
return false; // only elements in drake.containers will be taken into account
},
moves: function (el, source, handle, sibling) {
// these sources only receive, they do not give
if (source === av.dnd.anlDndChart || source === av.dnd.organIcon || source === av.dnd.trashCan) {
return false;
}
return true; // otherwise they both work as receivers and givers
},
accepts: function (el, target, source, sibling) {
// actual accepts function is taken out into its own function to be usable outside the dragula constructor
return av.dnd.accepts(el, target, source);
},
invalid: function (el, handle) {
return false; // don't prevent any drags from initiating by default
},
copy: function (el, source) {
//Makes sure the only item that will be copied instead of moved is in the FreezerMove div
return source === av.dnd.ancestorBox || source === av.dnd.activeOrgan || source === av.dnd.activeConfig || source === av.dnd.fzConfig || source === av.dnd.fzOrgan || source === av.dnd.fzWorld || source === av.dnd.fzTdish;
},
direction: 'vertical', // Y axis is considered when determining where an element would be dropped
copySortSource: false, // elements in copy-source containers can be reordered
revertOnSpill: true, // spilling will put the element back where it was dragged from, if this is true
removeOnSpill: false, // spilling will `.remove` the element, if this is true
mirrorContainer: document.body, // set the element that gets mirror elements appended
ignoreInputTextSelection: true // allows users to select input text, see details below
});
//--------------------------------------------------------------------------------------- end Dragula Initialization --
//-------------------------------------------------------------------------------------------------- av.dnd.accepts --
// This is defining which containers can accept what
av.dnd.accepts = function(el, target, source) {
if (source === av.dnd.anlDndChart) { // prevent dragging from analysis chart
return false;
}
if (source === av.dnd.popDish0 || source === av.dnd.popDish1 || source === av.dnd.popDish2) {
return false;
}
// if (target === source) {
// return true;
// }
if (source === av.dnd.ancestorBox) {
if (av.grd.runState === "started" && (target === av.dnd.trashCan || target === av.dnd.gridCanvas)) {
return false;
}
if (target === av.dnd.activeConfig) {
return false;
}
return true;
}
if (source === av.dnd.activeConfig) {
if (av.grd.runState != "started" && target === av.dnd.fzWorld) {
return false;
} else if (target === av.dnd.fzConfig || target === av.dnd.fzWorld) {
return true;
}
}
if (source === av.dnd.activeOrgan && (target === av.dnd.fzOrgan || target === av.dnd.organIcon || target === av.dnd.organCanvas)) {
return true;
}
if (source === av.dnd.fzConfig && (target === av.dnd.activeConfig || target === av.dnd.gridCanvas)) {
return true;
}
if (source === av.dnd.fzWorld && (target === av.dnd.activeConfig || target === av.dnd.gridCanvas || target === av.dnd.anlDndChart || target === av.dnd.popDish0 || target === av.dnd.popDish1 || target === av.dnd.popDish2)) {
return true;
}
if (source === av.dnd.fzOrgan) {
if (av.grd.runState === "started" && (target === av.dnd.gridCanvas || target === av.dnd.ancestorBox)) {
return false;
}
else if (target === av.dnd.activeConfig || target === av.dnd.anlDndChart || target === av.dnd.popDish0 || target === av.dnd.popDish1 || target === av.dnd.popDish2) {
return false;
}
else if (target === av.dnd.organCanvas || target === av.dnd.organIcon || target === av.dnd.gridCanvas || av.dnd.ancestorBox) {
return true;
}
}
if (source === av.dnd.fzTdish && target === av.dnd.testConfig) {
return true;
}
if (target === av.dnd.trashCan) {
if (source === av.dnd.activeOrgan || source === av.dnd.organCanvas) { // according to avida ed 3, unable to delete from activeOrgan or organCanvas
return false;
}
return true;
}
return false;
};
//---------------------------------------------------------------------------------------------- end av.dnd.accepts --
//===================================================================================================== Handle drag ==
//----------------------------------------------------------------------------------------------------- dra.on drag --
dra.on('drag', (el, source) => {
dragging = true;
// these three if's are for handling drops on gridCanvas
// necessary because for some reason inside mouse events, dra 'source' and 'target' are messed up
if (source === av.dnd.fzOrgan) {
sourceIsFzOrgan = true;
} else sourceIsFzOrgan = false;
if (source === av.dnd.fzWorld) {
sourceIsFzWorld = true;
} else sourceIsFzWorld = false;
if (source === av.dnd.fzConfig) {
sourceIsFzConfig = true;
} else sourceIsFzConfig = false;
if (source === av.dnd.ancestorBox) {
sourceIsAncestorBox = true;
} else sourceIsAncestorBox = false;
if (av.debug.dnd) { console.log('DnD: el =', el); }
elForGrid = el;
});
//----------------------------------------------------------------------------------------------------- dra.on over --
dra.on('over', (el, container, source) => {
// when mouse is over some container, change cursor shape according to whether or not item is accepted at target container
if (av.dnd.accepts(el, container, source)) {
document.body.style.cursor = "copy";
} else {
document.body.style.cursor = "no-drop";
}
});
//------------------------------------------------------------------------------------------------------ dra.on out --
dra.on('out', (el, container, source) => {
// when mouse is out of some container, revert to default cursor shape
document.body.style.cursor = "default";
});
//--------------------------------------------------------------------------------------------------- dra.on cancel --
dra.on('cancel', (el, container, source) => {
// if drag was canceled, revert to default cursor shape
document.body.style.cursor = "default";
});
//----------------------------------------------------------------------------------------------------- dra.on drop --
// handle drop
dra.on('drop', (el, target, source) => {
if (av.debug.dnd) { console.log('DnD: el=', el); }
// if the drop is not accepted at this target, cancel and return
if (!av.dnd.accepts(el, target, source)) {
dra.cancel();
return;
}
// el, target, source are dom objects aka things you could 'target.id' to
// if the experiment has already started and user is trying to run a new experiment, show the newDishModal, which prompts user to save
if (av.grd.runState === 'started' && (source === av.dnd.fzConfig || source === av.dnd.fzWorld) && (target === av.dnd.gridCanvas || target === av.dnd.activeConfig)) {
av.dnd.userDraggedNewConfig = true;
av.dom.newDishModalID.style.display = 'block'; // show the 'please save' modal
av.dom.newDishCancel.onclick = function () {
av.dom.newDishModalID.style.display = 'none';
dra.cancel();
av.dnd.remove(target, el);
return;
};
av.dom.newDishDiscard.onclick = function () {
av.post.addUser('Button: newDishDiscard');
av.dom.newDishModalID.style.display = 'none';
if ((source === av.dnd.fzWorld || source === av.dnd.fzConfig) && target === av.dnd.gridCanvas) {
av.dnd.landActiveConfigFn(el, av.dnd.activeConfig, source, 'av.dom.newDishDiscard.onclick1');
}
else if ((source === av.dnd.fzWorld || source === av.dnd.fzConfig) && target === av.dnd.activeConfig) {
av.dnd.landActiveConfigFn(el, target, source, 'av.dom.newDishDiscard.onclick2');
}
};
av.dom.newDishSaveWorld.onclick = function () {
av.post.addUser('Button: newDishSaveWorld');
av.ptd.FrPopulationFn();
av.dom.newDishModalID.style.display = 'none';
av.dnd.landActiveConfigFn(el, av.dnd.activeConfig, source, 'av.dom.newDishSaveWorld.onclick');
};
av.dom.newDishSaveConfig.onclick = function () {
av.post.addUser('Button: newDishSaveConfig');
av.ptd.FrConfigFn('av.dom.newDishSaveConfig.onclick');
av.dom.newDishModalID.style.display = 'none';
av.dnd.landActiveConfigFn(el, av.dnd.activeConfig, source, 'av.dom.newDishSaveConfig.onclick');
};
}
else {
if (target === av.dnd.activeConfig) {
av.dnd.landActiveConfigFn(el, target, source, 'target=av.dnd.activeConfig');
}
if (av.grd.runState === 'started' && (source === av.dnd.fzTdish) && (target === av.dnd.gridCanvas || target === av.dnd.testConfig)) {
//below is older and does not work
//if (target === av.dnd.testConfig || target === av.dnd.ancestorBoTest && av.grd.runState === 'started') {
av.dom.newDishModalID.style.display = 'block';
dra.cancel();
} else if (target === av.dnd.testConfig) {
av.dnd.landTestConfigFn(el, target, source, 'dra.on drop: target=av.dnd.activeConfig');
}
if (target === av.dnd.trashCan) {
// however, if the drag is being initiated from the gridCanvas aka, then the event handler is in mouse.js
// refer to av.mouse.ParentMouse or av.mouse.KidMouse
av.dnd.landTrashCan(el, source);
}
if (target === av.dnd.fzConfig) {
av.dnd.landFzConfig(el, target, source);
}
if (target === av.dnd.ancestorBox) {
av.dnd.landAncestorBox(el, target, source);
}
if (target === av.dnd.ancestorBoTest) {
av.dnd.landAncestorBoTest(el, target, source);
}
if (target === av.dnd.fzWorld) {
// does not trigger if source is gridCanvas because techinically there are no 'items' on the grid right now.
// on the grid, mouse movements overtake. Code for that is in mouse.js (av.mouse.kidMouse)
av.dnd.landFzWorld(el, target, source);
}
if (target === av.dnd.fzOrgan) {
av.dnd.landFzOrgan(el, target, source); // not getting called if source is gridCanvas
}
if (target === av.dnd.organIcon) {
av.dnd.landOrganIcon(el, target, source);
}
if (target === av.dnd.activeOrgan) {
av.dnd.landActiveOrgan(el, target, source);
}
if (target === av.dnd.organCanvas) {
av.dnd.landOrganCanvas(el, target, source);
}
if (target === av.dnd.anlDndChart) {
av.dnd.landAnlDndChart(el, target, source);
}
if (target === av.dnd.popDish0 || target === av.dnd.popDish1 || target === av.dnd.popDish2) {
if (target === av.dnd.popDish0) {
av.dnd.landpopDish(el, target, source, 0);
}
else if (target === av.dnd.popDish1) {
av.dnd.landpopDish(el, target, source, 1);
}
else if (target === av.dnd.popDish2) {
av.dnd.landpopDish(el, target, source, 2);
}
}
}
// Special case for gridCanvas
$(document).on('mouseup touchend', function (evt) {
'use strict';
document.body.style.cursor = "default"; // want the mouse to be default after mouseup
if (dragging) {
var x;
var y;
// capture the x and y coordinates
if(evt.type == 'touchend'){
var touch = evt.originalEvent.touches[0] || evt.originalEvent.changedTouches[0];
x = touch.pageX;
y = touch.pageY;
} else if (evt.type == 'mouseup') {
x = evt.clientX;
y = evt.clientY;
}
av.mouse.UpGridPos = [x, y];
// the below convoluted method is necessary to see which elements are below the mouse cursor at this moment
var elements = $.map(document.elementsFromPoint(x, y), (x) => {return x.id});
// if gridCanvas is behind this mouse point
if (elements.indexOf("gridCanvas") != -1 && av.grd.runState !== 'started') {
if (sourceIsFzOrgan) {
av.dnd.landGridCanvas(elForGrid, av.dnd.gridCanvas, av.dnd.fzOrgan);
av.grd.drawGridSetupFn('av.dnd.gridCanvas where target = gridCanvas');
}
else if (sourceIsFzWorld) {
av.dnd.landActiveConfigFn(elForGrid, av.dnd.activeConfig, av.dnd.fzWorld, 'sourceIsFzWorld');
}
else if (sourceIsFzConfig) {
av.dnd.landActiveConfigFn(elForGrid, av.dnd.activeConfig, av.dnd.fzConfig, 'sourceIsFzConfig');
}
else if (sourceIsAncestorBox) {
av.dnd.landGridCanvas(elForGrid, av.dnd.gridCanvas, av.dnd.ancestorBox);
av.grd.drawGridSetupFn('av.dnd.gridCanvas where target = gridCanvas');
}
}
dragging = false;
$(document).unbind('mousemove touchmove');
}
// change the color back (whatever it was before) of the most recently added dom object
if (mostRecentlyAddedDomid != '') {
$('#' + mostRecentlyAddedDomid).css('background', 'inherit');
}
document.body.style.cursor = "default";
// for debugging
// if (av.dbg.flg.drg) { console.log('dragula: end mouseup touchend: av.fzr =', av.fzr); }
if (av.dbg.flg.drg) { console.log('dragula: end mouseup touchend: av.dnd.containerMap =', av.dnd.containerMap); }
});
});
//------------------------------------------------------------------------------------------------- end dra.on drop --
// Select an item from the freezer using click
av.dnd.selectedId = '';
//--------------------------------------------------------------------------------------------- navColClass.onClick --
// allow click selection only if it's within the freezer
$('.navColClass').on('click', function(e) {
document.body.style.cursor = "default"; // want the mouse to be default for click
if (e.target) {
var classList = e.target.className.split(" "); // e.target.className is a string
if (av.dnd.selectedId !== '' && e.target.id === av.dnd.selectedId) {
$('#' + e.target.id).css('background', 'inherit');
$('#' + e.target.id).css('border-color', 'inherit');
av.dnd.selectedId = '';
}
else if (av.dnd.selectedId === '' && classList.indexOf('item') != -1) { // if the target is of class 'item' (aka draggable item)
$('#' + e.target.id).css('background', 'rgb(189, 229, 245)');
$('#' + e.target.id).css('border-color', '#3440e6');
av.dnd.selectedId = e.target.id;
}
else if (av.dnd.selectedId != '' && classList.indexOf('item') != -1) { // if something is selected already and user selects another one
$('#' + av.dnd.selectedId).css('background', 'inherit');
$('#' + e.target.id).css('background', 'rgb(189, 229, 245)');
$('#' + e.target.id).css('border-color', '#3440e6');
av.dnd.selectedId = e.target.id;
}
}
});
//----------------------------------------------------------------------------------------- end navColClass.onClick --
//========================================================================== When something is added to the Freezer ==
//--------------------------------------------------------------------------------------------- av.dnd.landFzConfig --
// when a configuration is added to the freezer
av.dnd.landFzConfig = function(el, target, source) {
'use strict';
if (av.debug.dnd) { console.log('av.dnd.landFzConfig: fzr', av.fzr); }
// create a new dom id for the new object
el.id = 'dom_c' + av.fzr.cNum;
mostRecentlyAddedDomid = el.id; // register this as the most recently added dom object
// give a new name to the object
var oldName = el.textContent.trim();
var sName = av.dnd.namefzrItem(target, oldName);
var configurationName = prompt('Please name your dish configuration', sName);
if (configurationName === null) {
//cancelled so the item should NOT be added to the freezer.
dra.cancel();
return;
}
else {
// confirm that it is a unique name
var configName = av.dnd.getUniqueFzrName(target, configurationName);
if (configName !== null) {
el.innerHTML = `<img src='images/Avida-ED-dish-icon.png' class='DishIcon'></img> ${configName}`;
// el.textContent = configName;
// Add an entry to av.dnd.containerMap
av.dnd.insert(target, el, 'c');
// insert a new directory into the freezer
av.fzr.dir[el.id] = 'c'+ av.fzr.cNum;
// insert a new domid into the freezer
av.fzr.domid['c'+ av.fzr.cNum] = el.id;
// insert a new file into the freezer
av.fzr.file[av.fzr.dir[el.id]+'/entryname.txt'] = configName;
av.fwt.makeFzrConfig(av.fzr.cNum,'av.dnd.landFzConfig');
// increment av.fzr.cNum
av.fzr.cNum++;
//create a right av.mouse-click context menu for the item just created.
av.dnd.contextMenu(target, el.id, 'av.dnd.landFzConfig'); //might need to comment out again (djb)
av.fzr.saveUpdateState('no');
if (av.debug.dnd) { console.log('dir', av.fzr.dir[el.id], '; configName', configName ); } //domid is el.id
} else { //user cancelled so the item should NOT be added to the freezer.
dra.cancel();
return;
}
}
};
//----------------------------------------------------------------------------------------- end av.dnd.landFzConfig --
//---------------------------------------------------------------------------------------------- av.dnd.landFzOrgan --
//when an organism is added to the freezer
av.dnd.landFzOrgan = function(el, target, source) {
el.id = 'dom_g' + av.fzr.gNum;
mostRecentlyAddedDomid = el.id;
var gen;
var oldName = el.textContent.trim();
var sName = av.dnd.namefzrItem(target, oldName);
var avidian = prompt('Please name your avidian', sName);
if (avidian === null) {
//cancelled so the item should NOT be added to the freezer.
dra.cancel();
return;
}
else {
var avName = av.dnd.getUniqueFzrName(target, avidian);
if (null !== avName) { //give dom item new avName name
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent + '; --> ' + avName);
av.dnd.insert(target, el, 'g');
el.innerHTML = `<img src='images/Avida-ED-ancestor-icon.png' class='AvidianIcon'></img> ${avName}`;
// el.textContent = avName;
if (source === av.dnd.ancestorBox) { //do not remove if population has started running
//update structure to hold freezer data for Organisms.
var Ndx = av.parents.domid.indexOf(el.id); //Find index into parent structure
gen = av.parents.genome[Ndx];
}
else if (source === av.dnd.activeOrgan) { gen = av.fzr.actOrgan.genome; }
av.fzr.dir[el.id] = 'g' + av.fzr.gNum;
av.fzr.domid['g'+ av.fzr.gNum] = el.id;
av.fzr.file['g' + av.fzr.gNum + '/genome.seq'] = gen;
av.fzr.file['g' + av.fzr.gNum + '/entryname.txt'] = avName;
if (av.debug.dnd) { console.log('fzr', av.fzr); }
if (av.debug.dnd) { console.log('fzOrgan', av.dnd.fzOrgan); }
//create a right av.mouse-click context menu for the item just created.
if (av.debug.dnd) { console.log('before context menu: target',target, '; domId', domid ); }
av.fzr.gNum++;
av.dnd.contextMenu(target, el.id, 'av.dnd.landFzOrgan', av.dnd.landFzOrgan);
av.fzr.saveUpdateState('no');
}
else { //Not given a name, so it should NOT be added to the freezer.
// do not do anything
dra.cancel();
return;
}
}
if (av.debug.dnd) console.log('near end of av.dnd.landFzOrgan');
if (source != av.dnd.ancestorBox) {
if (av.debug.dnd) console.log('dojo dnd to Organ Freezer, not from Ancestor Box');
}
if (av.debug.dnd) console.log('End of av.dnd.landFzOrgan');
};
//------------------------------------------------------------------------------------------ end av.dnd.landFzOrgan --
//---------------------------------------------------------------------------------------------- av.dnd.landFzWorld --
//when a populated dish is added to the freezer
av.dnd.landFzWorld = function(el, target, source) {
'use strict';
if (av.debug.dnd) console.log('landFzPopDish: fzr', av.fzr);
el.id = 'dom_w' + av.fzr.wNum;
mostRecentlyAddedDomid = el.id;
var oldName = el.textContent.trim() + '@' + av.grd.popStatsMsg.update.formatNum(0);
var sName = av.dnd.namefzrItem(target, oldName);
var worldName = prompt('Please name your populated dish', sName);
if (worldName === null) {
//cancelled so the item should NOT be added to the freezer.
dra.cancel();
return;
}
else {
var nameWorld = av.dnd.getUniqueFzrName(target, worldName);
if (nameWorld !== null) {
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent.trim() + ' --> ' + nameWorld);
el.innerHTML = `<img src='images/Avida-ED-dish-icon.png' class='DishIcon'></img> ${nameWorld}`;
// el.textContent = nameWorld;
av.dnd.insert(target, el, 'w');
av.fzr.dir[el.id] = 'w'+ av.fzr.wNum;
av.fzr.domid['w'+ av.fzr.wNum] = el.id;
//create a right av.mouse-click context menu for the item just created.
av.dnd.contextMenu(target, el.id, 'av.dnd.landFzWorldFn', av.dnd.landFzOrgan);
av.fwt.makeFzrWorld(av.fzr.wNum, 'av.dnd.landFzWorldFn');
av.msg.exportExpr('w' + av.fzr.wNum);
av.msg.sendData();
av.fzr.saveUpdateState('no');
av.fzr.wNum++;
} else { //user cancelled so the item should NOT be added to the freezer.
// do nothing
dra.cancel();
return;
}
}
};
//------------------------------------------------------------------------------------------ end av.dnd.landFzWorld --
//================================================================================== Process drop down menu choices ==
//---------------------------------------------------------------------------------------- av.dnd.FzAddExperimentFn --
// Running actions from drop down menu
// When using dojoDnd, the an item could be selected in each section of the freezer.
// Also I did not know an easy way to see if an item was selected in each freezer section.
av.dnd.FzAddExperimentFn = function (source, target, type) {
var fzSection = source.id;
var targetId = target.id;
var addedPopPage = false;
var addedAnaPage = false;
switch (av.dnd.clickedMenu) {
case "addOrgan":
if (av.dnd.selectedId === "") {
alert('You must select an organism first');
}
else {
var classList = document.getElementById(av.dnd.selectedId).className.split(" ");
var el = $.map($('#' + av.dnd.selectedId), (value, key) => { return value; })[0].cloneNode(true);
if (classList.indexOf('g') === -1) {
$('#' + av.dnd.selectedId).css('background', 'inherit');
av.dnd.selectedId = '';
return;
} else if (av.grd.runState === "started") {
alert("Can't add a new organism to a running experiment. Start a new experiment to continue.");
} else {
addedPopPage = av.dnd.landAncestorBox(el, target, source);
}
// reset the av.dnd.selectedId
$('#' + mostRecentlyAddedDomid).css('background', 'inherit'); // revert the background color of the most recently added dom object
$('#' + av.dnd.selectedId).css('background', 'inherit'); // av.dnd.selectedId is the id of the dom object from which the new object was copied from
av.dnd.selectedId = '';
}
break;
case "addPop":
if (av.dnd.selectedId === "") {
alert('You must select an populated dish first');
}
else {
var classList = document.getElementById(av.dnd.selectedId).className.split(" ");
var el = $.map($('#' + av.dnd.selectedId), (value, key) => { return value; })[0].cloneNode(true);
if (classList.indexOf('w') === -1) {
$('#' + av.dnd.selectedId).css('background', 'inherit');
av.dnd.selectedId = '';
return;
} else if (av.grd.runState === "started") {
alert("Can't add a new populated dish to a running experiment. Start a new experiment to continue.");
} else {
addedPopPage = av.dnd.landActiveConfigFn(el, target, source, 'addedPopPage1');
}
// reset the av.dnd.selectedId
$('#' + mostRecentlyAddedDomid).css('background', 'inherit'); // revert the background color of the most recently added dom object
$('#' + av.dnd.selectedId).css('background', 'inherit'); // av.dnd.selectedId is the id of the dom object from which the new object was copied from
av.dnd.selectedId = '';
}
break;
case "addConfig":
if (av.dnd.selectedId === "") {
alert('You must select an configured dish first');
}
else {
var classList = document.getElementById(av.dnd.selectedId).className.split(" ");
var el = $.map($('#' + av.dnd.selectedId), (value, key) => { return value; })[0].cloneNode(true);
if (classList.indexOf('c') === -1) {
$('#' + av.dnd.selectedId).css('background', 'inherit');
av.dnd.selectedId = '';
return;
} else if (av.grd.runState === "started") {
alert("Can't add a new configured dish to a running experiment. Start a new experiment to continue.");
} else {
addedPopPage = av.dnd.landActiveConfigFn(el, target, source, 'addedPopPage2');
}
// reset the av.dnd.selectedId
$('#' + mostRecentlyAddedDomid).css('background', 'inherit'); // revert the background color of the most recently added dom object
$('#' + av.dnd.selectedId).css('background', 'inherit'); // av.dnd.selectedId is the id of the dom object from which the new object was copied from
av.dnd.selectedId = '';
}
break;
case "addToGenomeView":
if (av.dnd.selectedId != "") {
var classList = document.getElementById(av.dnd.selectedId).className.split(" ");
var el = $.map($('#' + av.dnd.selectedId), (value, key) => { return value; })[0].cloneNode(true);
if (classList.indexOf('g') === -1) {
$('#' + av.dnd.selectedId).css('background', 'inherit');
av.dnd.selectedId = '';
return;
} else {
addedPopPage = av.dnd.landActiveOrgan(el, target, source);
}
// reset the av.dnd.selectedId
$('#' + mostRecentlyAddedDomid).css('background', 'inherit'); // revert the background color of the most recently added dom object
$('#' + av.dnd.selectedId).css('background', 'inherit'); // av.dnd.selectedId is the id of the dom object from which the new object was copied from
av.dnd.selectedId = '';
} else if (av.dnd.gridSelected != "" && av.dnd.gridSelected != undefined) {
if (av.dnd.gridSelected == "parent") { // if ancestor is selected
av.mouse.traceSelectedParent('av.dnd.FzAddExperimentFn');
} else if (av.dnd.gridSelected == "kid") { // if kid is selected
av.mouse.traceSelected('av.dnd.FzAddExperimentFn');
}
}
break;
case "addToAnalysisView":
if (av.dnd.selectedId === "") {
alert('You must select an populated dish first');
}
else {
var classList = document.getElementById(av.dnd.selectedId).className.split(" ");
var el = $.map($('#' + av.dnd.selectedId), (value, key) => { return value; })[0].cloneNode(true);
if (classList.indexOf('w') === -1) {
$('#' + av.dnd.selectedId).css('background', 'inherit');
av.dnd.selectedId = '';
return;
} else {
addedAnaPage = av.dnd.landAnlDndChart(el, target, source);
}
// reset the av.dnd.selectedId
$('#' + mostRecentlyAddedDomid).css('background', 'inherit'); // revert the background color of the most recently added dom object
$('#' + av.dnd.selectedId).css('background', 'inherit'); // av.dnd.selectedId is the id of the dom object from which the new object was copied from
av.dnd.selectedId = '';
}
break;
}
if (addedPopPage) av.grd.drawGridSetupFn('av.dnd.FzAddExperimentFn');
};
//------------------------------------------------------------------------------------ end av.dnd.FzAddExperimentFn --
//=================================================================================================== Analysis Page ==
//---------------------------------------------------------------------------------------------- av.dnd.landpopDish --
av.dnd.landpopDish = function(el, target, source, num) {
'use strict';
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent.trim());
//if there is an existing item, need to clear all nodes and assign most recent to item 0
//clear out the old data
av.dnd.empty(target);
// get the data for the dragged dish
var dir = av.fzr.dir[el.id];
// give the new dom object a new dom id
el.id = 'dom_w' + av.fzr.wNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// insert element into target av.dnd.containerMap
av.dnd.insert(target, el, 'w');
// insert element into the target DOM
av.dnd.insertToDOM(target, el);
// load world data
av.anl.loadWorldData(num, dir);
av.anl.loadSelectedData(num, 'yLeftSelect', 'left', 'av.dnd.landpopDish');
av.anl.loadSelectedData(num, 'yRightSelect', 'right', 'av.dnd.landpopDish');
av.anl.AnaChartFn();
};
//------------------------------------------------------------------------------------------ end av.dnd.landpopDish --
//------------------------------------------------------------------------------------------------- av.dnd.putNslot --
av.dnd.putNslot = function (el, num, source) {
'use strict';
//the console.log get the data one way, the codes gets the same data another way.
// console.log('sourceContainer=', source.parent.id, '; world domID=', source.anchor.id, '; world Name=', source.anchor.textContent.trim());
// get the data for the dragged dish
var dir = av.fzr.dir[el.id];
// give the new dom object a new dom id
el.id = 'dom_w' + av.fzr.wNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// insert element into target av.dnd.containerMap
av.dnd.insert(source, el, 'w');
// insert element into DOM
av.dnd.insertToDOM(source, el);
// load world data
av.anl.loadWorldData(num, dir);
av.anl.loadSelectedData(num, 'yLeftSelect', 'left', 'av.dnd.putNslot');
av.anl.loadSelectedData(num, 'yRightSelect', 'right', 'av.dnd.putNslot');
};
//--------------------------------------------------------------------------------------------- end av.dnd.putNslot --
//------------------------------------------------------------------------------------------ av.dnd.landAnlDndChart --
av.dnd.landAnlDndChart = function(el, target, source) {
'use strict';
if (av.dbg.flg.drg) { console.log('dragula: in av.dnd.landAnlDndChart'); }
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent);
var items = av.dnd.getAllItems(av.dnd.popDish0);
if (0 === items.length) { av.dnd.putNslot(el, 0, av.dnd.popDish0); }
else {
items = av.dnd.getAllItems(av.dnd.popDish1);
if (0 === items.length) { av.dnd.putNslot(el, 1, av.dnd.popDish1); }
else {
items = av.dnd.getAllItems(av.dnd.popDish2);
if (0 === items.length) { av.dnd.putNslot(el, 2, av.dnd.popDish2);}
}
}
// in all cases no population name is stored in the graph div
av.dnd.empty(target);
av.anl.AnaChartFn();
};
//-------------------------------------------------------------------------------------- end av.dnd.landAnlDndChart --
//=================================================================================================== Organism Page ==
//------------------------------------------------------------------------------------------ av.dnd.landOrganCanvas --
av.dnd.landOrganCanvas = function(el, target, source) {
'use strict';
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent);
// behave the same way as if organism was dropped onto active organ box
av.dnd.landActiveOrgan(el, target, source);
};
//-------------------------------------------------------------------------------------- end av.dnd.landOrganCanvas --
//------------------------------------------------------------------------------------------ av.dnd.landActiveOrgan --
av.dnd.landActiveOrgan = function(el, target, source) {
// need to have only the most recent dropped organism in av.dnd.activeOrgan.
// Do this by deleting everything in activeOrgan and reinserting the most resent one after a drop event.
'use strict';
if (av.debug.dnd) { console.log('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent); }
//clear out the old data if an organism is already there
av.dnd.empty(av.dnd.activeOrgan);
// get the data for the dragged organism
var dir = av.fzr.dir[el.id];
el = el.cloneNode(true);
// give a new id to the new dom object
el.id = 'dom_g' + av.fzr.gNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// insert element into target av.dnd.containerMap
av.dnd.insert(av.dnd.activeOrgan, el, 'g');
// insert element into target DOM
av.dnd.insertToDOM(av.dnd.activeOrgan, el);
// update active organ
av.fzr.actOrgan.actDomid = el.id;
av.dnd.updateFromFzrOrganism(el);
av.msg.doOrgTrace();
};
//------------------------------------------------------------------------------------------ av.dnd.landActiveOrgan --
//-------------------------------------------------------------------------------------------- av.dnd.landOrganIcon --
av.dnd.landOrganIcon = function(el, target, source) {
// clear out the old data if an organism is already there
'use strict';
av.post.addUser('DnD: ' + source.id + '--> ' + target.id + ': by: ' + el.textContent);
if (av.debug.dnd) { console.log('DnD: source', source.id); }
// remove the existing configuration
av.dnd.empty(av.dnd.activeOrgan);
// get the data for the dragged organism
var dir = av.fzr.dir[el.id];
var parentID = el.id;
// give a new dom id to the new dom object
el.id = 'dom_g' + av.fzr.gNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// insert element into target av.dnd.containerMap
av.dnd.insert(av.dnd.activeOrgan, el, 'g');
// insert element into target DOM
av.dnd.insertToDOM(av.dnd.activeOrgan, el);
// update active organ
av.fzr.actOrgan.actDomid = el.id;
if (source === av.dnd.fzOrgan) {
av.dnd.updateFromFzrOrganism(el);
}
if (source === av.dnd.ancestorBox) {
var Ndx = av.parents.domid.indexOf(parentID);
if (av.debug.dnd) { console.log('DnD: test from ancestorBox to organIcon', Ndx); }
av.fzr.actOrgan.name = av.parents.name[Ndx];
av.fzr.actOrgan.genome = av.parents.genome[Ndx];
if (av.debug.dnd) { console.log('fzr', av.fzr, '; parents', av.parents, '; ndx', Ndx); }
}
// change to organism page
av.ui.mainBoxSwap('organismBlock');
av.ind.organismCanvasHolderSize('mouseup_organIcon_parent');
av.ui.adjustOrgInstructionTextAreaSize();
if (av.dbg.flg.mouse) { console.log('mouse: from parent', av.parent, '; fzr', av.fzr); }
av.post.addUser('Dragged item to Organism Icon');
av.msg.doOrgTrace(); // request new Organism Trace from Avida and draw that.
// /* yemi: update organism canvas */
// av.ind.updateOrgTrace();
// clear out av.dnd.organIcon as nothing is stored there - just moved on to OrganismCurrent
av.dnd.empty(target); //clear items from icon
};
//---------------------------------------------------------------------------------------- end av.dnd.landOrganIcon --
//------------------------------------------------------------------------------------ av.dnd.updateFromFzrOrganism --
av.dnd.updateFromFzrOrganism = function (el) {
'use strict';
var domId = el.id;
var dir = av.fzr.dir[domId];
if (av.debug.dnd) { console.log('DnD: domId', domId, '; dir', dir); }
av.fzr.actOrgan.name = av.fzr.file[dir+'/entryname.txt'];
av.fzr.actOrgan.genome = av.fzr.file[dir+'/genome.seq'];
if (av.debug.dnd) { console.log('DnD: domId', domId); }
if (av.debug.dnd) { console.log('DnD: domId', domId, '; dir', dir, '; name', av.fzr.actOrgan.name, '; genome', av.fzr.actOrgan.genome); }
if (av.debug.dnd) { console.log('DnD: fzr', av.fzr); }
if (av.debug.dnd) { console.log('DnD: av.fzr.actOrgan', av.fzr.actOrgan); }
};
//-------------------------------------------------------------------------------- end av.dnd.updateFromFzrOrganism --
//================================================================================================= Population Page ==
//------------------------------------------------------------------------------------ av.dnd.updateFromFzrOrganism --
av.dnd.landGridCanvas = function(el, target, source) {
'use strict';
if (av.debug.dnd) { console.log('DnD: inside gridCanvas dnd'); }
if (av.debug.dnd) { console.log('DnD: parents', av.parents); }
var nn = av.parents.name.length;
av.post.addUser('DnD: ' + source.id + '--> GridCanvas: by: ' + el.textContent.trim() + ' on (' + av.mouse.UpGridPos[0] + ', ' + av.mouse.UpGridPos[1] + ')' );
// to correctly place the organism, need to calculate offsets
var offsetXLocal = ($("#gridHolder").width() - av.dom.gridCanvas.width) / 2;
var offsetYLocal = ($("#gridHolder").height() - av.dom.gridCanvas.height) / 2;
var widthOfNav = parseInt($('#navColId').css('width'));
var heightOfTop = parseInt($('#popTopRw').css('height')) + parseInt($('#headerMain').css('height'));
var mouseX = av.mouse.UpGridPos[0] - av.grd.marginX - av.grd.xOffset - offsetXLocal - widthOfNav - 5; // diane moved semicolen to right of -5
var mouseY = av.mouse.UpGridPos[1] - av.grd.marginY - av.grd.yOffset - offsetYLocal - heightOfTop - 5; // yemi: hardcoded 5; works for now
if (av.debug.dnd) { console.log('DnD: mouse.UpGridPosX, y', av.mouse.UpGridPos[0], av.mouse.UpGridPos[1]); }
if (av.debug.dnd) { console.log('DnD: mouseX, y', mouseX, mouseY); }
av.parents.col[nn] = Math.floor(mouseX / av.grd.cellWd);
av.parents.row[nn] = Math.floor(mouseY / av.grd.cellHt);
// check to see if in the grid part of the canvas
if (av.parents.col[nn] >= 0 && av.parents.col[nn] < av.grd.cols && av.parents.row[nn] >= 0 && av.parents.row[nn] < av.grd.rows) {
av.parents.AvidaNdx[nn] = av.parents.row[nn] * av.grd.cols + av.parents.col[nn];
// start setting up for getting data for parents structure
nn = av.parents.name.length; // get index into parents
// clone the element
el = el.cloneNode(true);
// get the data for the dragged element
var dir = av.fzr.dir[el.id];
// give a new id to the new dom object
el.id = 'dom_g' + av.fzr.gNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// give a new name
el.innerHTML = `<img src='images/Avida-ED-ancestor-icon.png' class='AvidianIcon'></img> ${av.dnd.nameParent(el.textContent.trim())}`;
// el.textContent = av.dnd.nameParent(el.textContent.trim());
// insert element into ancestorBox av.dnd.containerMap
av.dnd.insert(av.dnd.ancestorBox, el, 'g');
// insert element into ancestorBox DOM
av.dnd.insertToDOM(av.dnd.ancestorBox, el);
var container = target.id !== undefined ? "#" + av.dnd.ancestorBox.id : "." + av.dnd.ancestorBox.className;
if (av.debug.dnd) { console.log('DnD: av.dnd.containerMap[#ancestorBox]', av.dnd.containerMap[container]); } //av.dnd.containerMap not defined?
// Push the item to av.parents
av.parents.domid.push(el.id);
//update parents structure
av.parents.handNdx.push(nn);
av.parents.howPlaced[nn] = 'hand';
av.parents.injected[nn] = false;
if (av.debug.dnd) { console.log('DnD: av.dnd.landGridCanvas; domId', el.id, '; av.fzr.genome', av.fzr.genome); }
av.parents.genome.push(av.fzr.file[dir+'/genome.seq']);
//Find color of ancestor
if (0 < av.parents.Colors.length) {av.parents.color.push(av.parents.Colors.pop());}
else {av.parents.color.push(av.color.defaultParentColor);}
//Re-Draw Grid - done in routine that calls this one.
}
else {
// not on grid
av.post.addUser('DnD: ' + source.id + '--> GridCanvas: by: ' + el.textContent.trim());
}
//In all cases remove the ancestor from the gridCanvas so we only keep them in the av.dnd.ancestorBox.
av.dnd.empty(av.dnd.gridCanvas); //http://stackoverflow.com/questions/11909540/how-to-remove-delete-an-item-from-a-dojo-drag-and-drop-source
if (av.debug.dnd) { console.log('DnD: parents', av.parents); }
};
//-------------------------------------------------------------------------------- end av.dnd.updateFromFzrOrganism --
//------------------------------------------------------------------------------------------ av.dnd.landAncestorBox --
av.dnd.landAncestorBox = function(el, target, source) {
'use strict';
// get the data for the dragged element
var dir = av.fzr.dir[el.id];
if (source !== av.dnd.ancestorBox) {
//find genome by finding source
av.parents.genome.push(av.fzr.file[dir + '/genome.seq']);
var nn = av.parents.name.length;
av.parents.autoNdx.push(nn);
av.parents.injected.push(false);
// give a new id to the new dom object
el.id = 'dom_g' + av.fzr.gNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// rename the item with a new name
var newName = av.dnd.nameParent(el.textContent.trim());
el.innerHTML = `<img src='images/Avida-ED-ancestor-icon.png' class='AvidianIcon'></img> ${newName}`;
// el.textContent = newName;
// insert element into target av.dnd.containerMap
av.dnd.insert(target, el, 'g');
// if you place organism into ancestorBox, placement is set to 'auto'
av.parents.howPlaced.push('auto');
av.parents.domid.push(el.id); // domid in ancestorBox used to remove if square in grid moved to trashcan
if (av.debug.dnd) { console.log('DnD: av.parents.domid=', av.parents.domid); }
// find color of ancestor
if (0 < av.parents.Colors.length) { av.parents.color.push(av.parents.Colors.pop());}
else { av.parents.color.push(av.color.defaultParentColor); }
av.parents.placeAncestors();
if (av.debug.dnd) { console.log('DnD: parents', av.parents.name[nn], av.parents.domid[nn], av.parents.genome[nn]); }
av.grd.drawGridSetupFn('av.dnd.landAncestorBox');
// if the element has not been added yet to target because it has been moved from outside the dragula framework, manually add them
var childDomIds = $.map(document.querySelector('#' + target.id).children, (x) => { if (!x.classList.contains('gu-transit')) return x.id; });
if (childDomIds.indexOf(el.id) === -1) {
target.append(el);
}
return (true);
}
else { return (false); }
};
//-------------------------------------------------------------------------------------- end av.dnd.landAncestorBox --
//--------------------------------------------------------------------------------------- av.dnd.landAncestorBoTest --
av.dnd.landAncestorBoTest = function(el, target, source) {
//Do not copy parents if one is moved within Ancestor Box
'use strict';
// get the data for the dragged element
var dir = av.fzr.dir[el.id];
if (source !== av.dnd.ancestorBoTest) {
av.post.data = {
'operation' : 'DojoDnd',
'name' : 'av.dnd.landAncestorBoTest',
//'vars' : {'source' : 'av.dnd.fzOrgan', 'nodeDir': move.dir, 'target': 'av.dnd.ancestorBoTest'},
'vars' : {'source' : source.id, 'nodeDir': dir, 'target': target.id, 'call': 'dnd.landAncestorBoTest'},
'assumptions' : {'nodeName': el.textContent.trim() , 'via': 'usr'}
};
//find genome by finding source
av.parents.genome.push(av.fzr.file[dir + '/genome.seq']);
var nn = av.parents.name.length;
av.parents.autoNdx.push(nn);
av.parents.injected.push(false);
// give a new id to the new dom object
el.id = 'dom_g' + av.fzr.gNum++;
mostRecentlyAddedDomid = el.id;
// add an entry to av.fzr.dir for this new new dom id
av.fzr.dir[el.id] = dir;
// and vice versa
av.fzr.domid[dir] = el.id;
// rename the item with a new name
var newName = av.dnd.nameParent(el.textContent.trim());
el.innerHTML = `<img src='images/Avida-ED-ancestor-icon.png' class='AvidianIcon'></img> ${newName}`;
// el.textContent = newName;
// insert element into target av.dnd.containerMap
av.dnd.insert(target, el, 'g');
// if you place organism into ancestorBox, placement is set to 'auto'
av.parents.howPlaced.push('auto');
av.parents.domid.push(el.id); // domid in ancestorBox used to remove if square in grid moved to trashcan
// find color of ancestor
if (0 < av.parents.Colors.length) { av.parents.color.push(av.parents.Colors.pop());}
else { av.parents.color.push(av.color.defaultParentColor); }
av.parents.placeAncestors();
if (av.debug.dnd) { console.log('DnD: parents', av.parents.name[nn], av.parents.domid[nn], av.parents.genome[nn]); }
av.grd.drawGridSetupFn('av.dnd.landAncestorBox');
// if the element has not been added yet to target because it has been moved from outside the dragula framework, manually add them
var childDomIds = $.map(document.querySelector('#' + target.id).children, (x) => { if (!x.classList.contains('gu-transit')) return x.id;});