Debian Codegraph @

dojox/mdnd/tests/unitTests/dropMode/DefaultDropModeTest.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5
6 <title>DefaultDropMode</title>
7
8 <script type="text/javascript"
9 src="../../../../../dojo/dojo.js"
10 data-dojo-config="isDebug: true, parseOnLoad: true">
11 </script>
12
13 <script type="text/javascript">
14 dojo.require("dijit.robotx");
15 dojo.require("dojo.parser");
16 dojo.require("dojox.mdnd.tests.unitTests.dropMode.FixtureLib");
17 dojo.require("dojox.mdnd.dropMode.DefaultDropMode");
18
19 dojo.addOnLoad(function(){
20
21 doh.robot.initRobot('resources/domElement.html');
22
23 doh.register("getDragPoint",
24 [
25 // summary:
26 // getDragPoint get the reference point used to
27 // represent the drag item.
28 //
29 // For the defaultDropMode, this point varies with the
30 // direction of moving (up or down).
31
32 new getDragPointFixture("firstCall",function(){
33 // On the first call, this point is :
34 // X = (X position + width/2)
35 // Y = Y position
36 var point = this.dropMode.getDragPoint(this.coords, this.size, this.mousePosition);
37 doh.assertTrue(point.x === 75);
38 doh.assertTrue(point.y === 50);
39 }),
40
41 new getDragPointFixture("moveHorizontal",function(){
42 // The drag item move from (25,50) to (125,50).
43 // X = (X position + width/2)
44 // Y = Y position
45
46 //1st call
47 this.dropMode.getDragPoint(this.coords, this.size, this.mousePosition);
48 //2nd call
49 var point = this.dropMode.getDragPoint(
50 {'x':125,'y':50},
51 this.size);
52 doh.assertTrue(point.x === 175);
53 doh.assertTrue(point.y === 50);
54 }),
55
56 new getDragPointFixture("moveUp",function(){
57 // The drag item move from (25,50) to (25,0).
58 // X = (X position + width/2)
59 // Y = Y position
60
61 //1st call
62 this.dropMode.getDragPoint(this.coords, this.size, this.mousePosition);
63 //2nd call
64 var point = this.dropMode.getDragPoint(
65 {'x':25,'y':0},
66 this.size);
67 doh.assertTrue(point.x === 75);
68 doh.assertTrue(point.y === 0);
69 }),
70
71 new getDragPointFixture("moveDown",function(){
72 // The drag item move from (25,50) to (25,0).
73 // X = (X position + width/2)
74 // Y = Y position + Y size
75
76 //1st call
77 this.dropMode.getDragPoint(this.coords, this.size, this.mousePosition);
78 //2nd call
79 var point = this.dropMode.getDragPoint(
80 {'x':25,'y':75},
81 this.size);
82 doh.assertTrue(point.x === 75);
83 doh.assertTrue(point.y === 175);
84 })
85 ]
86 );
87
88 doh.register("addArea",
89 [
90 // summary:
91 // addArea allows to add a DnD area. They are sorted
92 // by their x position.
93
94 new AreaFixture("addAnArea", function(){
95 this.dropMode.addArea(this.array, this.objectA);
96 doh.assertTrue(this.array.length === 1);
97 doh.assertTrue(this.objectA.coords.x === 50 && this.objectA.coords.y === 50);
98 }),
99
100 new AreaFixture("addAtStart", function(){
101 this.dropMode.addArea(this.array, this.objectB);
102 this.dropMode.addArea(this.array, this.objectA);
103 doh.assertTrue(this.array.length === 2);
104 doh.assertTrue(this.array[0]=== this.objectA);
105 }),
106
107 new AreaFixture("addAtEnd", function(){
108 this.dropMode.addArea(this.array, this.objectB);
109 this.dropMode.addArea(this.array, this.objectC);
110 doh.assertTrue(this.array.length === 2);
111 doh.assertTrue(this.array[1] === this.objectC);
112 }),
113
114 new AreaFixture("addAtMiddle", function(){
115 this.dropMode.addArea(this.array, this.objectB);
116 this.dropMode.addArea(this.array, this.objectD);
117 console.dir(this.array);
118 this.dropMode.addArea(this.array, this.objectC);
119 doh.assertTrue(this.array.length === 3);
120 doh.assertTrue(this.array[1] === this.objectC);
121 })
122 ]
123 );
124
125 doh.register("updateAreas",
126 [
127 // summary:
128 // Refresh intervals between areas to determinate the
129 // nearest area to drop an item.
130
131 new AreaFixture("areaDropZone", function(){
132 this.dropMode.addArea(this.array, this.objectA);
133 this.dropMode.addArea(this.array, this.objectB);
134 this.dropMode.addArea(this.array, this.objectC);
135 this.dropMode.addArea(this.array, this.objectD);
136 this.dropMode.updateAreas(this.array);
137
138 doh.assertTrue(this.objectA.coords.x1 === -1 && this.objectA.coords.x2 === 176);
139 doh.assertTrue(this.objectB.coords.x1 === 176 && this.objectB.coords.x2 === 326);
140 doh.assertTrue(this.objectD.coords.x1 === 601 && this.objectD.coords.x2 === -1);
141 }),
142
143 new AreaFixture("updateDOMCoord", function(){
144 this.dropMode.addArea(this.array, this.objectA);
145 this.dropMode.addArea(this.array, this.objectB);
146 this.dropMode.addArea(this.array, this.objectC);
147 this.dropMode.addArea(this.array, this.objectD);
148 this.dropMode.updateAreas(this.array);
149
150 doh.assertTrue(this.objectC.coords.x === 350 && this.objectC.coords.y === 50);
151 doh.assertTrue(this.objectC.coords.x1 === 326 && this.objectC.coords.x2 === 601);
152 var domNode = this.objectC.node;
153 dojo.style(domNode,{'left': '400px','top':'25px'});
154 this.dropMode.updateAreas(this.array);
155 doh.assertTrue(this.objectC.coords.x === 400 && this.objectC.coords.y === 25);
156 doh.assertTrue(this.objectC.coords.x1 === 351 && this.objectC.coords.x2 === 626);
157 })
158 ]
159 );
160
161 doh.register("initItems",
162 [
163 // summary:
164 // iniItems allows to initialize the horizontal line
165 // in order to determinate the drop zone.
166
167 new ItemFixture("initItems", function(){
168
169 this.object = {
170 'items':[this.itemA]
171 }
172 this.dropMode.initItems(this.object);
173
174 doh.assertTrue(this.itemA.y === 551);
175 }),
176
177 new ItemFixture("initItems2", function(){
178
179 this.object = {
180 'items':[this.itemA, this.itemB, this.itemC, this.itemD]
181 }
182 this.dropMode.initItems(this.object);
183
184 doh.assertTrue(this.itemA.y === 551);
185 doh.assertTrue(this.itemB.y === 701);
186 doh.assertTrue(this.itemC.y === 851);
187 doh.assertTrue(this.itemD.y === 1051);
188 })
189 ]
190 );
191
192 doh.register("refreshItems",
193 [
194 new ItemFixture("addAtStart", function(){
195
196 this.object = {
197 'items':[this.itemA, this.itemB, this.itemC, this.itemD]
198 }
199 this.dropMode.initItems(this.object);
200 this.dropMode.refreshItems(this.object, 0, {h:50,w:50}, true);
201
202 doh.assertTrue(this.itemA.y === 601);
203 }),
204
205 new ItemFixture("addDropIndicator", function(){
206
207 this.object = {
208 'items':[this.itemA, this.itemB, this.itemC, this.itemD]
209 }
210 this.dropMode.initItems(this.object);
211 this.dropMode.refreshItems(this.object, 2, {h:50,w:50}, true);
212 doh.assertTrue(this.itemB.y === 701);
213 doh.assertTrue(this.itemD.y === 1101);
214 }),
215
216 new ItemFixture("removeDropIndicator", function(){
217
218 this.object = {
219 'items':[this.itemA, this.itemB, this.itemC, this.itemD]
220 }
221 this.dropMode.initItems(this.object);
222 this.dropMode.refreshItems(this.object, 2, {h:50,w:50}, true);
223
224 doh.assertTrue(this.itemB.y === 701);
225 doh.assertTrue(this.itemD.y === 1101);
226
227 this.dropMode.refreshItems(this.object, 2, {h:50,w:50}, false);
228
229 doh.assertTrue(this.itemB.y === 701);
230 doh.assertTrue(this.itemD.y === 1051);
231 })
232 ]
233 );
234
235 doh.run();
236 });
237 </script>
238 <style type="text/css"></style>
239 </head>
240 <body></body>
241 </html>