Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.         DynAPI Distribution
  3.         Swiper Animation Extension - originally designed by Erik Arvidsson (http://web.eae.net)
  4.  
  5.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.        
  7.         requires: DynLayer
  8.        
  9. */
  10.  
  11. Swiper = {}; // used by dynapi.library
  12.  
  13. DynLayer.prototype.swipeTo = function(dir, steps, ms) {
  14.  
  15.         this._swipeSteps = (steps!=null)? steps: 4;
  16.         this._swipeMS = (ms!=null)? ms:25;
  17.         this._swipeDir=dir;
  18.  
  19.         if (this.swipeTimer != null) window.clearTimeout(this.swipeTimer);
  20.                
  21.         if (!this._swipeCnt) {          // No animation yet!
  22.                 this._swipeOrgX  = this.getX();
  23.                 this._swipeOrgY  = this.getY();
  24.                 this._swipeOrgWidth = this.getWidth();
  25.                 this._swipeOrgHeight  = this.getHeight();
  26.         }
  27.        
  28.         this._swipeCnt = this._swipeSteps;
  29.         this.setClip([0,0,0,0]);
  30.                        
  31.         window.setTimeout(this+"._swipe()", this._swipeMS);
  32. };
  33. DynLayer.prototype._swipe = function() {
  34.         var steps       = this._swipeSteps;
  35.         var x = this._swipeOrgX;
  36.         var y = this._swipeOrgY;
  37.         var w = this._swipeOrgWidth;
  38.         var h = this._swipeOrgHeight;
  39.        
  40.         if (this._swipeCnt == 0) {
  41.                 this.setClip([0, w, h,0]);
  42.                 this.invokeEvent('swipefinish');
  43.                 return;
  44.         }
  45.         else {
  46.                 this._swipeCnt--;
  47.                 this.setVisible(true);
  48.                 switch (this._swipeDir) {
  49.                         case "bottom":          //down (see the numpad)
  50.                                 this.setClip([h * this._swipeCnt / steps, w, h, 0]);
  51.                                 this.setY(y - h * this._swipeCnt / steps);
  52.                                 break;
  53.                         case "top":
  54.                                 this.setClip([0, w, h * (steps - this._swipeCnt) / steps, 0]);
  55.                                 this.setY(y + h * this._swipeCnt / steps);
  56.                                 break;
  57.                         case "right":
  58.                                 this.setClip([0, w, h,w * this._swipeCnt / steps]);
  59.                                 this.setX(x - w * this._swipeCnt / steps);
  60.                                 break;
  61.                         case "left":
  62.                                 this.setClip([0, w * (steps - this._swipeCnt) / steps, h, 0]);
  63.                                 this.setX(x + w * this._swipeCnt / steps);
  64.                                 break;
  65.                         case "bottom-right":
  66.                                 this.setClip([h * this._swipeCnt / steps, w, h, w * this._swipeCnt / steps]);
  67.                                 this.setX(x - w * this._swipeCnt / steps);
  68.                                 this.setY(y - h * this._swipeCnt / steps);
  69.                                 break;
  70.                         case "bottom-left":
  71.                                 this.setClip([h * this._swipeCnt / steps, w * (steps - this._swipeCnt) / steps, h, 0]);
  72.                                 this.setX(x + w * this._swipeCnt / steps);
  73.                                 this.setY(y - h * this._swipeCnt / steps);
  74.                                 break;
  75.                         case "top-left":
  76.                                 this.setClip([0, w * (steps - this._swipeCnt) / steps, h * (steps - this._swipeCnt) / steps, 0]);
  77.                                 this.setX(x + w * this._swipeCnt / steps);
  78.                                 this.setY(y + h * this._swipeCnt / steps);
  79.                                 break;
  80.                         case "top-right":
  81.                                 this.setClip([0, w, h * (steps - this._swipeCnt) / steps, w * this._swipeCnt / steps]);
  82.                                 this.setX(x - w * this._swipeCnt / steps);
  83.                                 this.setY(y + h * this._swipeCnt / steps);
  84.                 }              
  85.                 this.swipeTimer = window.setTimeout(this+"._swipe()", this._swipeMS);
  86.         }
  87. };
  88.  
  89.