drag.js
13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
$axure.internal(function($ax) {
var widgetDragInfo = new Object();
var _drag = {};
$ax.drag = _drag;
$ax.drag.GetWidgetDragInfo = function() {
return $.extend({}, widgetDragInfo);
};
$ax.drag.StartDragWidget = function(event, id) {
$ax.setjBrowserEvent(jQuery.Event(event));
if(event.donotdrag) return;
var x, y;
var tg;
if(IE_10_AND_BELOW) {
x = window.event.clientX + window.document.documentElement.scrollLeft + window.document.body.scrollLeft;
y = window.event.clientY + window.document.documentElement.scrollTop + window.document.body.scrollTop;
tg = window.event.srcElement;
} else {
if(event.changedTouches) {
x = event.changedTouches[0].pageX;
y = event.changedTouches[0].pageY;
} else {
x = event.pageX;
y = event.pageY;
event.preventDefault();
}
tg = event.target;
}
widgetDragInfo.hasStarted = false;
widgetDragInfo.widgetId = id;
widgetDragInfo.cursorStartX = x;
widgetDragInfo.cursorStartY = y;
widgetDragInfo.lastX = x;
widgetDragInfo.lastY = y;
widgetDragInfo.currentX = x;
widgetDragInfo.currentY = y;
widgetDragInfo.movedWidgets = new Object();
widgetDragInfo.startTime = (new Date()).getTime();
widgetDragInfo.targetWidget = tg;
var movedownName = IE_10_AND_BELOW && $ax.features.supports.windowsMobile ?
$ax.features.eventNames.mouseDownName : $ax.features.eventNames.mouseMoveName;
$ax.event.addEvent(document, movedownName, _dragWidget, true);
$ax.event.addEvent(document, $ax.features.eventNames.mouseUpName, _stopDragWidget, true);
// if(IE && BROWSER_VERSION < 9) {
// if($ax.features.supports.windowsMobile) {
// window.document.attachEvent($ax.features.eventNames.mouseDownName, _dragWidget);
// window.document.attachEvent($ax.features.eventNames.mouseUpName, _stopDragWidget);
// } else {
// window.document.attachEvent('on' + $ax.features.eventNames.mouseMoveName, _dragWidget);
// window.document.attachEvent('on' + $ax.features.eventNames.mouseUpName, _stopDragWidget);
// }
// } else {
// window.document.addEventListener($ax.features.eventNames.mouseMoveName, _dragWidget, true);
// window.document.addEventListener($ax.features.eventNames.mouseUpName, _stopDragWidget, true);
// }
$ax.legacy.SuppressBubble(event);
};
var _dragWidget = function(event) {
$ax.setjBrowserEvent(jQuery.Event(event));
var x, y;
if(IE_10_AND_BELOW) {
x = window.event.clientX + window.document.documentElement.scrollLeft + window.document.body.scrollLeft;
y = window.event.clientY + window.document.documentElement.scrollTop + window.document.body.scrollTop;
} else {
if(event.changedTouches) {
x = event.changedTouches[0].pageX;
y = event.changedTouches[0].pageY;
//allow scroll (defaults) if only swipe events have cases and delta x is less than 5px and not blocking scrolling
var deltaX = x - widgetDragInfo.currentX;
var target = window.document.getElementById(widgetDragInfo.widgetId);
if($ax.event.hasSyntheticEvent(widgetDragInfo.widgetId, "onDrag") || $ax.event.hasSyntheticEvent(widgetDragInfo.widgetId, "onSwipeUp") ||
$ax.event.hasSyntheticEvent(widgetDragInfo.widgetId, "onSwipeDown") || (deltaX * deltaX) > 25
|| ($ax.document.configuration.preventScroll && $ax.legacy.GetScrollable(target) == window.document.body)) {
event.preventDefault();
}
} else {
x = event.pageX;
y = event.pageY;
}
}
widgetDragInfo.xDelta = x - widgetDragInfo.currentX;
widgetDragInfo.yDelta = y - widgetDragInfo.currentY;
widgetDragInfo.lastX = widgetDragInfo.currentX;
widgetDragInfo.lastY = widgetDragInfo.currentY;
widgetDragInfo.currentX = x;
widgetDragInfo.currentY = y;
widgetDragInfo.currentTime = (new Date()).getTime();
$ax.legacy.SuppressBubble(event);
if(!widgetDragInfo.hasStarted) {
widgetDragInfo.hasStarted = true;
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onDragStart");
widgetDragInfo.oldBodyCursor = window.document.body.style.cursor;
window.document.body.style.cursor = 'move';
var widget = window.document.getElementById(widgetDragInfo.widgetId);
widgetDragInfo.oldCursor = widget.style.cursor;
widget.style.cursor = 'move';
}
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onDrag");
};
var _suppressClickAfterDrag = function(event) {
_removeSuppressEvents();
$ax.legacy.SuppressBubble(event);
};
var _removeSuppressEvents = function () {
if(IE_10_AND_BELOW) {
$ax.event.removeEvent(event.srcElement, 'click', _suppressClickAfterDrag, undefined, true);
$ax.event.removeEvent(widgetDragInfo.targetWidget, 'mousemove', _removeSuppressEvents, undefined, true);
} else {
$ax.event.removeEvent(document, "click", _suppressClickAfterDrag, true);
$ax.event.removeEvent(document, 'mousemove', _removeSuppressEvents, true);
}
};
var _stopDragWidget = function(event) {
$ax.setjBrowserEvent(jQuery.Event(event));
var tg;
var movedownName = IE_10_AND_BELOW && $ax.features.supports.windowsMobile ?
$ax.features.eventNames.mouseDownName : $ax.features.eventNames.mouseMoveName;
$ax.event.removeEvent(document, movedownName, _dragWidget, true);
$ax.event.removeEvent(document, $ax.features.eventNames.mouseUpName, _stopDragWidget, true);
tg = IE_10_AND_BELOW ? window.event.srcElement : event.target;
//
//
// if(OLD_IE && BROWSER_VERSION < 9) {
// if($ax.features.supports.windowsMobile) {
// window.document.detachEvent($ax.features.eventNames.mouseDownName, _dragWidget);
// window.document.detachEvent($ax.features.eventNames.mouseUpName, _stopDragWidget);
//
// } else {
// window.document.detachEvent('on' + $ax.features.eventNames.mouseMoveName, _dragWidget);
// window.document.detachEvent('on' + $ax.features.eventNames.mouseUpName, _stopDragWidget);
// }
// tg = window.event.srcElement;
// } else {
// window.document.removeEventListener($ax.features.eventNames.mouseMoveName, _dragWidget, true);
// window.document.removeEventListener($ax.features.eventNames.mouseUpName, _stopDragWidget, true);
// tg = event.target;
// }
if(widgetDragInfo.hasStarted) {
widgetDragInfo.currentTime = (new Date()).getTime();
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onDragDrop");
if($ax.globalVariableProvider.getVariableValue('totaldragx') < -30 && $ax.globalVariableProvider.getVariableValue('dragtime') < 1000) {
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onSwipeLeft");
}
if($ax.globalVariableProvider.getVariableValue('totaldragx') > 30 && $ax.globalVariableProvider.getVariableValue('dragtime') < 1000) {
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onSwipeRight");
}
var totalDragY = $ax.globalVariableProvider.getVariableValue('totaldragy');
if(totalDragY < -30 && $ax.globalVariableProvider.getVariableValue('dragtime') < 1000) {
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onSwipeUp");
}
if(totalDragY > 30 && $ax.globalVariableProvider.getVariableValue('dragtime') < 1000) {
$ax.event.raiseSyntheticEvent(widgetDragInfo.widgetId, "onSwipeDown");
}
window.document.body.style.cursor = widgetDragInfo.oldBodyCursor;
var widget = window.document.getElementById(widgetDragInfo.widgetId);
// It may be null if OnDragDrop filtered out the widget
if(widget != null) widget.style.cursor = widgetDragInfo.oldCursor;
if(widgetDragInfo.targetWidget == tg && !event.changedTouches) {
// suppress the click after the drag on desktop browsers
if(IE_10_AND_BELOW && widgetDragInfo.targetWidget) {
$ax.event.addEvent(widgetDragInfo.targetWidget, 'click', _suppressClickAfterDrag, true, true);
$ax.event.addEvent(widgetDragInfo.targetWidget, "onmousemove", _removeSuppressEvents, true, true);
} else {
$ax.event.addEvent(document, "click", _suppressClickAfterDrag, true);
$ax.event.addEvent(document, "mousemove", _removeSuppressEvents, true);
}
//
//
// if(IE && BROWSER_VERSION < 9 && widgetDragInfo.targetWidget) {
// widgetDragInfo.targetWidget.attachEvent("onclick", _suppressClickAfterDrag);
// widgetDragInfo.targetWidget.attachEvent("onmousemove", _removeSuppressEvents);
// } else {
// window.document.addEventListener("click", _suppressClickAfterDrag, true);
// window.document.addEventListener("mousemove", _removeSuppressEvents, true);
// }
}
}
widgetDragInfo.hasStarted = false;
widgetDragInfo.movedWidgets = new Object();
return false;
};
$ax.drag.GetDragX = function() {
if(widgetDragInfo.hasStarted) return widgetDragInfo.xDelta;
return 0;
};
$ax.drag.GetDragY = function() {
if(widgetDragInfo.hasStarted) return widgetDragInfo.yDelta;
return 0;
};
$ax.drag.GetTotalDragX = function() {
if(widgetDragInfo.hasStarted) return widgetDragInfo.currentX - widgetDragInfo.cursorStartX;
return 0;
};
$ax.drag.GetTotalDragY = function() {
if(widgetDragInfo.hasStarted) return widgetDragInfo.currentY - widgetDragInfo.cursorStartY;
return 0;
};
$ax.drag.GetDragTime = function() {
if(widgetDragInfo.hasStarted) return widgetDragInfo.currentTime - widgetDragInfo.startTime;
return 600000;
};
// $ax.drag.GetCursorRectangles = function() {
// var rects = new Object();
// rects.lastRect = new rect($ax.lastMouseLocation.x, $ax.lastMouseLocation.y, 1, 1);
// rects.currentRect = new rect($ax.mouseLocation.x, $ax.mouseLocation.y, 1, 1);
// return rects;
// };
// $ax.drag.GetWidgetRectangles = function(id) {
// var widget = window.document.getElementById(id);
// var rects = new Object();
// rects.lastRect = new rect($ax.legacy.getAbsoluteLeft(widget), $ax.legacy.getAbsoluteTop(widget), Number($('#' + id).css('width').replace("px", "")), Number($('#' + id).css('height').replace("px", "")));
// rects.currentRect = rects.lastRect;
// return rects;
// };
// $ax.drag.IsEntering = function(movingRects, targetRects) {
// return !movingRects.lastRect.IntersectsWith(targetRects.currentRect) && movingRects.currentRect.IntersectsWith(targetRects.currentRect);
// };
// $ax.drag.IsLeaving = function(movingRects, targetRects) {
// return movingRects.lastRect.IntersectsWith(targetRects.currentRect) && !movingRects.currentRect.IntersectsWith(targetRects.currentRect);
// };
// function IsOver(movingRects, targetRects) {
// return movingRects.currentRect.IntersectsWith(targetRects.currentRect);
// }
// function IsNotOver(movingRects, targetRects) {
// return !IsOver(movingRects, targetRects);
// }
$ax.drag.LogMovedWidgetForDrag = function (id, dragInfo) {
dragInfo = dragInfo || widgetDragInfo;
if(dragInfo.hasStarted) {
var containerIndex = id.indexOf('_container');
if(containerIndex != -1) id = id.substring(0, containerIndex);
// If state or other non-widget id, this should not be dragged, and should exit out to avoid exceptions.
if(!$obj(id)) return;
var query = $ax('#' + id);
var x = query.left();
var y = query.top();
var movedWidgets = dragInfo.movedWidgets;
if(!movedWidgets[id]) {
movedWidgets[id] = new Location(x, y);
}
}
};
var Location = function(x, y) {
this.x = x;
this.y = y;
};
$ax.drag.location = Location;
var Rectangle = $ax.drag.Rectangle = function(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.right = x + width;
this.bottom = y + height;
};
Rectangle.prototype.IntersectsWith = function(rect) {
if(this.Invalid()) return false;
if(rect.length) {
for(var i = 0; i < rect.length; i++) if(!rect[i].Invalid && this.IntersectsWith(rect[i])) return true;
return false;
}
if(rect.Invalid()) return false;
return this.x < rect.right && this.right > rect.x && this.y < rect.bottom && this.bottom > rect.y;
};
Rectangle.prototype.Invalid = function() {
return this.x == -1 && this.y == -1 && this.width == -1 && this.height == -1;
};
Rectangle.prototype.Move = function(x, y) {
return new Rectangle(x, y, this.width, this.height);
};
});