| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/array", |
| 5 |
"dojo/dom-geometry", |
| 6 |
"dojox/mdnd/AreaManager" |
| 7 |
],function(dojo, declare, array, geom, AreaManager){ |
| 8 |
var ddm = declare("dojox.mdnd.dropMode.DefaultDropMode", null, { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
_oldXPoint: null, |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
_oldYPoint: null, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
_oldBehaviour: "up", |
| 24 |
|
| 25 |
addArea: function(areas, object){ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
var length = areas.length; |
| 37 |
var position = geom.position(object.node, true); |
| 38 |
object.coords = {'x':position.x, 'y':position.y}; |
| 39 |
if (length == 0) { |
| 40 |
areas.push(object); |
| 41 |
}else{ |
| 42 |
var x = object.coords.x; |
| 43 |
for (var i = 0; i < length; i++) { |
| 44 |
if (x < areas[i].coords.x) { |
| 45 |
for (var j = length-1; j >= i; j--) |
| 46 |
areas[j + 1] = areas[j]; |
| 47 |
areas[i] = object; |
| 48 |
break; |
| 49 |
} |
| 50 |
} |
| 51 |
if (i == length) |
| 52 |
areas.push(object); |
| 53 |
} |
| 54 |
return areas; |
| 55 |
}, |
| 56 |
|
| 57 |
updateAreas: function(areaList){ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
var length = areaList.length; |
| 70 |
if (length > 1){ |
| 71 |
var currentRight, nextLeft; |
| 72 |
for (var i = 0; i < length; i++) { |
| 73 |
var area = areaList[i]; |
| 74 |
var nextArea; |
| 75 |
area.coords.x1 = -1; |
| 76 |
area.coords.x2 = -1; |
| 77 |
if (i == 0) { |
| 78 |
nextArea = areaList[i+1]; |
| 79 |
this._updateArea(area); |
| 80 |
this._updateArea(nextArea); |
| 81 |
currentRight = area.coords.x + area.node.offsetWidth; |
| 82 |
nextLeft = nextArea.coords.x; |
| 83 |
area.coords.x2 = currentRight + (nextLeft-currentRight)/2; |
| 84 |
} |
| 85 |
else if (i == length-1) { |
| 86 |
area.coords.x1 = areaList[i-1].coords.x2; |
| 87 |
}else{ |
| 88 |
nextArea = areaList[i+1]; |
| 89 |
this._updateArea(nextArea); |
| 90 |
currentRight = area.coords.x + area.node.offsetWidth; |
| 91 |
nextLeft = nextArea.coords.x; |
| 92 |
area.coords.x1 = areaList[i-1].coords.x2; |
| 93 |
area.coords.x2 = currentRight + (nextLeft-currentRight)/2; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
}, |
| 98 |
|
| 99 |
_updateArea : function(area){ |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
var position = geom.position(area.node, true); |
| 109 |
area.coords.x = position.x; |
| 110 |
area.coords.y = position.y; |
| 111 |
}, |
| 112 |
|
| 113 |
initItems: function(area){ |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
array.forEach(area.items, function(obj){ |
| 121 |
|
| 122 |
var node = obj.item.node; |
| 123 |
var position = geom.position(node, true); |
| 124 |
var y = position.y + position.h/2; |
| 125 |
obj.y = y; |
| 126 |
}); |
| 127 |
area.initItems = true; |
| 128 |
}, |
| 129 |
|
| 130 |
refreshItems: function(area, indexItem, size, added){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
if (indexItem == -1) { |
| 144 |
return; |
| 145 |
}else if(area && size && size.h){ |
| 146 |
var height = size.h; |
| 147 |
if (area.margin){ |
| 148 |
height += area.margin.t; |
| 149 |
} |
| 150 |
var length = area.items.length; |
| 151 |
for (var i=indexItem; i<length; i++){ |
| 152 |
var item = area.items[i]; |
| 153 |
if (added) { |
| 154 |
item.y += height; |
| 155 |
}else{ |
| 156 |
item.y -= height; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
}, |
| 161 |
|
| 162 |
getDragPoint: function(coords, size, mousePosition){ |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
var y = coords.y; |
| 184 |
if (this._oldYPoint){ |
| 185 |
if (y > this._oldYPoint) { |
| 186 |
this._oldBehaviour = "down"; |
| 187 |
y += size.h; |
| 188 |
} |
| 189 |
else |
| 190 |
if (y <= this._oldYPoint) { |
| 191 |
this._oldBehaviour = "up"; |
| 192 |
} |
| 193 |
} |
| 194 |
this._oldYPoint = y; |
| 195 |
return { |
| 196 |
'x': coords.x + (size.w / 2), |
| 197 |
'y': y |
| 198 |
}; |
| 199 |
}, |
| 200 |
|
| 201 |
getTargetArea: function(areaList, coords, currentIndexArea ){ |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
var index = 0; |
| 216 |
var x = coords.x; |
| 217 |
var end = areaList.length; |
| 218 |
if (end > 1) { |
| 219 |
var start = 0, direction = "right", compute = false; |
| 220 |
if (currentIndexArea == -1 || arguments.length<3) { |
| 221 |
|
| 222 |
compute = true; |
| 223 |
} |
| 224 |
else { |
| 225 |
|
| 226 |
if (this._checkInterval(areaList, currentIndexArea, x)){ |
| 227 |
index = currentIndexArea; |
| 228 |
}else{ |
| 229 |
if (this._oldXPoint < x){ |
| 230 |
start = currentIndexArea + 1; |
| 231 |
}else{ |
| 232 |
start = currentIndexArea - 1; |
| 233 |
end = 0; |
| 234 |
direction = "left"; |
| 235 |
} |
| 236 |
compute = true; |
| 237 |
} |
| 238 |
} |
| 239 |
if (compute) { |
| 240 |
if (direction === "right") { |
| 241 |
for (var i = start; i < end; i++) { |
| 242 |
if (this._checkInterval(areaList, i, x)) { |
| 243 |
index = i; |
| 244 |
break; |
| 245 |
} |
| 246 |
} |
| 247 |
}else{ |
| 248 |
for (var i = start; i >= end; i--) { |
| 249 |
if (this._checkInterval(areaList, i, x)) { |
| 250 |
index = i; |
| 251 |
break; |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
this._oldXPoint = x; |
| 258 |
return index; |
| 259 |
}, |
| 260 |
|
| 261 |
_checkInterval: function(areaList, index, x){ |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
var coords = areaList[index].coords; |
| 277 |
if (coords.x1 == -1) { |
| 278 |
if (x <= coords.x2) { |
| 279 |
return true; |
| 280 |
} |
| 281 |
} |
| 282 |
else |
| 283 |
if (coords.x2 == -1) { |
| 284 |
if (x > coords.x1) { |
| 285 |
return true; |
| 286 |
} |
| 287 |
} |
| 288 |
else { |
| 289 |
if (coords.x1 < x && x <= coords.x2) { |
| 290 |
return true; |
| 291 |
} |
| 292 |
} |
| 293 |
return false; |
| 294 |
}, |
| 295 |
|
| 296 |
getDropIndex: function( targetArea, coords){ |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
var length = targetArea.items.length; |
| 309 |
var coordinates = targetArea.coords; |
| 310 |
var y = coords.y; |
| 311 |
if (length > 0) { |
| 312 |
|
| 313 |
for (var i = 0; i < length; i++) { |
| 314 |
|
| 315 |
if (y < targetArea.items[i].y) { |
| 316 |
return i; |
| 317 |
} |
| 318 |
else { |
| 319 |
if (i == length-1) { |
| 320 |
return -1; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
return -1; |
| 326 |
}, |
| 327 |
|
| 328 |
destroy: function(){ |
| 329 |
|
| 330 |
} |
| 331 |
}); |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
AreaManager.areaManager()._dropMode = new ddm(); |
| 337 |
return ddm; |
| 338 |
}); |