Author: jmorliaguet
Date: Sun Apr  2 16:42:35 2006
New Revision: 2760

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- scalability: the drop-and-drop controller now scales better when there
  are lots of elements on the page since drop/shift zones are registered
  on drag events.



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 Sun Apr  2 
16:42:35 2006
@@ -690,7 +690,6 @@
   new CPSSkins.Controller(), {
 
   setup: function() {
-    this.dragEvent = this.dragEvent.bindAsEventListener(this);
     this.moveEvent = this.moveEvent.bindAsEventListener(this);
     this.dropEvent = this.dropEvent.bindAsEventListener(this);
     this.cancelEvent = new Function("return false");
@@ -698,7 +697,6 @@
     this._dropzones = [];
     this._shiftablezones = [];
     this._containerzones = [];
-    this._draggable_token = 'cpsskins_draggable_' + this.hash();
 
     // cancel text selection
     document.onmousedown = this.cancelEvent;
@@ -708,38 +706,31 @@
   },
 
   register: function(view) {
-    var dragEvent = this.dragEvent;
     var dragging = this.def.dragging;
     if (!dragging) {
       return;
     }
-    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;
+    var dragEvent = this.dragEvent.bindAsEventListener(
+                      Object.extend(this, {'widget': widget}));
+    Event.observe(widget, "mousedown", dragEvent);
+    var handle = dragging.handle || dragging.sources || [];
+    this.handle_selector = new Selector(handle);
+  },
 
-    if (!handle) { handle = sources; }
-    handle.each(function(h) {
-      $$(h).each(function(el) {
-        if (el.childOf(widget)) {
-          Event.observe(el, "mousedown", dragEvent);
-          el.setStyle({'cursor': 'move'});
-        }
-      });
-    });
-
-    sources.each(function(d) {
-      $$(d).each(function(el) {
-        if (el.childOf(widget)) {
-          el[draggable_token] = true;
-        };
-      });
-    });
+  unregister: function(view) {
+    var widget = view.widget;
+    var dragEvent = this.dragEvent.bindAsEventListener(
+                      Object.extend(this, {'widget': widget}));
+    Event.stopObserving(widget, "mousedown", dragEvent);
+  },
 
+  _setupZones: function() {
+    var widget = this.widget;
     var shifting = this.def.shifting;
+    var dropzones = this._dropzones;
+    var shiftablezones = this._shiftablezones;
+    var containerzones = this._containerzones;
     if (shifting) {
       if (shifting.element) {
         $$(shifting.element).each(function(el) {
@@ -759,16 +750,17 @@
         });
       });
     }
-
   },
 
   _findDraggable: function(e) {
     var element = Event.element(e);
-    var draggable_token = this._draggable_token;
-    while (element.parentNode && !element[draggable_token]) {
+    var handle_selector = this.handle_selector;
+    var widget = this.widget;
+    while (element.parentNode && !handle_selector.match(element)) {
+      if (!$(element).childOf(widget)) return null;
       element = element.parentNode;
     }
-    return element;
+    return (element != document) ? element : null;
   },
 
   _getVerticalSpeed: function(y) {
@@ -794,12 +786,15 @@
 
   dragEvent: function(e) {
     if (!Event.isLeftClick(e)) return false;
-    var draggable = $(this._findDraggable(e));
+    var draggable = this._findDraggable(e);
     if (!draggable) {
       return false;
     }
+
+    this._setupZones();
+
+    this.target = $(draggable);
     var pos = Position.cumulativeOffset(draggable);
-    this.target = draggable;
 
     var x = Event.pointerX(e);
     var y = Event.pointerY(e);
@@ -1799,7 +1794,7 @@
     var controllers_ids = view.getControllers();
     controllers_ids.each(function(c) {
       var controller = CPSSkins.getControllerById(c);
-      if (controller) { 
+      if (controller) {
         controller.views.add(view_id);
         controller.unregister(view);
         controller.register(view);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to