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
|
Sys.UI.FloatingBehavior = function() {
Sys.UI.FloatingBehavior.initializeBase(this);
var _handle;
var _location;
var _dragStartLocation;
var _mouseDownHandler = Function.createDelegate(this, mouseDownHandler);
this.move = this.createEvent();
this.get_handle = function() {
return _handle;
}
this.set_handle = function(value) {
if (_handle != null) {
_handle.detachEvent("onmousedown", _mouseDownHandler);
}
_handle = value;
_handle.attachEvent("onmousedown", _mouseDownHandler);
}
this.get_location = function() {
return _location;
}
this.set_location = function(value) {
if (_location != value) {
_location = value;
if (this.get_isInitialized()) {
var numbers = _location.split(',');
var location = { x : parseInt(numbers[0]), y : parseInt(numbers[1]) };
Sys.UI.Control.setLocation(this.control.element, location);
}
this.raisePropertyChanged('location');
}
}
this.initialize = function() {
Sys.UI.FloatingBehavior.callBaseMethod(this, 'initialize');
Sys.UI.DragDropManager.registerDropTarget(this);
var el = this.control.element;
var location;
if (_location) {
var numbers = _location.split(',');
location = { x : parseInt(numbers[0]), y : parseInt(numbers[1]) };
}
else {
location = Sys.UI.Control.getLocation(el);
}
el.style.width = el.offsetWidth + "px";
el.style.height = el.offsetHeight + "px";
el.style.position = "absolute";
Sys.UI.Control.setLocation(el, location);
}
this.dispose = function() {
Sys.UI.DragDropManager.unregisterDropTarget(this);
if (_handle != null) {
_handle.detachEvent("onmousedown", _mouseDownHandler);
}
_mouseDownHandler = null;
Sys.UI.FloatingBehavior.callBaseMethod(this, 'dispose');
}
this.getDescriptor = function() {
var td = Sys.UI.FloatingBehavior.callBaseMethod(this, 'getDescriptor');
td.addProperty("data", Object, true);
td.addProperty("dataType", String, true);
td.addProperty("dragMode", Sys.UI.DragMode, true);
td.addProperty("dropTargetElement", Object, true);
td.addProperty("handle", Object, false, Sys.Attributes.Element, true);
td.addProperty('location', String);
td.addEvent("move", true);
return td;
}
this.checkCanDrag = function(element) {
var undraggableTagNames = ["input", "button", "select", "textarea", "label"];
var tagName = element.tagName;
if ((tagName.toLowerCase() == "a") && (element.href != null) && (element.href.length > 0)) {
return false;
}
if (undraggableTagNames.indexOf(tagName.toLowerCase()) > -1) {
return false;
}
return true;
}
function mouseDownHandler() {
var el = this.control.element;
if (this.checkCanDrag(window.event.srcElement)) {
_dragStartLocation = Sys.UI.Control.getLocation(el);
window.event.returnValue = false;
this.startDragDrop(el);
}
}
this.startDragDrop = function(dragVisual) {
Sys.UI.DragDropManager.startDragDrop(this, dragVisual, null);
}
// IDragSource implementation
this.get_dataType = function() {
return "_floatingObject";
}
this.get_data = function(context) {
return null;
}
this.get_dragMode = function() {
return Sys.UI.DragMode.Move;
}
this.onDragStart = Function.emptyMethod;
this.onDrag = Function.emptyMethod;
this.onDragEnd = function(canceled) {
if (!canceled) {
var cancelArgs = new Sys.CancelEventArgs();
this.move.invoke(this, cancelArgs);
canceled = cancelArgs.get_canceled();
}
var el = this.control.element;
if (canceled) {
Sys.UI.Control.setLocation(el, _dragStartLocation);
}
else {
var location = Sys.UI.Control.getLocation(el);
_location = location.x + ',' + location.y;
this.raisePropertyChanged('location');
}
}
// IDropTarget implementation
this.get_dropTargetElement = function() {
return document.body;
}
this.canDrop = function(dragMode, dataType, data) {
return (dataType == "_floatingObject");
}
this.drop = Function.emptyMethod;
this.onDragEnterTarget = Function.emptyMethod;
this.onDragLeaveTarget = Function.emptyMethod;
this.onDragInTarget = Function.emptyMethod;
}
Sys.UI.FloatingBehavior.registerSealedClass('Sys.UI.FloatingBehavior', Sys.UI.Behavior, Sys.UI.IDragSource, Sys.UI.IDropTarget, Sys.IDisposable);
Sys.TypeDescriptor.addType('script', 'floatingBehavior', Sys.UI.FloatingBehavior);
|