Diffstat (limited to 'frontend/gamma/js/MochiKit/DragAndDrop.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/DragAndDrop.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/frontend/gamma/js/MochiKit/DragAndDrop.js b/frontend/gamma/js/MochiKit/DragAndDrop.js index 62777c5..cf84f77 100644 --- a/frontend/gamma/js/MochiKit/DragAndDrop.js +++ b/frontend/gamma/js/MochiKit/DragAndDrop.js | |||
@@ -1,107 +1,107 @@ | |||
1 | /*** | 1 | /*** |
2 | MochiKit.DragAndDrop 1.5 | 2 | MochiKit.DragAndDrop 1.5 |
3 | 3 | ||
4 | See <http://mochikit.com/> for documentation, downloads, license, etc. | 4 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
5 | 5 | ||
6 | Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) | 6 | Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) |
7 | Mochi-ized By Thomas Herve (_firstname_@nimail.org) | 7 | Mochi-ized By Thomas Herve (_firstname_@nimail.org) |
8 | 8 | ||
9 | ***/ | 9 | ***/ |
10 | 10 | ||
11 | MochiKit.Base._module('DragAndDrop', '1.5', ['Base', 'Iter', 'DOM', 'Signal', 'Visual', 'Position']); | 11 | MochiKit.Base.module(MochiKit, 'DragAndDrop', '1.5', ['Base', 'Iter', 'DOM', 'Signal', 'Visual', 'Position']); |
12 | 12 | ||
13 | MochiKit.DragAndDrop.Droppables = { | 13 | MochiKit.DragAndDrop.Droppables = { |
14 | /*** | 14 | /*** |
15 | 15 | ||
16 | Manage all droppables. Shouldn't be used, use the Droppable object instead. | 16 | Manage all droppables. Shouldn't be used, use the Droppable object instead. |
17 | 17 | ||
18 | ***/ | 18 | ***/ |
19 | drops: [], | 19 | drops: [], |
20 | 20 | ||
21 | remove: function (element) { | 21 | remove: function (element) { |
22 | this.drops = MochiKit.Base.filter(function (d) { | 22 | this.drops = MochiKit.Base.filter(function (d) { |
23 | return d.element != MochiKit.DOM.getElement(element); | 23 | return d.element != MochiKit.DOM.getElement(element); |
24 | }, this.drops); | 24 | }, this.drops); |
25 | }, | 25 | }, |
26 | 26 | ||
27 | register: function (drop) { | 27 | register: function (drop) { |
28 | this.drops.push(drop); | 28 | this.drops.push(drop); |
29 | }, | 29 | }, |
30 | 30 | ||
31 | unregister: function (drop) { | 31 | unregister: function (drop) { |
32 | this.drops = MochiKit.Base.filter(function (d) { | 32 | this.drops = MochiKit.Base.filter(function (d) { |
33 | return d != drop; | 33 | return d != drop; |
34 | }, this.drops); | 34 | }, this.drops); |
35 | }, | 35 | }, |
36 | 36 | ||
37 | prepare: function (element) { | 37 | prepare: function (element) { |
38 | MochiKit.Base.map(function (drop) { | 38 | MochiKit.Base.map(function (drop) { |
39 | if (drop.isAccepted(element)) { | 39 | if (drop.isAccepted(element)) { |
40 | if (drop.options.activeclass) { | 40 | if (drop.options.activeclass) { |
41 | MochiKit.DOM.addElementClass(drop.element, | 41 | MochiKit.DOM.addElementClass(drop.element, |
42 | drop.options.activeclass); | 42 | drop.options.activeclass); |
43 | } | 43 | } |
44 | drop.options.onactive(drop.element, element); | 44 | drop.options.onactive(drop.element, element); |
45 | } | 45 | } |
46 | }, this.drops); | 46 | }, this.drops); |
47 | }, | 47 | }, |
48 | 48 | ||
49 | findDeepestChild: function (drops) { | 49 | findDeepestChild: function (drops) { |
50 | var deepest = drops[0]; | 50 | var deepest = drops[0]; |
51 | 51 | ||
52 | for (var i = 1; i < drops.length; ++i) { | 52 | for (var i = 1; i < drops.length; ++i) { |
53 | if (MochiKit.DOM.isChildNode(drops[i].element, deepest.element)) { | 53 | if (MochiKit.DOM.isChildNode(drops[i].element, deepest.element)) { |
54 | deepest = drops[i]; | 54 | deepest = drops[i]; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | return deepest; | 57 | return deepest; |
58 | }, | 58 | }, |
59 | 59 | ||
60 | show: function (point, element) { | 60 | show: function (point, element) { |
61 | if (!this.drops.length) { | 61 | if (!this.drops.length) { |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | var affected = []; | 64 | var affected = []; |
65 | 65 | ||
66 | if (this.last_active) { | 66 | if (this.last_active) { |
67 | this.last_active.deactivate(); | 67 | this.last_active.deactivate(); |
68 | } | 68 | } |
69 | MochiKit.Iter.forEach(this.drops, function (drop) { | 69 | MochiKit.Iter.forEach(this.drops, function (drop) { |
70 | if (drop.isAffected(point, element)) { | 70 | if (drop.isAffected(point, element)) { |
71 | affected.push(drop); | 71 | affected.push(drop); |
72 | } | 72 | } |
73 | }); | 73 | }); |
74 | if (affected.length > 0) { | 74 | if (affected.length > 0) { |
75 | var drop = this.findDeepestChild(affected); | 75 | var drop = this.findDeepestChild(affected); |
76 | MochiKit.Position.within(drop.element, point.page.x, point.page.y); | 76 | MochiKit.Position.within(drop.element, point.page.x, point.page.y); |
77 | drop.options.onhover(element, drop.element, | 77 | drop.options.onhover(element, drop.element, |
78 | MochiKit.Position.overlap(drop.options.overlap, drop.element)); | 78 | MochiKit.Position.overlap(drop.options.overlap, drop.element)); |
79 | drop.activate(); | 79 | drop.activate(); |
80 | } | 80 | } |
81 | }, | 81 | }, |
82 | 82 | ||
83 | fire: function (event, element) { | 83 | fire: function (event, element) { |
84 | if (!this.last_active) { | 84 | if (!this.last_active) { |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | MochiKit.Position.prepare(); | 87 | MochiKit.Position.prepare(); |
88 | 88 | ||
89 | if (this.last_active.isAffected(event.mouse(), element)) { | 89 | if (this.last_active.isAffected(event.mouse(), element)) { |
90 | this.last_active.options.ondrop(element, | 90 | this.last_active.options.ondrop(element, |
91 | this.last_active.element, event); | 91 | this.last_active.element, event); |
92 | } | 92 | } |
93 | }, | 93 | }, |
94 | 94 | ||
95 | reset: function (element) { | 95 | reset: function (element) { |
96 | MochiKit.Base.map(function (drop) { | 96 | MochiKit.Base.map(function (drop) { |
97 | if (drop.options.activeclass) { | 97 | if (drop.options.activeclass) { |
98 | MochiKit.DOM.removeElementClass(drop.element, | 98 | MochiKit.DOM.removeElementClass(drop.element, |
99 | drop.options.activeclass); | 99 | drop.options.activeclass); |
100 | } | 100 | } |
101 | drop.options.ondesactive(drop.element, element); | 101 | drop.options.ondesactive(drop.element, element); |
102 | }, this.drops); | 102 | }, this.drops); |
103 | if (this.last_active) { | 103 | if (this.last_active) { |
104 | this.last_active.deactivate(); | 104 | this.last_active.deactivate(); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | }; | 107 | }; |
@@ -213,369 +213,369 @@ MochiKit.DragAndDrop.Droppable.prototype = { | |||
213 | 213 | ||
214 | /** @id MochiKit.DragAndDrop.deactivate */ | 214 | /** @id MochiKit.DragAndDrop.deactivate */ |
215 | deactivate: function () { | 215 | deactivate: function () { |
216 | /*** | 216 | /*** |
217 | 217 | ||
218 | A droppable is deactivate when a draggable has been over it and left. | 218 | A droppable is deactivate when a draggable has been over it and left. |
219 | 219 | ||
220 | ***/ | 220 | ***/ |
221 | if (this.options.hoverclass) { | 221 | if (this.options.hoverclass) { |
222 | MochiKit.DOM.removeElementClass(this.element, | 222 | MochiKit.DOM.removeElementClass(this.element, |
223 | this.options.hoverclass); | 223 | this.options.hoverclass); |
224 | } | 224 | } |
225 | this.options.hoverfunc(this.element, false); | 225 | this.options.hoverfunc(this.element, false); |
226 | MochiKit.DragAndDrop.Droppables.last_active = null; | 226 | MochiKit.DragAndDrop.Droppables.last_active = null; |
227 | }, | 227 | }, |
228 | 228 | ||
229 | /** @id MochiKit.DragAndDrop.activate */ | 229 | /** @id MochiKit.DragAndDrop.activate */ |
230 | activate: function () { | 230 | activate: function () { |
231 | /*** | 231 | /*** |
232 | 232 | ||
233 | A droppable is active when a draggable is over it. | 233 | A droppable is active when a draggable is over it. |
234 | 234 | ||
235 | ***/ | 235 | ***/ |
236 | if (this.options.hoverclass) { | 236 | if (this.options.hoverclass) { |
237 | MochiKit.DOM.addElementClass(this.element, this.options.hoverclass); | 237 | MochiKit.DOM.addElementClass(this.element, this.options.hoverclass); |
238 | } | 238 | } |
239 | this.options.hoverfunc(this.element, true); | 239 | this.options.hoverfunc(this.element, true); |
240 | MochiKit.DragAndDrop.Droppables.last_active = this; | 240 | MochiKit.DragAndDrop.Droppables.last_active = this; |
241 | }, | 241 | }, |
242 | 242 | ||
243 | /** @id MochiKit.DragAndDrop.destroy */ | 243 | /** @id MochiKit.DragAndDrop.destroy */ |
244 | destroy: function () { | 244 | destroy: function () { |
245 | /*** | 245 | /*** |
246 | 246 | ||
247 | Delete this droppable. | 247 | Delete this droppable. |
248 | 248 | ||
249 | ***/ | 249 | ***/ |
250 | MochiKit.DragAndDrop.Droppables.unregister(this); | 250 | MochiKit.DragAndDrop.Droppables.unregister(this); |
251 | }, | 251 | }, |
252 | 252 | ||
253 | /** @id MochiKit.DragAndDrop.repr */ | 253 | /** @id MochiKit.DragAndDrop.repr */ |
254 | repr: function () { | 254 | repr: function () { |
255 | return '[' + this.__class__.NAME + ", options:" + MochiKit.Base.repr(this.options) + "]"; | 255 | return '[' + this.__class__.NAME + ", options:" + MochiKit.Base.repr(this.options) + "]"; |
256 | } | 256 | } |
257 | }; | 257 | }; |
258 | 258 | ||
259 | MochiKit.DragAndDrop.Draggables = { | 259 | MochiKit.DragAndDrop.Draggables = { |
260 | /*** | 260 | /*** |
261 | 261 | ||
262 | Manage draggables elements. Not intended to direct use. | 262 | Manage draggables elements. Not intended to direct use. |
263 | 263 | ||
264 | ***/ | 264 | ***/ |
265 | drags: [], | 265 | drags: [], |
266 | 266 | ||
267 | register: function (draggable) { | 267 | register: function (draggable) { |
268 | if (this.drags.length === 0) { | 268 | if (this.drags.length === 0) { |
269 | var conn = MochiKit.Signal.connect; | 269 | var conn = MochiKit.Signal.connect; |
270 | this.eventMouseUp = conn(document, 'onmouseup', this, this.endDrag); | 270 | this.eventMouseUp = conn(document, 'onmouseup', this, this.endDrag); |
271 | this.eventMouseMove = conn(document, 'onmousemove', this, | 271 | this.eventMouseMove = conn(document, 'onmousemove', this, |
272 | this.updateDrag); | 272 | this.updateDrag); |
273 | this.eventKeypress = conn(document, 'onkeypress', this, | 273 | this.eventKeypress = conn(document, 'onkeypress', this, |
274 | this.keyPress); | 274 | this.keyPress); |
275 | } | 275 | } |
276 | this.drags.push(draggable); | 276 | this.drags.push(draggable); |
277 | }, | 277 | }, |
278 | 278 | ||
279 | unregister: function (draggable) { | 279 | unregister: function (draggable) { |
280 | this.drags = MochiKit.Base.filter(function (d) { | 280 | this.drags = MochiKit.Base.filter(function (d) { |
281 | return d != draggable; | 281 | return d != draggable; |
282 | }, this.drags); | 282 | }, this.drags); |
283 | if (this.drags.length === 0) { | 283 | if (this.drags.length === 0) { |
284 | var disc = MochiKit.Signal.disconnect; | 284 | var disc = MochiKit.Signal.disconnect; |
285 | disc(this.eventMouseUp); | 285 | disc(this.eventMouseUp); |
286 | disc(this.eventMouseMove); | 286 | disc(this.eventMouseMove); |
287 | disc(this.eventKeypress); | 287 | disc(this.eventKeypress); |
288 | } | 288 | } |
289 | }, | 289 | }, |
290 | 290 | ||
291 | activate: function (draggable) { | 291 | activate: function (draggable) { |
292 | // allows keypress events if window is not currently focused | 292 | // allows keypress events if window is not currently focused |
293 | // fails for Safari | 293 | // fails for Safari |
294 | window.focus(); | 294 | window.focus(); |
295 | this.activeDraggable = draggable; | 295 | this.activeDraggable = draggable; |
296 | }, | 296 | }, |
297 | 297 | ||
298 | deactivate: function () { | 298 | deactivate: function () { |
299 | this.activeDraggable = null; | 299 | this.activeDraggable = null; |
300 | }, | 300 | }, |
301 | 301 | ||
302 | updateDrag: function (event) { | 302 | updateDrag: function (event) { |
303 | if (!this.activeDraggable) { | 303 | if (!this.activeDraggable) { |
304 | return; | 304 | return; |
305 | } | 305 | } |
306 | var pointer = event.mouse(); | 306 | var pointer = event.mouse(); |
307 | // Mozilla-based browsers fire successive mousemove events with | 307 | // Mozilla-based browsers fire successive mousemove events with |
308 | // the same coordinates, prevent needless redrawing (moz bug?) | 308 | // the same coordinates, prevent needless redrawing (moz bug?) |
309 | if (this._lastPointer && (MochiKit.Base.repr(this._lastPointer.page) == | 309 | if (this._lastPointer && |
310 | MochiKit.Base.repr(pointer.page))) { | 310 | this._lastPointer.page.x == pointer.page.x && |
311 | this._lastPointer.page.y == pointer.page.y) { | ||
311 | return; | 312 | return; |
312 | } | 313 | } |
313 | this._lastPointer = pointer; | 314 | this._lastPointer = pointer; |
314 | this.activeDraggable.updateDrag(event, pointer); | 315 | this.activeDraggable.updateDrag(event, pointer); |
315 | }, | 316 | }, |
316 | 317 | ||
317 | endDrag: function (event) { | 318 | endDrag: function (event) { |
318 | if (!this.activeDraggable) { | 319 | if (!this.activeDraggable) { |
319 | return; | 320 | return; |
320 | } | 321 | } |
321 | this._lastPointer = null; | 322 | this._lastPointer = null; |
322 | this.activeDraggable.endDrag(event); | 323 | this.activeDraggable.endDrag(event); |
323 | this.activeDraggable = null; | 324 | this.activeDraggable = null; |
324 | }, | 325 | }, |
325 | 326 | ||
326 | keyPress: function (event) { | 327 | keyPress: function (event) { |
327 | if (this.activeDraggable) { | 328 | if (this.activeDraggable) { |
328 | this.activeDraggable.keyPress(event); | 329 | this.activeDraggable.keyPress(event); |
329 | } | 330 | } |
330 | }, | 331 | }, |
331 | 332 | ||
332 | notify: function (eventName, draggable, event) { | 333 | notify: function (eventName, draggable, event) { |
333 | MochiKit.Signal.signal(this, eventName, draggable, event); | 334 | MochiKit.Signal.signal(this, eventName, draggable, event); |
334 | } | 335 | } |
335 | }; | 336 | }; |
336 | 337 | ||
337 | /** @id MochiKit.DragAndDrop.Draggable */ | 338 | /** @id MochiKit.DragAndDrop.Draggable */ |
338 | MochiKit.DragAndDrop.Draggable = function (element, options) { | 339 | MochiKit.DragAndDrop.Draggable = function (element, options) { |
339 | var cls = arguments.callee; | 340 | var cls = arguments.callee; |
340 | if (!(this instanceof cls)) { | 341 | if (!(this instanceof cls)) { |
341 | return new cls(element, options); | 342 | return new cls(element, options); |
342 | } | 343 | } |
343 | this.__init__(element, options); | 344 | this.__init__(element, options); |
344 | }; | 345 | }; |
345 | 346 | ||
346 | MochiKit.DragAndDrop.Draggable.prototype = { | 347 | MochiKit.DragAndDrop.Draggable.prototype = { |
347 | /*** | 348 | /*** |
348 | 349 | ||
349 | A draggable object. Simple instantiate : | 350 | A draggable object. Simple instantiate : |
350 | 351 | ||
351 | new MochiKit.DragAndDrop.Draggable('myelement'); | 352 | new MochiKit.DragAndDrop.Draggable('myelement'); |
352 | 353 | ||
353 | ***/ | 354 | ***/ |
354 | __class__ : MochiKit.DragAndDrop.Draggable, | 355 | __class__ : MochiKit.DragAndDrop.Draggable, |
355 | 356 | ||
356 | __init__: function (element, /* optional */options) { | 357 | __init__: function (element, /* optional */options) { |
357 | var v = MochiKit.Visual; | 358 | var v = MochiKit.Visual; |
358 | var b = MochiKit.Base; | 359 | var b = MochiKit.Base; |
359 | options = b.update({ | 360 | options = b.update({ |
360 | 361 | ||
361 | /** @id MochiKit.DragAndDrop.handle */ | 362 | /** @id MochiKit.DragAndDrop.handle */ |
362 | handle: false, | 363 | handle: false, |
363 | 364 | ||
364 | /** @id MochiKit.DragAndDrop.starteffect */ | 365 | /** @id MochiKit.DragAndDrop.starteffect */ |
365 | starteffect: function (innerelement) { | 366 | starteffect: function (innerelement) { |
366 | this._savedOpacity = MochiKit.Style.getStyle(innerelement, 'opacity') || 1.0; | 367 | this._savedOpacity = MochiKit.Style.getStyle(innerelement, 'opacity') || 1.0; |
367 | new v.Opacity(innerelement, {duration:0.2, from:this._savedOpacity, to:0.7}); | 368 | new v.Opacity(innerelement, {duration:0.2, from:this._savedOpacity, to:0.7}); |
368 | }, | 369 | }, |
369 | /** @id MochiKit.DragAndDrop.reverteffect */ | 370 | /** @id MochiKit.DragAndDrop.reverteffect */ |
370 | reverteffect: function (innerelement, top_offset, left_offset) { | 371 | reverteffect: function (innerelement, top_offset, left_offset) { |
371 | var dur = Math.sqrt(Math.abs(top_offset^2) + | 372 | var dur = Math.sqrt(Math.abs(top_offset^2) + |
372 | Math.abs(left_offset^2))*0.02; | 373 | Math.abs(left_offset^2))*0.02; |
373 | return new v.Move(innerelement, | 374 | return new v.Move(innerelement, |
374 | {x: -left_offset, y: -top_offset, duration: dur}); | 375 | {x: -left_offset, y: -top_offset, duration: dur}); |
375 | }, | 376 | }, |
376 | 377 | ||
377 | /** @id MochiKit.DragAndDrop.endeffect */ | 378 | /** @id MochiKit.DragAndDrop.endeffect */ |
378 | endeffect: function (innerelement) { | 379 | endeffect: function (innerelement) { |
379 | new v.Opacity(innerelement, {duration:0.2, from:0.7, to:this._savedOpacity}); | 380 | new v.Opacity(innerelement, {duration:0.2, from:0.7, to:this._savedOpacity}); |
380 | }, | 381 | }, |
381 | 382 | ||
382 | /** @id MochiKit.DragAndDrop.onchange */ | 383 | /** @id MochiKit.DragAndDrop.onchange */ |
383 | onchange: b.noop, | 384 | onchange: b.noop, |
384 | 385 | ||
385 | /** @id MochiKit.DragAndDrop.zindex */ | 386 | /** @id MochiKit.DragAndDrop.zindex */ |
386 | zindex: 1000, | 387 | zindex: 1000, |
387 | 388 | ||
388 | /** @id MochiKit.DragAndDrop.revert */ | 389 | /** @id MochiKit.DragAndDrop.revert */ |
389 | revert: false, | 390 | revert: false, |
390 | 391 | ||
391 | /** @id MochiKit.DragAndDrop.scroll */ | 392 | /** @id MochiKit.DragAndDrop.scroll */ |
392 | scroll: false, | 393 | scroll: false, |
393 | 394 | ||
394 | /** @id MochiKit.DragAndDrop.scrollSensitivity */ | 395 | /** @id MochiKit.DragAndDrop.scrollSensitivity */ |
395 | scrollSensitivity: 20, | 396 | scrollSensitivity: 20, |
396 | 397 | ||
397 | /** @id MochiKit.DragAndDrop.scrollSpeed */ | 398 | /** @id MochiKit.DragAndDrop.scrollSpeed */ |
398 | scrollSpeed: 15, | 399 | scrollSpeed: 15, |
399 | // false, or xy or [x, y] or function (x, y){return [x, y];} | 400 | // false, or xy or [x, y] or function (x, y){return [x, y];} |
400 | 401 | ||
401 | /** @id MochiKit.DragAndDrop.snap */ | 402 | /** @id MochiKit.DragAndDrop.snap */ |
402 | snap: false | 403 | snap: false |
403 | }, options); | 404 | }, options); |
404 | 405 | ||
405 | var d = MochiKit.DOM; | 406 | var d = MochiKit.DOM; |
406 | this.element = d.getElement(element); | 407 | this.element = d.getElement(element); |
407 | 408 | ||
408 | if (options.handle && (typeof(options.handle) == 'string')) { | 409 | if (options.handle && (typeof(options.handle) == 'string')) { |
409 | this.handle = d.getFirstElementByTagAndClassName(null, | 410 | this.handle = d.getFirstElementByTagAndClassName(null, |
410 | options.handle, this.element); | 411 | options.handle, this.element); |
411 | } | 412 | } |
412 | if (!this.handle) { | 413 | if (!this.handle) { |
413 | this.handle = d.getElement(options.handle); | 414 | this.handle = d.getElement(options.handle); |
414 | } | 415 | } |
415 | if (!this.handle) { | 416 | if (!this.handle) { |
416 | this.handle = this.element; | 417 | this.handle = this.element; |
417 | } | 418 | } |
418 | 419 | ||
419 | if (options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { | 420 | if (options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { |
420 | options.scroll = d.getElement(options.scroll); | 421 | options.scroll = d.getElement(options.scroll); |
421 | this._isScrollChild = MochiKit.DOM.isChildNode(this.element, options.scroll); | 422 | this._isScrollChild = MochiKit.DOM.isChildNode(this.element, options.scroll); |
422 | } | 423 | } |
423 | 424 | ||
424 | MochiKit.Style.makePositioned(this.element); // fix IE | 425 | MochiKit.Style.makePositioned(this.element); // fix IE |
425 | 426 | ||
426 | this.delta = this.currentDelta(); | 427 | this.delta = this.currentDelta(); |
427 | this.options = options; | 428 | this.options = options; |
428 | this.dragging = false; | 429 | this.dragging = false; |
429 | 430 | ||
430 | this.eventMouseDown = MochiKit.Signal.connect(this.handle, | 431 | this.eventMouseDown = MochiKit.Signal.connect(this.handle, |
431 | 'onmousedown', this, this.initDrag); | 432 | 'onmousedown', this, this.initDrag); |
432 | MochiKit.DragAndDrop.Draggables.register(this); | 433 | MochiKit.DragAndDrop.Draggables.register(this); |
433 | }, | 434 | }, |
434 | 435 | ||
435 | /** @id MochiKit.DragAndDrop.destroy */ | 436 | /** @id MochiKit.DragAndDrop.destroy */ |
436 | destroy: function () { | 437 | destroy: function () { |
437 | MochiKit.Signal.disconnect(this.eventMouseDown); | 438 | MochiKit.Signal.disconnect(this.eventMouseDown); |
438 | MochiKit.DragAndDrop.Draggables.unregister(this); | 439 | MochiKit.DragAndDrop.Draggables.unregister(this); |
439 | }, | 440 | }, |
440 | 441 | ||
441 | /** @id MochiKit.DragAndDrop.currentDelta */ | 442 | /** @id MochiKit.DragAndDrop.currentDelta */ |
442 | currentDelta: function () { | 443 | currentDelta: function () { |
443 | var s = MochiKit.Style.getStyle; | 444 | var s = MochiKit.Style.getStyle; |
444 | return [ | 445 | return [ |
445 | parseInt(s(this.element, 'left') || '0'), | 446 | parseInt(s(this.element, 'left') || '0', 10), |
446 | parseInt(s(this.element, 'top') || '0')]; | 447 | parseInt(s(this.element, 'top') || '0', 10)]; |
447 | }, | 448 | }, |
448 | 449 | ||
449 | /** @id MochiKit.DragAndDrop.initDrag */ | 450 | /** @id MochiKit.DragAndDrop.initDrag */ |
450 | initDrag: function (event) { | 451 | initDrag: function (event) { |
451 | if (!event.mouse().button.left) { | 452 | if (!event.mouse().button.left) { |
452 | return; | 453 | return; |
453 | } | 454 | } |
454 | // abort on form elements, fixes a Firefox issue | 455 | // abort on form elements, fixes a Firefox issue |
455 | var src = event.target(); | 456 | var src = event.target(); |
456 | var tagName = (src.tagName || '').toUpperCase(); | 457 | var tagName = (src.tagName || '').toUpperCase(); |
457 | if (tagName === 'INPUT' || tagName === 'SELECT' || | 458 | if (tagName === 'INPUT' || tagName === 'SELECT' || |
458 | tagName === 'OPTION' || tagName === 'BUTTON' || | 459 | tagName === 'OPTION' || tagName === 'BUTTON' || |
459 | tagName === 'TEXTAREA') { | 460 | tagName === 'TEXTAREA') { |
460 | return; | 461 | return; |
461 | } | 462 | } |
462 | 463 | ||
463 | if (this._revert) { | 464 | if (this._revert) { |
464 | this._revert.cancel(); | 465 | this._revert.cancel(); |
465 | this._revert = null; | 466 | this._revert = null; |
466 | } | 467 | } |
467 | 468 | ||
468 | var pointer = event.mouse(); | 469 | var pointer = event.mouse(); |
469 | var pos = MochiKit.Position.cumulativeOffset(this.element); | 470 | var pos = MochiKit.Position.cumulativeOffset(this.element); |
470 | this.offset = [pointer.page.x - pos.x, pointer.page.y - pos.y]; | 471 | this.offset = [pointer.page.x - pos.x, pointer.page.y - pos.y]; |
471 | 472 | ||
472 | MochiKit.DragAndDrop.Draggables.activate(this); | 473 | MochiKit.DragAndDrop.Draggables.activate(this); |
473 | event.stop(); | 474 | event.stop(); |
474 | }, | 475 | }, |
475 | 476 | ||
476 | /** @id MochiKit.DragAndDrop.startDrag */ | 477 | /** @id MochiKit.DragAndDrop.startDrag */ |
477 | startDrag: function (event) { | 478 | startDrag: function (event) { |
478 | this.dragging = true; | 479 | this.dragging = true; |
479 | if (this.options.selectclass) { | 480 | if (this.options.selectclass) { |
480 | MochiKit.DOM.addElementClass(this.element, | 481 | MochiKit.DOM.addElementClass(this.element, |
481 | this.options.selectclass); | 482 | this.options.selectclass); |
482 | } | 483 | } |
483 | if (this.options.zindex) { | 484 | if (this.options.zindex) { |
484 | this.originalZ = parseInt(MochiKit.Style.getStyle(this.element, | 485 | this.originalZ = MochiKit.Style.getStyle(this.element, 'z-index'); |
485 | 'z-index') || '0'); | ||
486 | this.element.style.zIndex = this.options.zindex; | 486 | this.element.style.zIndex = this.options.zindex; |
487 | } | 487 | } |
488 | 488 | ||
489 | if (this.options.ghosting) { | 489 | if (this.options.ghosting) { |
490 | this._clone = this.element.cloneNode(true); | 490 | this._clone = this.element.cloneNode(true); |
491 | this.ghostPosition = MochiKit.Position.absolutize(this.element); | 491 | this.ghostPosition = MochiKit.Position.absolutize(this.element); |
492 | this.element.parentNode.insertBefore(this._clone, this.element); | 492 | this.element.parentNode.insertBefore(this._clone, this.element); |
493 | } | 493 | } |
494 | 494 | ||
495 | if (this.options.scroll) { | 495 | if (this.options.scroll) { |
496 | if (this.options.scroll == window) { | 496 | if (this.options.scroll == window) { |
497 | var where = this._getWindowScroll(this.options.scroll); | 497 | var where = this._getWindowScroll(this.options.scroll); |
498 | this.originalScrollLeft = where.left; | 498 | this.originalScrollLeft = where.left; |
499 | this.originalScrollTop = where.top; | 499 | this.originalScrollTop = where.top; |
500 | } else { | 500 | } else { |
501 | this.originalScrollLeft = this.options.scroll.scrollLeft; | 501 | this.originalScrollLeft = this.options.scroll.scrollLeft; |
502 | this.originalScrollTop = this.options.scroll.scrollTop; | 502 | this.originalScrollTop = this.options.scroll.scrollTop; |
503 | } | 503 | } |
504 | } | 504 | } |
505 | 505 | ||
506 | MochiKit.DragAndDrop.Droppables.prepare(this.element); | 506 | MochiKit.DragAndDrop.Droppables.prepare(this.element); |
507 | MochiKit.DragAndDrop.Draggables.notify('start', this, event); | 507 | MochiKit.DragAndDrop.Draggables.notify('start', this, event); |
508 | if (this.options.starteffect) { | 508 | if (this.options.starteffect) { |
509 | this.options.starteffect(this.element); | 509 | this.options.starteffect(this.element); |
510 | } | 510 | } |
511 | }, | 511 | }, |
512 | 512 | ||
513 | /** @id MochiKit.DragAndDrop.updateDrag */ | 513 | /** @id MochiKit.DragAndDrop.updateDrag */ |
514 | updateDrag: function (event, pointer) { | 514 | updateDrag: function (event, pointer) { |
515 | if (!this.dragging) { | 515 | if (!this.dragging) { |
516 | this.startDrag(event); | 516 | this.startDrag(event); |
517 | } | 517 | } |
518 | MochiKit.Position.prepare(); | 518 | MochiKit.Position.prepare(); |
519 | MochiKit.DragAndDrop.Droppables.show(pointer, this.element); | 519 | MochiKit.DragAndDrop.Droppables.show(pointer, this.element); |
520 | MochiKit.DragAndDrop.Draggables.notify('drag', this, event); | 520 | MochiKit.DragAndDrop.Draggables.notify('drag', this, event); |
521 | this.draw(pointer); | 521 | this.draw(pointer); |
522 | this.options.onchange(this); | 522 | this.options.onchange(this); |
523 | 523 | ||
524 | if (this.options.scroll) { | 524 | if (this.options.scroll) { |
525 | this.stopScrolling(); | 525 | this.stopScrolling(); |
526 | var p, q; | 526 | var p, q; |
527 | if (this.options.scroll == window) { | 527 | if (this.options.scroll == window) { |
528 | var s = this._getWindowScroll(this.options.scroll); | 528 | var s = this._getWindowScroll(this.options.scroll); |
529 | p = new MochiKit.Style.Coordinates(s.left, s.top); | 529 | p = new MochiKit.Style.Coordinates(s.left, s.top); |
530 | q = new MochiKit.Style.Coordinates(s.left + s.width, | 530 | q = new MochiKit.Style.Coordinates(s.left + s.width, |
531 | s.top + s.height); | 531 | s.top + s.height); |
532 | } else { | 532 | } else { |
533 | p = MochiKit.Position.page(this.options.scroll); | 533 | p = MochiKit.Position.page(this.options.scroll); |
534 | p.x += this.options.scroll.scrollLeft; | 534 | p.x += this.options.scroll.scrollLeft; |
535 | p.y += this.options.scroll.scrollTop; | 535 | p.y += this.options.scroll.scrollTop; |
536 | p.x += (window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0); | 536 | p.x += (window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0); |
537 | p.y += (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0); | 537 | p.y += (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0); |
538 | q = new MochiKit.Style.Coordinates(p.x + this.options.scroll.offsetWidth, | 538 | q = new MochiKit.Style.Coordinates(p.x + this.options.scroll.offsetWidth, |
539 | p.y + this.options.scroll.offsetHeight); | 539 | p.y + this.options.scroll.offsetHeight); |
540 | } | 540 | } |
541 | var speed = [0, 0]; | 541 | var speed = [0, 0]; |
542 | if (pointer.page.x > (q.x - this.options.scrollSensitivity)) { | 542 | if (pointer.page.x > (q.x - this.options.scrollSensitivity)) { |
543 | speed[0] = pointer.page.x - (q.x - this.options.scrollSensitivity); | 543 | speed[0] = pointer.page.x - (q.x - this.options.scrollSensitivity); |
544 | } else if (pointer.page.x < (p.x + this.options.scrollSensitivity)) { | 544 | } else if (pointer.page.x < (p.x + this.options.scrollSensitivity)) { |
545 | speed[0] = pointer.page.x - (p.x + this.options.scrollSensitivity); | 545 | speed[0] = pointer.page.x - (p.x + this.options.scrollSensitivity); |
546 | } | 546 | } |
547 | if (pointer.page.y > (q.y - this.options.scrollSensitivity)) { | 547 | if (pointer.page.y > (q.y - this.options.scrollSensitivity)) { |
548 | speed[1] = pointer.page.y - (q.y - this.options.scrollSensitivity); | 548 | speed[1] = pointer.page.y - (q.y - this.options.scrollSensitivity); |
549 | } else if (pointer.page.y < (p.y + this.options.scrollSensitivity)) { | 549 | } else if (pointer.page.y < (p.y + this.options.scrollSensitivity)) { |
550 | speed[1] = pointer.page.y - (p.y + this.options.scrollSensitivity); | 550 | speed[1] = pointer.page.y - (p.y + this.options.scrollSensitivity); |
551 | } | 551 | } |
552 | this.startScrolling(speed); | 552 | this.startScrolling(speed); |
553 | } | 553 | } |
554 | 554 | ||
555 | // fix AppleWebKit rendering | 555 | // fix AppleWebKit rendering |
556 | if (/AppleWebKit/.test(navigator.appVersion)) { | 556 | if (/AppleWebKit/.test(navigator.appVersion)) { |
557 | window.scrollBy(0, 0); | 557 | window.scrollBy(0, 0); |
558 | } | 558 | } |
559 | event.stop(); | 559 | event.stop(); |
560 | }, | 560 | }, |
561 | 561 | ||
562 | /** @id MochiKit.DragAndDrop.finishDrag */ | 562 | /** @id MochiKit.DragAndDrop.finishDrag */ |
563 | finishDrag: function (event, success) { | 563 | finishDrag: function (event, success) { |
564 | var dr = MochiKit.DragAndDrop; | 564 | var dr = MochiKit.DragAndDrop; |
565 | this.dragging = false; | 565 | this.dragging = false; |
566 | if (this.options.selectclass) { | 566 | if (this.options.selectclass) { |
567 | MochiKit.DOM.removeElementClass(this.element, | 567 | MochiKit.DOM.removeElementClass(this.element, |
568 | this.options.selectclass); | 568 | this.options.selectclass); |
569 | } | 569 | } |
570 | 570 | ||
571 | if (this.options.ghosting) { | 571 | if (this.options.ghosting) { |
572 | // XXX: from a user point of view, it would be better to remove | 572 | // XXX: from a user point of view, it would be better to remove |
573 | // the node only *after* the MochiKit.Visual.Move end when used | 573 | // the node only *after* the MochiKit.Visual.Move end when used |
574 | // with revert. | 574 | // with revert. |
575 | MochiKit.Position.relativize(this.element, this.ghostPosition); | 575 | MochiKit.Position.relativize(this.element, this.ghostPosition); |
576 | MochiKit.DOM.removeElement(this._clone); | 576 | MochiKit.DOM.removeElement(this._clone); |
577 | this._clone = null; | 577 | this._clone = null; |
578 | } | 578 | } |
579 | 579 | ||
580 | if (success) { | 580 | if (success) { |
581 | dr.Droppables.fire(event, this.element); | 581 | dr.Droppables.fire(event, this.element); |