-
Notifications
You must be signed in to change notification settings - Fork 0
/
draganddrop.js
146 lines (124 loc) · 4.32 KB
/
draganddrop.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
function onDragStart(event) {
event.dataTransfer.setData("text", event.target.getAttribute('id'));
}
function allowDrop(ev) {
ev.preventDefault();
}
function drop(e) {
e.preventDefault();
var data = e.dataTransfer.getData("text");
// console.log('data ' + data);
var item = document.getElementById(data);
// console.log('item ' + data);
if (item) {
// debugger;
//добавить возможность перетаскивания друг на друга
let targetDiv = e.target;
var previousBoard = item.closest('.panels-board');
var targetBoard = e.target.closest('.panels-board');
// console.log(previousBoard);
state.moveItemToOtherPanel(previousBoard.id, targetBoard.id, item.id)
targetBoard.getElementsByClassName('list-group')[0].appendChild(item);
var highlighted = document.getElementsByClassName('on-delete');
for (let elem of highlighted) {
elem.className = elem.className.replace('on-delete', '');
}
// document.getElementsByClassName('alert-danger').forEach(function(elem){
// elem.className = elem.className.replace('alert-danger', '');
// });
} else {
console.error('Cannot find element, event:', e)
}
}
function dropDel(event){
event.preventDefault();
var data = event.dataTransfer.getData("text");
var item = document.getElementById(data);
var previousBoard = item.closest('.panels-board');
if (item) {
var targetDiv = event.target;
state.deleteItemFromState(previousBoard.id, item)
item.remove();
// можно как-то более изящно
localStorage.state = JSON.stringify(state);
var highlighted = document.getElementsByClassName('on-delete');
for (let elem of highlighted) {
// elem.className = elem.className.replace('on-delete', '');
elem.className = 'col-sm';
}
}else {
console.error('Cannot find element to Delete, event:', event)
}
}
function onDragLeave(event){
// console.log(event.target.className)
event.target.className = 'col-sm';
}
function dragOverDelBut(event){
// console.log(event.dataTransfer.myCount)
// if ( event.dataTransfer.myCount !== 1){
// event.dataTransfer.myCount = 0}
// // console.log('dataTransfer '+ event.dataTransfer.files)
// // event.dataTransfer.myP = 1;
// // var a = event.dataTransfer.items;
// // var b = event.dataTransfer.myP;
// // debugger
// if (event.dataTransfer.myCount === 0){
// console.log('hey')
// allowDrop(event);
// event.currentTarget.className += ' on-delete'
// event.myCount = 'dedined';
// event.dataTransfer.myCount++;
// console.log(event.dataTransfer.myCount)
// }
allowDrop(event);
event.currentTarget.className = 'col-sm on-delete';
}
/* events fired on the drop targets */
// document.addEventListener("dragenter", function(event) {
// // prevent default to allow drop
// // console.log('enter:' + event.toElement.id);
// // if (event.fromElement != null){
// // console.log('leave:' + event.fromElement.id);
// // }else {
// // console.log('leave:none');
// // }
// event.preventDefault();
// //
// }, false);
// document.addEventListener("dragleave", function(event) {
// // prevent default to allow drop
// event.preventDefault();
// var fromElement = event.fromElement;
// if (
// fromElement.className == 'row' ||
// fromElement.className == 'container' ||
// fromElement.tagName == 'span' ||
// fromElement.tagName == 'html' ||
// fromElement.tagName == 'body'
// ){
// return false;
// }
// var toElement = event.toElement;
// console.log(fromElement);
// if (fromElement == null || toElement == null){
// return false;
// }
// if (fromElement.id != 'trash'){
// addClass = ' alert-info';
// } else {
// if (event.fromElement.className.indexOf('panel-board') == -1){
// fromElement = event.fromElement.closest('.panels-board');
// }
// }
// var addClass = ' alert-info';
// if (event.toElement.className.indexOf('panel-board') == -1){
// toElement = event.toElement.closest('.panels-board');
// }
// if (fromElement != null){
// fromElement.className += addClass;
// }
// if (toElement != null){
// toElement.className = toElement.className.replace(addClass, '');
// }
// }, false);