Author: jmorliaguet
Date: Sat Mar 25 18:14:40 2006
New Revision: 2727

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
Log:

- better optimisation: we register shiftable and container zones only once.



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sat Mar 25 
18:14:40 2006
@@ -691,13 +691,13 @@
   setup: function() {
     this.dragEvent = this.dragEvent.bindAsEventListener(this);
     this.moveEvent = this.moveEvent.bindAsEventListener(this);
-    this.mouseOverEvent = this.mouseOverEvent.bindAsEventListener(this);
     this.dropEvent = this.dropEvent.bindAsEventListener(this);
     this.cancelEvent = new Function("return false");
 
     this._dropzones = [];
+    this._shiftablezones = [];
+    this._containerzones = [];
     this._draggable_token = 'cpsskins_draggable_' + this.hash();
-    this._shiftable_token = 'cpsskins_shiftable_' + this.hash();
 
     // cancel text selection
     document.onmousedown = this.cancelEvent;
@@ -713,6 +713,8 @@
     var handle = dragging.handle;
     var sources = dragging.sources || [];
     var dropzones = this._dropzones;
+    var shiftablezones = this._shiftablezones;
+    var containerzones = this._containerzones;
     var draggable_token = this._draggable_token;
     var widget = view.widget;
 
@@ -732,6 +734,14 @@
       });
     });
 
+    if (this.def.shifting) {
+      $$(this.def.shifting.element).each(function(el) {
+        if (el.childOf(widget)) shiftablezones.push(el);
+      });
+      $$(this.def.shifting.container).each(function(el) {
+        if (el.childOf(widget)) containerzones.push(el);
+      });
+    }
     if (this.def.dropping) {
       (this.def.dropping.targets || []).each(function(d) {
         $$(d).each(function(el) {
@@ -787,7 +797,7 @@
     var dragging = this.def.dragging;
     var shifting = this.def.shifting;
 
-    if (shifting || dragging.offset_x || dragging.offset_y ) {
+    if (dragging.offset_x || dragging.offset_y ) {
       this.x1 = dragging.offset_x || -5;
       this.y1 = dragging.offset_y || -5;
     } else {
@@ -830,7 +840,6 @@
     this.moved.moveTo({'x': x-this.x1, 'y': y-this.y1});
 
     Event.observe(document, "mousemove", this.moveEvent);
-    Event.observe(document, "mouseover", this.mouseOverEvent);
     Event.observe(document, "mouseup", this.dropEvent);
 
     if (this.def.dropping) {
@@ -850,37 +859,33 @@
     var x = Event.pointerX(e);
     var y = Event.pointerY(e);
     this.moved.moveTo({'x': x-this.x1, 'y': y-this.y1});
-    Event.stop(e);
-  },
-
-  mouseOverEvent: function(e) {
-    var x = Event.pointerX(e);
-    var y = Event.pointerY(e);
-    var el = $(Event.element(e));
 
     var shifting = this.def.shifting;
     if (shifting) {
-      var element = shifting.element || null;
-      if (element && el.hasClassName(element)) {
-        var speed = this._getVerticalSpeed(y);
-        if (Math.abs(speed) < 1) return;
-        if (speed > 0) {
-          var target = this._findNext(el, shifting.element);
-        } else {
-          var target = el;
-        }
-        el.parentNode.insertBefore(this.dragged, target);
-      }
+      this._shiftablezones.each(function(s) {
+        if (Position.within(s, x, y)) {
+          var speed = this._getVerticalSpeed(y);
+          if (Math.abs(speed) < 1) return;
+          if (speed > 0) {
+            var target = this._findNext(s, shifting.element);
+          } else {
+            var target = s;
+          }
+          s.parentNode.insertBefore(this.dragged, target);
+          return;
+        };
+      }.bind(this));
 
-      var container = shifting.container || null;
-      if (container && el.hasClassName(container)) {
-        el.appendChild(this.dragged);
-      }
+      this._containerzones.each(function(s) {
+        if (Position.within(s, x, y)) {
+          s.appendChild(this.dragged);
+          return;
+        };
+      }.bind(this));
     }
 
     if (this.def.dragging.feedback) {
       if (this.target)
-        return;
         var dim = this.target.getDimensions();
         this.moved.setStyle({
           'width': dim.width + 'px', 'height': dim.height + 'px'
@@ -892,7 +897,6 @@
   dropEvent: function(e) {
     Event.stopObserving(document, "mousemove", this.moveEvent);
     Event.stopObserving(document, "mouseup", this.dropEvent);
-    Event.stopObserving(document, "mouseover", this.mouseOverEvent);
 
     var x = Event.pointerX(e);
     var y = Event.pointerY(e);

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
        Sat Mar 25 18:14:40 2006
@@ -109,8 +109,8 @@
      }
    },
    "shifting": {
-     "element": "block",
-     "container": "container"
+     "element": ".block",
+     "container": ".container"
   }}
   </ins>
 
@@ -143,8 +143,8 @@
      }
    },
    "shifting": {
-     "element": "block",
-     "container": "container"
+     "element": ".block",
+     "container": ".container"
    },
    "dropping": {
      "zoomto": {
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to