Skip to content

Commit b8a19b9

Browse files
committed
tweaks on styles
1 parent a246a14 commit b8a19b9

File tree

4 files changed

+208
-54
lines changed

4 files changed

+208
-54
lines changed

Container.ts

Lines changed: 101 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ namespace BioDeep.UI {
3131
srcContainer: string,
3232
containers: string[]) {
3333

34-
this.containers = new Dictionary<string[]>(TypeInfo.EmptyObject(containers, () => (<string[]>[])));
34+
var union = [...containers];
35+
union.push(srcContainer);
36+
37+
this.containers = new Dictionary<string[]>(TypeInfo.EmptyObject(union, () => (<string[]>[])));
3538
this.registerDatas(items, srcContainer);
3639
this.registerContainers(containers);
40+
this.registerContainers([srcContainer]);
3741

3842
stylingContainers(containers);
3943
stylingItems(From(items).Select(id => id.key));
44+
stylingContainers([srcContainer]);
4045
}
4146

4247
private registerContainers(names: string[]) {
@@ -56,6 +61,7 @@ namespace BioDeep.UI {
5661
*/
5762
private binEach(bin: HTMLElement, container: Dictionary<string[]>) {
5863
var key: string = bin.id;
64+
var dev = this;
5965

6066
Linq.DOM.addEvent(bin, 'dragover', function (e) {
6167
if (e.preventDefault) {
@@ -88,26 +94,67 @@ namespace BioDeep.UI {
8894
var event = <DragEvent>e;
8995
var strval: string = event.dataTransfer.getData('Text');
9096

91-
console.log(strval);
97+
// console.log(strval);
9298

9399
var data = <Map<string, string>>JSON.parse(strval);
94100
var keyId: string = data.key;
95101
var el = document.getElementById(keyId);
102+
// var newItem = Container.createNewItem(data);
103+
var newItem = Container.createItem(data);
96104

97-
el.parentNode.removeChild(el);
105+
el.parentNode.parentNode.removeChild(el.parentNode);
98106
// stupid nom text + fade effect
99107
bin.className = '';
100-
document.getElementById(`${bin.id}-ul`).appendChild(Container.createItem(data).key);
108+
document.getElementById(`${bin.id}-ul`).appendChild(newItem.key);
101109
applyItemStyle(keyId);
110+
dev.registerItemDragEvent(newItem.value);
111+
112+
container.Keys.ForEach(key => {
113+
if (container.Item(key).indexOf(data.key) > -1) {
114+
var list = From(container.Item(key))
115+
.Where(id => id != data.key)
116+
.ToArray();
117+
118+
container.Delete(key).Add(key, list);
119+
}
120+
})
102121

103122
// 在这里得到data数据之后,将数据添加进入对应的容器之中
104-
// console.log(container);
123+
105124
container.Item(key).push(data.key);
125+
localStorage.setItem("groupset", JSON.stringify(dev.Data));
106126

127+
// console.log(container);
107128
return false;
108129
});
109130
}
110131

132+
/**
133+
* 将其他的容器之中的数据给删除
134+
*/
135+
// public deleteData(idValue: string ) {
136+
137+
138+
// }
139+
140+
private registerItemDragEvent(a: HTMLAnchorElement): void {
141+
a.setAttribute('draggable', 'true');
142+
143+
Linq.DOM.addEvent(a, 'dragstart', function (e) {
144+
var event = <DragEvent>e;
145+
var data: string = JSON.stringify({
146+
key: a.id,
147+
value: a.innerText
148+
});
149+
150+
// only dropEffect='copy' will be dropable
151+
event.dataTransfer.effectAllowed = 'copy';
152+
// required otherwise doesn't work
153+
event.dataTransfer.setData('Text', data);
154+
});
155+
}
156+
157+
111158
/**
112159
* 为数据对象在容器之中注册鼠标事件
113160
*/
@@ -120,27 +167,61 @@ namespace BioDeep.UI {
120167
})
121168
data.Select(a => a.value)
122169
.ForEach(el => {
123-
el.setAttribute('draggable', 'true');
124-
125-
Linq.DOM.addEvent(el, 'dragstart', function (e) {
126-
var event = <DragEvent>e;
127-
var data: string = JSON.stringify({
128-
key: el.id,
129-
value: el.innerText
130-
});
131-
132-
// only dropEffect='copy' will be dropable
133-
event.dataTransfer.effectAllowed = 'copy';
134-
// required otherwise doesn't work
135-
event.dataTransfer.setData('Text', data);
136-
});
170+
this.registerItemDragEvent(el);
137171
});
138172
}
139173

140-
private static createItem(item: Map<string, string>): Map<HTMLLIElement, HTMLAnchorElement> {
174+
/**
175+
* 测试部分开始
176+
*/
177+
178+
/**
179+
* 原始数据分组移动时,在新的分组中添加数据显示
180+
*/
181+
182+
private static createNewItem(item: Map<string, string>): Map<HTMLLIElement, HTMLAnchorElement> {
141183
var li = document.createElement("li");
142184
var a = document.createElement("a");
185+
var i_tag = document.createElement("i");
186+
187+
a.id = item.key;
188+
a.href = "#";
189+
a.innerText = item.value;
190+
var a_style = a.style;
191+
a_style.cssFloat = "left";
192+
li.appendChild(a);
193+
194+
i_tag.className = "fa fa-times";
195+
i_tag.onclick = function() {
196+
i_tag.parentNode.removeChild(i_tag);
197+
198+
};
199+
var style = i_tag.style;
200+
style.lineHeight = "line-height: 52px";
201+
style.color = "red";
202+
style.fontSize = "20px";
203+
style.cursor = "pointer";
204+
style.cssFloat = "right";
205+
style.marginRight = "10px";
206+
style.marginTop = "20px";
207+
li.appendChild(i_tag);
208+
209+
return <Map<HTMLLIElement, HTMLAnchorElement>>{
210+
key: li, value: a
211+
};
212+
}
213+
214+
215+
/**
216+
* 测试结束
217+
*/
143218

219+
220+
221+
private static createItem(item: Map<string, string>): Map<HTMLLIElement, HTMLAnchorElement> {
222+
var li = document.createElement("li");
223+
var a = document.createElement("a");
224+
144225
a.id = item.key;
145226
a.href = "#";
146227
a.innerText = item.value;

Styles.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
var div = document.getElementById(id);
66
var style = div.style;
77

8-
style.height = "250px";
9-
style.width = "166px";
8+
style.height = "450px";
9+
style.width = "100%";
1010
style.cssFloat = "left";
11-
style.border = "5px solid #000";
11+
style.backgroundColor = "#d9edf7";
12+
style.borderRadius = "5px";
1213
style.position = "relative";
1314
style.marginTop = "0";
1415
})
@@ -29,12 +30,17 @@
2930
var style = a.style;
3031

3132
style.textDecoration = "none";
32-
style.color = "#000";
33-
style.margin = "10px";
34-
style.width = "150px";
35-
style.border = "3px dashed #999";
36-
style.background = "#eee";
33+
style.width = "85%";
34+
style.background = "rgb(238, 238, 238)";
3735
style.padding = "10px";
3836
style.display = "block";
37+
style.color = "#fff";
38+
style.margin = "10px 0px 10px 5%";
39+
style.backgroundColor = "#1ea2e9";
40+
style.border = "1px solid #428bca";
41+
style.cursor = "pointer";
42+
style.borderRadius = "5px";
43+
style.fontSize = "13px";
44+
3945
}
4046
}

test/drag_and_drop.js

Lines changed: 92 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)