Diffstat (limited to 'frontend/beta/js/YUI-extensions/dd/DragSource.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/beta/js/YUI-extensions/dd/DragSource.js | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/dd/DragSource.js b/frontend/beta/js/YUI-extensions/dd/DragSource.js new file mode 100644 index 0000000..efee2d6 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/DragSource.js | |||
@@ -0,0 +1,218 @@ | |||
1 | // kill drag drop dependency | ||
2 | if(YAHOO.util.DragDrop){ | ||
3 | |||
4 | YAHOO.ext.dd.DragSource = function(el, config){ | ||
5 | this.el = getEl(el); | ||
6 | this.dragData = {}; | ||
7 | |||
8 | YAHOO.ext.util.Config.apply(this, config); | ||
9 | |||
10 | if(!this.proxy){ | ||
11 | this.proxy = new YAHOO.ext.dd.StatusProxy(); | ||
12 | } | ||
13 | this.el.on('mouseup', this.handleMouseUp); | ||
14 | YAHOO.ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, | ||
15 | {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true}); | ||
16 | |||
17 | this.dragging = false; | ||
18 | }; | ||
19 | |||
20 | YAHOO.extendX(YAHOO.ext.dd.DragSource, YAHOO.util.DDProxy, { | ||
21 | dropAllowed : 'ydd-drop-ok', | ||
22 | dropNotAllowed : 'ydd-drop-nodrop', | ||
23 | |||
24 | getDragData : function(e){ | ||
25 | return this.dragData; | ||
26 | }, | ||
27 | |||
28 | onDragEnter : function(e, id){ | ||
29 | var target = YAHOO.util.DragDropMgr.getDDById(id); | ||
30 | this.cachedTarget = target; | ||
31 | if(this.beforeDragEnter(target, e, id) !== false){ | ||
32 | if(target.isNotifyTarget){ | ||
33 | var status = target.notifyEnter(this, e, this.dragData); | ||
34 | this.proxy.setStatus(status); | ||
35 | }else{ | ||
36 | this.proxy.setStatus(this.dropAllowed); | ||
37 | } | ||
38 | |||
39 | if(this.afterDragEnter){ | ||
40 | this.afterDragEnter(target, e, id); | ||
41 | } | ||
42 | } | ||
43 | }, | ||
44 | |||
45 | beforeDragEnter : function(target, e, id){ | ||
46 | return true; | ||
47 | }, | ||
48 | |||
49 | alignElWithMouse: function() { | ||
50 | YAHOO.ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments); | ||
51 | this.proxy.sync(); | ||
52 | }, | ||
53 | |||
54 | onDragOver : function(e, id){ | ||
55 | var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); | ||
56 | if(this.beforeDragOver(target, e, id) !== false){ | ||
57 | if(target.isNotifyTarget){ | ||
58 | var status = target.notifyOver(this, e, this.dragData); | ||
59 | this.proxy.setStatus(status); | ||
60 | } | ||
61 | |||
62 | if(this.afterDragOver){ | ||
63 | this.afterDragOver(target, e, id); | ||
64 | } | ||
65 | } | ||
66 | }, | ||
67 | |||
68 | beforeDragOver : function(target, e, id){ | ||
69 | return true; | ||
70 | }, | ||
71 | |||
72 | onDragOut : function(e, id){ | ||
73 | var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); | ||
74 | if(this.beforeDragOut(target, e, id) !== false){ | ||
75 | if(target.isNotifyTarget){ | ||
76 | target.notifyOut(this, e, this.dragData); | ||
77 | } | ||
78 | this.proxy.reset(); | ||
79 | if(this.afterDragOut){ | ||
80 | this.afterDragOut(target, e, id); | ||
81 | } | ||
82 | } | ||
83 | this.cachedTarget = null; | ||
84 | }, | ||
85 | |||
86 | beforeDragOut : function(target, e, id){ | ||
87 | return true; | ||
88 | }, | ||
89 | |||
90 | |||
91 | onDragDrop : function(e, id){ | ||
92 | var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); | ||
93 | if(this.beforeDragDrop(target, e, id) !== false){ | ||
94 | if(target.isNotifyTarget){ | ||
95 | if(target.notifyDrop(this, e, this.dragData)){ // valid drop? | ||
96 | this.onValidDrop(target, e, id); | ||
97 | }else{ | ||
98 | this.onInvalidDrop(target, e, id); | ||
99 | } | ||
100 | }else{ | ||
101 | this.onValidDrop(target, e, id); | ||
102 | } | ||
103 | |||
104 | if(this.afterDragDrop){ | ||
105 | this.afterDragDrop(target, e, id); | ||
106 | } | ||
107 | } | ||
108 | }, | ||
109 | |||
110 | beforeDragDrop : function(target, e, id){ | ||
111 | return true; | ||
112 | }, | ||
113 | |||
114 | onValidDrop : function(target, e, id){ | ||
115 | this.hideProxy(); | ||
116 | }, | ||
117 | |||
118 | getRepairXY : function(e, data){ | ||
119 | return this.el.getXY(); | ||
120 | }, | ||
121 | |||
122 | onInvalidDrop : function(target, e, id){ | ||
123 | this.beforeInvalidDrop(target, e, id); | ||
124 | if(this.cachedTarget){ | ||
125 | if(this.cachedTarget.isNotifyTarget){ | ||
126 | this.cachedTarget.notifyOut(this, e, this.dragData); | ||
127 | } | ||
128 | this.cacheTarget = null; | ||
129 | } | ||
130 | this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this); | ||
131 | if(this.afterInvalidDrop){ | ||
132 | this.afterInvalidDrop(e, id); | ||
133 | } | ||
134 | }, | ||
135 | |||
136 | afterRepair : function(){ | ||
137 | this.el.highlight(this.hlColor || 'c3daf9'); | ||
138 | this.dragging = false; | ||
139 | }, | ||
140 | |||
141 | beforeInvalidDrop : function(target, e, id){ | ||
142 | return true; | ||
143 | }, | ||
144 | |||
145 | handleMouseDown : function(e){ | ||
146 | if(this.dragging) { | ||
147 | return; | ||
148 | } | ||
149 | if(YAHOO.ext.QuickTips){ | ||
150 | YAHOO.ext.QuickTips.disable(); | ||
151 | } | ||
152 | var data = this.getDragData(e); | ||
153 | if(data && this.onBeforeDrag(data, e) !== false){ | ||
154 | this.dragData = data; | ||
155 | this.proxy.stop(); | ||
156 | YAHOO.ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments); | ||
157 | } | ||
158 | }, | ||
159 | |||
160 | handleMouseUp : function(e){ | ||
161 | if(YAHOO.ext.QuickTips){ | ||
162 | YAHOO.ext.QuickTips.enable(); | ||
163 | } | ||
164 | }, | ||
165 | |||
166 | onBeforeDrag : function(data, e){ | ||
167 | return true; | ||
168 | }, | ||
169 | |||
170 | startDrag : function(e){ | ||
171 | this.proxy.reset(); | ||
172 | this.dragging = true; | ||
173 | this.proxy.update(''); | ||
174 | this.onInitDrag(e); | ||
175 | this.proxy.show(); | ||
176 | }, | ||
177 | |||
178 | onInitDrag : function(e){ | ||
179 | var clone = this.el.dom.cloneNode(true); | ||
180 | clone.id = YAHOO.util.Dom.generateId(); // prevent duplicate ids | ||
181 | this.proxy.update(clone); | ||
182 | return true; | ||
183 | }, | ||
184 | |||
185 | |||
186 | getProxy : function(){ | ||
187 | return this.proxy; | ||
188 | }, | ||
189 | |||
190 | hideProxy : function(){ | ||
191 | this.proxy.hide(); | ||
192 | this.proxy.reset(true); | ||
193 | this.dragging = false; | ||
194 | }, | ||
195 | |||
196 | triggerCacheRefresh : function(){ | ||
197 | YAHOO.util.DDM.refreshCache(this.groups); | ||
198 | }, | ||
199 | |||
200 | // override to prevent hiding | ||
201 | b4EndDrag: function(e) { | ||
202 | }, | ||
203 | |||
204 | // override to prevent moving | ||
205 | endDrag : function(e){ | ||
206 | this.onEndDrag(this.dragData, e); | ||
207 | }, | ||
208 | |||
209 | onEndDrag : function(data, e){ | ||
210 | |||
211 | }, | ||
212 | |||
213 | // pin to cursor | ||
214 | autoOffset : function(x, y) { | ||
215 | this.setDelta(-12, -20); | ||
216 | } | ||
217 | }); | ||
218 | } | ||