Author: jmorliaguet
Date: Fri Mar 10 21:03:31 2006
New Revision: 2573

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

- simpler / more elegant code:

    node.moveTo({...})

  instead of:

    CPSSkins.Canvas.moveTo(node, {...})



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 Fri Mar 10 
21:03:31 2006
@@ -34,7 +34,7 @@
 }
 
 var CPSSkins = {
-  Version: "0.7",
+  Version: "0.8",
 
   Controllers: $H({}),
   Effects: $H({}),
@@ -644,7 +644,7 @@
         'z-index': parseInt(draggable.getStyle('z-index') || 0) +1,
         'position': 'absolute'
       });
-      CPSSkins.Canvas.setOpacity(clone, 0.8);
+      clone.setOpacity(0.8);
       draggable.parentNode.insertBefore(clone, draggable);
       this.moved = clone;
     } else {
@@ -662,7 +662,7 @@
   moveEvent: function(e) {
     var x = Event.pointerX(e);
     var y = Event.pointerY(e);
-    CPSSkins.Canvas.moveTo(this.moved, {'x': x-this.x1, 'y': y-this.y1});
+    this.moved.moveTo({'x': x-this.x1, 'y': y-this.y1});
   },
 
   dropEvent: function(e) {
@@ -686,7 +686,7 @@
 
     if (this.def.ghosting) {
       if (revert) {
-        CPSSkins.Canvas.moveTo(this.moved, {
+        this.moved.moveTo({
           'x': this.x0,
           'y': this.y0,
           'duration': 400,
@@ -868,55 +868,6 @@
     return node;
   },
 
-  setOpacity: function(element, opacity) {
-    if (window.ActiveXObject) {
-      element.style.filter = "alpha(opacity=" + opacity*100 + ")";
-    } else {
-      element.style.opacity = opacity;
-    }
-  },
-
-  moveTo: function(node, options) {
-    node = $(node);
-    var x = options.x;
-    var y = options.y;
-    if (options.duration) {
-      var pos = Position.page(node);
-      var x0 = pos[0];
-      var y0 = pos[1];
-      new CPSSkins.Scheduler(Object.extend(options, {
-        action: function(value) {
-          node.setStyle({
-            'left': x0 + (x - x0) * value + 'px',
-            'top': y0 + (y - y0) * value + 'px'
-          });
-        },
-        onComplete: (options.onComplete || function() {}).bind(node)
-      }));
-    }
-    node.style.left = x + "px";
-    node.style.top = y + "px";
-  },
-
-  fitInsideScreen: function(node) {
-    node = $(node);
-    var dimensions = node.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 = node.style.top;
-    var left = node.style.left;
-    if (top) {
-      top = parseInt(top);
-      if (top + height > page_h) { node.style.top = top - height + "px"};
-    }
-    if (left) {
-      left = parseInt(left);
-      if (left + width > page_w) { node.style.left = left - width + "px"};
-    }
-  },
-
   addStyleSheet: function(id, src) {
     if (id in this._styles) {
       return;
@@ -966,6 +917,62 @@
 
 });
 
+if (!window.Element)
+  var Element = new Object();
+
+if (!Element.Methods)
+  Element.Methods = new Object();
+
+Object.extend(Element.Methods, {
+
+  setOpacity: function(element, opacity) {
+    if (window.ActiveXObject) {
+      element.style.filter = "alpha(opacity=" + opacity*100 + ")";
+    } else {
+      element.style.opacity = opacity;
+    }
+  },
+
+  moveTo: function(element, options) {
+    var x = options.x;
+    var y = options.y;
+    if (options.duration) {
+      var pos = Position.page(node);
+      var x0 = pos[0];
+      var y0 = pos[1];
+      new CPSSkins.Scheduler(Object.extend(options, {
+        action: function(value) {
+          element.setStyle({
+            'left': x0 + (x - x0) * value + 'px',
+            'top': y0 + (y - y0) * value + 'px'
+          });
+        },
+        onComplete: (options.onComplete || function() {}).bind(element)
+      }));
+    }
+    element.setStyle({'left': x + 'px', 'top': y + 'px' });
+  },
+
+  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"};
+    }
+  }
+
+});
+
 
 CPSSkins.Scheduler = Class.create();
 CPSSkins.Scheduler.prototype = {
@@ -1034,21 +1041,19 @@
   },
 
   fadein: function(node, options) {
-    var setOpacity = CPSSkins.Canvas.setOpacity;
-    setOpacity(node, 0);
+    node.setOpacity(0);
     return new CPSSkins.Scheduler({
       delay: options.delay,
       duration: options.duration,
-      action: function(value) { setOpacity(node, value) },
+      action: function(value) { node.setOpacity(value) },
       onComplete: function() { node.show() }
     });
   },
 
   fadeout: function(node, options) {
-    var setOpacity = CPSSkins.Canvas.setOpacity;
-    setOpacity(node, 1);
+    node.setOpacity(1);
     Object.extend(options, {
-      action: function(value) { setOpacity(node, 1-value) },
+      action: function(value) { node.setOpacity(1-value) },
       onComplete: function() { node.hide() }
     });
     return new CPSSkins.Scheduler(options);
@@ -1930,8 +1935,8 @@
 
     // Display the menu inside the screen
     var widget = this.widget;
-    CPSSkins.Canvas.moveTo(widget, {'x': this.mouseX, 'y': this.mouseY});
-    CPSSkins.Canvas.fitInsideScreen(widget);
+    widget.moveTo({'x': this.mouseX, 'y': this.mouseY});
+    widget.fitInsideScreen();
   },
 
   /* Event handlers */
@@ -2013,8 +2018,8 @@
     if (!selected) return;
 
     var widget = this.widget;
-    CPSSkins.Canvas.moveTo(widget, {'x': this.mouseX-50, 'y': this.mouseY});
-    CPSSkins.Canvas.fitInsideScreen(widget);
+    widget.moveTo({'x': this.mouseX-50, 'y': this.mouseY});
+    widget.fitInsideScreen();
   },
 
   render: function(data) {
@@ -2096,9 +2101,8 @@
   },
 
   prepare: function() {
-    this.widget.style.top = this.mouseY + 20 + "px";
-    this.widget.style.left = this.mouseX + "px";
-    CPSSkins.Canvas.fitInsideScreen(this.widget);
+    this.widget.moveTo({'x': this.mouseY + 20, 'y': this.mouseX});
+    this.widget.fitInsideScreen();
   },
 
   /* Event handlers */
@@ -2126,7 +2130,7 @@
   moveEvent: function(e) {
     var mouseX = Event.pointerX(e);
     var mouseY = Event.pointerY(e);
-    CPSSkins.Canvas.moveTo(this.widget, {'x': mouseX+10, 'y': mouseY+10});
+    this.widget.moveTo({'x': mouseX+10, 'y': mouseY+10});
   },
 
   hideEvent: function(e) {
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to