Author: jmorliaguet
Date: Sat Mar 25 17:47:24 2006
New Revision: 2726

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

- DnD: optimisations and moved the 'shift' option to 'shifting'



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 
17:47:24 2006
@@ -691,10 +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._draggable_token = 'cpsskins_draggable_' + this.hash();
+    this._shiftable_token = 'cpsskins_shiftable_' + this.hash();
 
     // cancel text selection
     document.onmousedown = this.cancelEvent;
@@ -710,6 +713,7 @@
     var handle = dragging.handle;
     var sources = dragging.sources || [];
     var dropzones = this._dropzones;
+    var draggable_token = this._draggable_token;
     var widget = view.widget;
 
     if (!handle) { handle = sources; }
@@ -724,7 +728,7 @@
 
     sources.each(function(d) {
       $$(d).each(function(el) {
-        if (el.childOf(widget)) el._cpsskins_draggable = true;
+        if (el.childOf(widget)) el[draggable_token] = true;
       });
     });
 
@@ -740,7 +744,8 @@
 
   _findDraggable: function(e) {
     var element = Event.element(e);
-    while (element.parentNode && !element._cpsskins_draggable) {
+    var draggable_token = this._draggable_token;
+    while (element.parentNode && !element[draggable_token]) {
       element = element.parentNode;
     }
     return element;
@@ -780,9 +785,9 @@
     this.y0 = pos[1];
 
     var dragging = this.def.dragging;
+    var shifting = this.def.shifting;
 
-    if (dragging.shift || dragging.container ||
-        dragging.offset_x || dragging.offset_y ) {
+    if (shifting || dragging.offset_x || dragging.offset_y ) {
       this.x1 = dragging.offset_x || -5;
       this.y1 = dragging.offset_y || -5;
     } else {
@@ -814,7 +819,7 @@
       document.getElementsByTagName('body')[0].appendChild(feedback);
       this.moved = feedback;
     } else {
-      if (!this.def.dragging.shift) {
+      if (!this.def.shifting) {
         this.moved = draggable;
       }
     }
@@ -825,6 +830,7 @@
     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) {
@@ -844,28 +850,37 @@
     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 shift = this.def.dragging.shift;
-    if (shift && el.hasClassName(shift)) {
-      var speed = this._getVerticalSpeed(y);
-      if (Math.abs(speed) < 1) return;
-      if (speed > 0) {
-        var target = this._findNext(el, shift);
-      } else {
-        var target = el;
+    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);
       }
-      el.parentNode.insertBefore(this.dragged, target);
-    }
 
-    var container = this.def.dragging.container;
-    if (container && el.hasClassName(container)) {
-      el.appendChild(this.dragged);
+      var container = shifting.container || null;
+      if (container && el.hasClassName(container)) {
+        el.appendChild(this.dragged);
+      }
     }
 
     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'
@@ -877,6 +892,7 @@
   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 17:47:24 2006
@@ -102,13 +102,15 @@
    "action": "displayInfo",
    "dragging": {
      "sources": ["#dragthis"],
-     "shift": "block",
-     "container": "container",
      "feedback": {
        "opacity": 0.8,
        "border": "#000",
        "background": "#ff0"
      }
+   },
+   "shifting": {
+     "element": "block",
+     "container": "container"
   }}
   </ins>
 
@@ -134,14 +136,16 @@
    "action": "displayInfo",
    "dragging": {
      "sources": [".block"],
-     "shift": "block",
-     "container": "container",
      "feedback": {
        "opacity": 0.7,
        "border": "#000",
        "background": "#fd9"
      }
    },
+   "shifting": {
+     "element": "block",
+     "container": "container"
+   },
    "dropping": {
      "zoomto": {
        "duration": 200
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to