Author: jmorliaguet
Date: Tue May 16 20:56:34 2006
New Revision: 3146

Modified:
   cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js

Log:

- dragged objects are kept inside the screen's area



Modified: cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
==============================================================================
--- cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    
(original)
+++ cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    Tue May 
16 20:56:34 2006
@@ -948,7 +948,10 @@
   moveEvent: function(e) {
     var x = Event.pointerX(e);
     var y = Event.pointerY(e);
-    this.moved.moveTo({'x': x-this.x1, 'y': y-this.y1});
+
+    var moved = $(this.moved);
+    moved.moveTo({x: x, y: y, fit: true});
+
     Event.stop(e);
 
     var now = new Date().getTime();
@@ -1310,25 +1313,23 @@
         onComplete: (options.onComplete || function() {}).bind(element)
       }));
     }
-    element.setStyle({'left': x + 'px', 'top': y + 'px' });
-  },
+    if (options.fit) {
+      var dimensions = element.getDimensions();
+      var width = dimensions.width;
+      var height = dimensions.height;
+      var page_w = window.innerWidth || document.body.clientWidth;
+      var page_h = window.innerHeight || document.body.clientHeight;
 
-  fitInsideScreen: function(element) {
-    var dimensions = element.getDimensions();
-    var width = dimensions.width;
-    var height = dimensions.height;
-    var page_w = window.innerWidth || document.body.clientWidth;
-    var page_h = window.innerHeight || document.body.clientHeight;
-    var top = element.style.top;
-    var left = element.style.left;
-    if (top) {
-      top = parseInt(top);
-      if (top + height > page_h) { element.style.top = top - height + "px"};
-    }
-    if (left) {
-      left = parseInt(left);
-      if (left + width > page_w) { element.style.left = left - width + "px"};
+      page_w = page_w -16;
+      page_h = page_h -16;
+
+      if (x + width > page_w) x = page_w - width;
+      if (x < 0) x = 0;
+
+      if (y + height > page_h) y = page_h - height;
+      if (y < 0) y = 0;
     }
+    element.setStyle({'left': x + 'px', 'top': y + 'px' });
   }
 
 });
@@ -2365,8 +2366,7 @@
 
     // Display the menu inside the screen
     var widget = this.widget;
-    widget.moveTo({'x': this.mouseX, 'y': this.mouseY});
-    widget.fitInsideScreen();
+    widget.moveTo({x: this.mouseX, y: this.mouseY, fit: true});
   },
 
   /* Event handlers */
@@ -2501,8 +2501,7 @@
   },
 
   prepare: function() {
-    this.widget.moveTo({'x': this.mouseX, 'y': this.mouseY +10});
-    this.widget.fitInsideScreen();
+    this.widget.moveTo({x: this.mouseX, y: this.mouseY +10, fit: true});
   },
 
   /* Event handlers */
@@ -2531,9 +2530,7 @@
   },
 
   moveEvent: function(e) {
-    var mouseX = Event.pointerX(e);
-    var mouseY = Event.pointerY(e);
-    this.widget.moveTo({'x': mouseX+10, 'y': mouseY+10});
+    this.widget.moveTo({x: Event.pointerX(e)+10, y: Event.pointerY(e)+10});
     Event.stop(e);
   },
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to