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