summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/DragAndDrop.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/DragAndDrop.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/DragAndDrop.js14
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,59 +1,59 @@
1/*** 1/***
2MochiKit.DragAndDrop 1.5 2MochiKit.DragAndDrop 1.5
3 3
4See <http://mochikit.com/> for documentation, downloads, license, etc. 4See <http://mochikit.com/> for documentation, downloads, license, etc.
5 5
6Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 6Copyright (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
11MochiKit.Base._module('DragAndDrop', '1.5', ['Base', 'Iter', 'DOM', 'Signal', 'Visual', 'Position']); 11MochiKit.Base.module(MochiKit, 'DragAndDrop', '1.5', ['Base', 'Iter', 'DOM', 'Signal', 'Visual', 'Position']);
12 12
13MochiKit.DragAndDrop.Droppables = { 13MochiKit.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
@@ -261,98 +261,99 @@ MochiKit.DragAndDrop.Draggables = {
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 */
338MochiKit.DragAndDrop.Draggable = function (element, options) { 339MochiKit.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
346MochiKit.DragAndDrop.Draggable.prototype = { 347MochiKit.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;
@@ -397,137 +398,136 @@ MochiKit.DragAndDrop.Draggable.prototype = {
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);