From 5a2cc17af5092f6cbfc7f1e4e447bee39bddabc1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 16 Mar 2009 07:32:23 -0600 Subject: [PATCH] Optimize dragging --- imp/js/src/dragdrop.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/imp/js/src/dragdrop.js b/imp/js/src/dragdrop.js index 2d820384b..3311d35f1 100644 --- a/imp/js/src/dragdrop.js +++ b/imp/js/src/dragdrop.js @@ -309,30 +309,41 @@ Drag = Class.create({ _onMoveDrag: function(xy, e) { - var c_opt, caption, cname, d_cap, elt, + var c_opt, caption, cname, d_cap, d = DragDrop.Drops.drop, div = DragDrop.Drags.div, - d_update = true; + d_update = true, + elt = e.element(); + + if (this.lastelt == elt) { + this._setCaption(div, xy); + return; + } + + this.lastelt = elt; /* Do mouseover/mouseout-like detection here. Saves on observe calls * and handles case where mouse moves over scrollbars. */ if (DragDrop.Drops.drops.size()) { - elt = e.element(); if (!elt.hasClassName('DropElt')) { elt = elt.up('.DropElt'); } if (elt) { elt = DragDrop.Drops.get_drop(elt); - if (elt != d) { + if (elt == d) { + d_update = false; + } else { elt.mouseOver(); + d = elt; } } else if (d) { d.mouseOut(); + d = null; } } - if (d && DragDrop.validDrop(this.element)) { + if (d_update && d && DragDrop.validDrop(this.element)) { d_cap = d.options.caption; if (d_cap) { caption = Object.isFunction(d_cap) ? d_cap(d.element, this.element, e) : d_cap; @@ -358,7 +369,12 @@ Drag = Class.create({ } } - if (!this.lastcaption.empty()) { + this._setCaption(div, xy); + }, + + _setCaption: function(div, xy) + { + if (this.lastcaption) { this._setContents(div, xy[0] + 15, xy[1] + (this.ghost ? (this.ghost.getHeight() + 5) : 5)); } }, -- 2.11.0