Merge branch 'master' of git+ssh://git.luon.net/git/plemp

This commit is contained in:
Paul van Tilburg 2010-09-12 00:33:11 +02:00
commit 24dec53ae5
1 changed files with 20 additions and 10 deletions

View File

@ -12,8 +12,10 @@ function setup_draggable(id) {
old_endeffect(element);
element.style.zIndex = new_ZIndex();
}
Draggables.addObserver(new DragRegObserver($(id)));
$(id).appear({duration: 1.0});
drag_obs = new DragRegObserver($(id));
Draggables.addObserver(drag_obs);
$(id).dirty = false;
$(id).appear();
}
// Observer for draggables that commits the drag changes to the server.
@ -22,12 +24,17 @@ DragRegObserver.prototype = {
initialize: function(element) {
this.element = $(element);
},
onStart: function() {},
onStart: function(eventName, draggable, event) {
console.debug(event);
draggable.element.dirty = true;
},
onEnd: function (eventName, draggable, event) {
if (Draggables.activeDraggable.element == this.element) {
elem = draggable.element;
new Ajax.Request(document.baseURI + 'savepos/' + elem.id +
'/' + elem.style.top + '/' + elem.style.left);
'/' + elem.style.top + '/' + elem.style.left, {
onSuccess: function(response) { elem.dirty = false; }
});
}
}
}
@ -37,7 +44,7 @@ function key_handler(e) {
var key_code = e.keyCode;
switch(key_code) {
case 27:
case 27: /* Escape */
hide_add_dialog();
break;
}
@ -65,13 +72,16 @@ function new_ZIndex() {
return parseInt(max_index) + 1;
}
// Moves a draggable with the given ID to a position if it is not already there.
// Moves a draggable with the given ID to a position unless:
// it is currently being dragged, or it has been dragged but not this is
// not registered at the server side yet, or it is already on the right spot.
function move_draggable_if_needed(id, left, top) {
var actDrag = Draggables.activeDraggable;
if ($(id).dirty || (actDrag && actDrag.element == $(id))) {
return false;
}
if ($(id).style.left != left || $(id).style.top != top) {
var actDrag = Draggables.activeDraggable;
if (!actDrag || actDrag.element != $(id)) {
new Effect.Move(id, { x: left, y: top, mode: 'absolute' });
}
new Effect.Move(id, { x: left, y: top, mode: 'absolute' });
}
}