|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>Interaction Groups</title> |
|
|
7 |
|
|
|
8 |
<style type="text/css"> |
|
|
9 |
/*margin and padding on body element |
|
|
10 |
can introduce errors in determining |
|
|
11 |
element position and are not recommended; |
|
|
12 |
we turn them off as a foundation for YUI |
|
|
13 |
CSS treatments. */ |
|
|
14 |
body { |
|
|
15 |
margin:0; |
|
|
16 |
padding:0; |
|
|
17 |
} |
|
|
18 |
</style> |
|
|
19 |
|
|
|
20 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
21 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
22 |
|
|
|
23 |
<!--there is no custom header content for this example--> |
|
|
24 |
|
|
|
25 |
</head> |
|
|
26 |
|
|
|
27 |
<body class=" yui-skin-sam"> |
|
|
28 |
|
|
|
29 |
<h1>Interaction Groups</h1> |
|
|
30 |
|
|
|
31 |
<div class="exampleIntro"> |
|
|
32 |
<p>Using interaction groups, this example demonstrates how to tie into the Drag & Drop Utility's interesting moments to provide visual affordances for the current drag operation.</p> |
|
|
33 |
|
|
|
34 |
</div> |
|
|
35 |
|
|
|
36 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
37 |
|
|
|
38 |
<style> |
|
|
39 |
.slot { |
|
|
40 |
border: 2px solid #808080; |
|
|
41 |
background-color: #CDCDCD; |
|
|
42 |
color: #666666; |
|
|
43 |
text-align: center; |
|
|
44 |
position: relative; |
|
|
45 |
float: left; |
|
|
46 |
margin: 4px; |
|
|
47 |
width: 60px; |
|
|
48 |
height: 60px; |
|
|
49 |
z-index: 0; |
|
|
50 |
} |
|
|
51 |
.player { |
|
|
52 |
border: 2px solid #808080; |
|
|
53 |
color: #ffffff; |
|
|
54 |
text-align: center; |
|
|
55 |
position: relative; |
|
|
56 |
float: left; |
|
|
57 |
margin: 4px; |
|
|
58 |
width: 60px; |
|
|
59 |
height: 60px; |
|
|
60 |
top: 150px; |
|
|
61 |
z-index: 1; |
|
|
62 |
cursor: move; |
|
|
63 |
} |
|
|
64 |
#pt1 { |
|
|
65 |
clear: both; |
|
|
66 |
} |
|
|
67 |
.bottom { |
|
|
68 |
top: 50px; |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
#pt1, #pt2 { |
|
|
72 |
background-color: #71241A; |
|
|
73 |
} |
|
|
74 |
#pb1, #pb2 { |
|
|
75 |
background-color: #004C6D; |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
#pboth1, #pboth2 { |
|
|
79 |
background-color: #FFA928; |
|
|
80 |
} |
|
|
81 |
|
|
|
82 |
#workarea { |
|
|
83 |
position: relative; |
|
|
84 |
height: 300px; |
|
|
85 |
width: 500px; |
|
|
86 |
} |
|
|
87 |
#workarea .yui-dd-drop-active-valid { |
|
|
88 |
border: 2px solid green; |
|
|
89 |
} |
|
|
90 |
#workarea .yui-dd-drop-over { |
|
|
91 |
background-color: green; |
|
|
92 |
} |
|
|
93 |
#workarea .yui-dd-drop-active-invalid { |
|
|
94 |
border: 2px solid red; |
|
|
95 |
} |
|
|
96 |
</style> |
|
|
97 |
|
|
|
98 |
<div id="workarea"> |
|
|
99 |
|
|
|
100 |
<div class="slot" id="t1">1</div> |
|
|
101 |
<div class="slot bottom" id="b1">3</div> |
|
|
102 |
<div class="slot bottom" id="b2">4</div> |
|
|
103 |
<div class="slot bottom" id="b3">5</div> |
|
|
104 |
<div class="slot bottom" id="b4">6</div> |
|
|
105 |
<div class="slot" id="t2">2</div> |
|
|
106 |
|
|
|
107 |
|
|
|
108 |
<div class="player" id="pt1">1</div> |
|
|
109 |
<div class="player" id="pt2">2</div> |
|
|
110 |
<div class="player" id="pb1">3</div> |
|
|
111 |
<div class="player" id="pb2">4</div> |
|
|
112 |
<div class="player" id="pboth1">5</div> |
|
|
113 |
<div class="player" id="pboth2">6</div> |
|
|
114 |
|
|
|
115 |
</div> |
|
|
116 |
|
|
|
117 |
<script> |
|
|
118 |
var config = {base:"../../build/", timeout: 10000}; |
|
|
119 |
config.filter = 'raw'; |
|
|
120 |
YUI(config).use('dd-drop', 'dd-proxy', 'dd-constrain', function(Y) { |
|
|
121 |
|
|
|
122 |
var slots = Y.Node.get('#workarea').queryAll('.slot'); |
|
|
123 |
Y.each(slots, function(v, k) { |
|
|
124 |
var id = v.get('id'), groups = ['two']; |
|
|
125 |
switch (id) { |
|
|
126 |
case 't1': |
|
|
127 |
case 't2': |
|
|
128 |
groups = ['one']; |
|
|
129 |
break; |
|
|
130 |
} |
|
|
131 |
var drop = new Y.DD.Drop({ |
|
|
132 |
node: v, |
|
|
133 |
groups: groups |
|
|
134 |
}); |
|
|
135 |
}); |
|
|
136 |
|
|
|
137 |
var players = Y.Node.get('#workarea').queryAll('.player'); |
|
|
138 |
Y.each(players, function(v, k) { |
|
|
139 |
var id = v.get('id'), groups = ['one', 'two']; |
|
|
140 |
switch (id) { |
|
|
141 |
case 'pt1': |
|
|
142 |
case 'pt2': |
|
|
143 |
groups = ['one']; |
|
|
144 |
break; |
|
|
145 |
case 'pb1': |
|
|
146 |
case 'pb2': |
|
|
147 |
groups = ['two']; |
|
|
148 |
break; |
|
|
149 |
} |
|
|
150 |
var drag = new Y.DD.Drag({ |
|
|
151 |
node: v, |
|
|
152 |
groups: groups, |
|
|
153 |
dragMode: 'intersect' |
|
|
154 |
}).plug(Y.Plugin.DDProxy, { |
|
|
155 |
moveOnEnd: false |
|
|
156 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
157 |
constrain2node: '#workarea' |
|
|
158 |
}); |
|
|
159 |
drag.on('drag:start', function() { |
|
|
160 |
var p = this.get('dragNode'), |
|
|
161 |
n = this.get('node'); |
|
|
162 |
n.setStyle('opacity', .25); |
|
|
163 |
if (!this._playerStart) { |
|
|
164 |
this._playerStart = this.nodeXY; |
|
|
165 |
} |
|
|
166 |
p.set('innerHTML', n.get('innerHTML')); |
|
|
167 |
p.setStyles({ |
|
|
168 |
backgroundColor: n.getStyle('backgroundColor'), |
|
|
169 |
color: n.getStyle('color'), |
|
|
170 |
opacity: .65 |
|
|
171 |
}); |
|
|
172 |
}); |
|
|
173 |
drag.on('drag:end', function() { |
|
|
174 |
var n = this.get('node'); |
|
|
175 |
n.setStyle('opacity', '1'); |
|
|
176 |
}); |
|
|
177 |
drag.on('drag:drophit', function(e) { |
|
|
178 |
var xy = e.drop.get('node').getXY(); |
|
|
179 |
this.get('node').setXY(xy, Y.UA.ie); |
|
|
180 |
}); |
|
|
181 |
drag.on('drag:dropmiss', function(e) { |
|
|
182 |
if (this._playerStart) { |
|
|
183 |
this.get('node').setXY(this._playerStart, Y.UA.ie); |
|
|
184 |
this._playerStart = null; |
|
|
185 |
} |
|
|
186 |
}); |
|
|
187 |
}); |
|
|
188 |
}); |
|
|
189 |
</script> |
|
|
190 |
|
|
|
191 |
|
|
|
192 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
193 |
|
|
|
194 |
</body> |
|
|
195 |
</html> |