aboutsummaryrefslogtreecommitdiffstats
path: root/railties/html/javascripts/dragdrop.js
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-07 14:18:16 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-07 14:18:16 +0000
commit94209e2fb7f244be5da2f208c2e5dacd2fede47e (patch)
tree3841083cd10c3b5231b0bd7d27adbc66f8ed744c /railties/html/javascripts/dragdrop.js
parent75157bbf64571548983892e62fab5789e9ab06d0 (diff)
downloadrails-94209e2fb7f244be5da2f208c2e5dacd2fede47e.tar.gz
rails-94209e2fb7f244be5da2f208c2e5dacd2fede47e.tar.bz2
rails-94209e2fb7f244be5da2f208c2e5dacd2fede47e.zip
Added a bunch of script.aculo.us features: Effect.ScrollTo, to smoothly scroll the page to an element, better Firefox flickering handling on SlideUp/SlideDown, Removed a possible memory leak in IE with draggables, Added support for cancelling dragging my hitting ESC #1644 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1759 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/html/javascripts/dragdrop.js')
-rw-r--r--railties/html/javascripts/dragdrop.js70
1 files changed, 39 insertions, 31 deletions
diff --git a/railties/html/javascripts/dragdrop.js b/railties/html/javascripts/dragdrop.js
index 20432a3c88..eb6511095f 100644
--- a/railties/html/javascripts/dragdrop.js
+++ b/railties/html/javascripts/dragdrop.js
@@ -196,17 +196,13 @@ var Droppables = {
},
fire: function(event, element) {
- if(!this.drops) return;
- var pX = Event.pointerX(event);
- var pY = Event.pointerY(event);
+ if(!this.last_active) return;
Position.prepare();
- var i = this.drops.length-1; do {
- var drop = this.drops[i];
- if(this.is_affected(pX, pY, element, drop))
- if(drop.droppable.onDrop)
- drop.droppable.onDrop(element);
- } while (i--);
+ if (this.is_affected(Event.pointerX(event), Event.pointerY(event), element, this.last_active))
+ if (this.last_active.droppable.onDrop)
+ this.last_active.droppable.onDrop(element, this.last_active);
+
},
reset: function() {
@@ -247,7 +243,6 @@ Draggable.prototype = {
}.extend(arguments[1] || {});
this.element = $(element);
- this.element.drag = this;
this.handle = options.handle ? $(options.handle) : this.element;
// fix IE
@@ -270,6 +265,7 @@ Draggable.prototype = {
Event.observe(this.handle, "mousedown", this.startDrag.bindAsEventListener(this));
Event.observe(document, "mouseup", this.endDrag.bindAsEventListener(this));
Event.observe(document, "mousemove", this.update.bindAsEventListener(this));
+ Event.observe(document, "keypress", this.keyPress.bindAsEventListener(this));
},
currentLeft: function() {
return parseInt(this.element.style.left || '0');
@@ -290,31 +286,43 @@ Draggable.prototype = {
Event.stop(event);
}
},
- endDrag: function(event) {
- if(this.active && this.dragging) {
- this.active = false;
- this.dragging = false;
+ finishDrag: function(event, success) {
+ this.active = false;
+ this.dragging = false;
+
+ if(success) Droppables.fire(event, this.element);
+ Draggables.notify('onEnd', this);
+
+ var revert = this.options.revert;
+ if(revert && typeof revert == 'function') revert = revert(this.element);
- Droppables.fire(event, this.element);
- Draggables.notify('onEnd', this);
+ if(revert && this.options.reverteffect) {
+ this.options.reverteffect(this.element,
+ this.currentTop()-this.originalTop,
+ this.currentLeft()-this.originalLeft);
+ } else {
+ this.originalLeft = this.currentLeft();
+ this.originalTop = this.currentTop();
+ }
+
+ this.element.style.zIndex = this.originalZ;
- var revert = this.options.revert;
- if(revert && typeof revert == 'function') revert = revert(this.element);
+ if(this.options.endeffect)
+ this.options.endeffect(this.element);
- if(revert && this.options.reverteffect) {
- this.options.reverteffect(this.element,
- this.currentTop()-this.originalTop,
- this.currentLeft()-this.originalLeft);
- } else {
- this.originalLeft = this.currentLeft();
- this.originalTop = this.currentTop();
+ Droppables.reset();
+ },
+ keyPress: function(event) {
+ if(this.active) {
+ if(event.keyCode==Event.KEY_ESC) {
+ this.finishDrag(event, false);
+ Event.stop(event);
}
- this.element.style.zIndex = this.originalZ;
-
- if(this.options.endeffect)
- this.options.endeffect(this.element);
-
- Droppables.reset();
+ }
+ },
+ endDrag: function(event) {
+ if(this.active && this.dragging) {
+ this.finishDrag(event, true);
Event.stop(event);
}
this.active = false;