home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 October / tst.iso / multimed / IDN / web / tapdogs / JS / ScrollBox.js < prev    next >
Encoding:
Text File  |  1999-09-24  |  2.3 KB  |  65 lines

  1. // Lemon (HK) Ltd
  2. // last modified on 30 July 1999
  3.  
  4. __registered_ScrollBox = new Array();
  5. SCROLLING_FACTOR=24;
  6.  
  7. function ScrollBox(src,margin,direction) {
  8.   this.lyr = SimpleLayer;
  9.   this.lyr(src);
  10.   __registered_ScrollBox[__registered_ScrollBox.length] = this;
  11.   if (direction==null) direction=0;
  12.   if (direction==0 || direction==2) {
  13.     this.up = new Button(src+".ScrollUp");
  14.     this.down = new Button(src+".ScrollDown");
  15.     this.up.onPress=ScrollBoxUp;
  16.     this.down.onPress=ScrollBoxDown; 
  17.     this.up.resize(margin, this.up.h);
  18.     this.down.resize(margin, this.up.h);
  19.   }
  20.   if (direction==1 || direction==2)
  21.   {
  22.     this.left = new Button(src+".ScrollLeft");
  23.     this.right = new Button(src+".ScrollRight");
  24.     this.left.onPress=ScrollBoxLeft;
  25.     this.right.onPress=ScrollBoxRight;
  26.     this.left.resize(this.left.w, margin);
  27.     this.right.resize(this.left.w, margin);
  28.   }
  29.   this.content = new SimpleLayer(src+".ScrollBody");
  30.   this.content.moveTo(0,0);
  31.   if (this.content.h < this.h) this.content.resize(this.content.w, this.h);
  32.   this.redraw=ScrollBoxRedraw;
  33.   this.redraw();
  34. }
  35. function ScrollBoxUp() { ScrollBoxScrollIt(this, 1, true); }
  36. function ScrollBoxDown() { ScrollBoxScrollIt(this, -1, true); }
  37. function ScrollBoxLeft() { ScrollBoxScrollIt(this, 1, false); }
  38. function ScrollBoxRight() { ScrollBoxScrollIt(this, -1, false); }
  39. function ScrollBoxScrollIt(target,dir,vert) {
  40.   var scrollbox = getParent(target.path);
  41.   var obj = findObject(scrollbox, __registered_ScrollBox);
  42.   if (obj && vert) {
  43.     var dh = obj.content.h - obj.h;
  44.     var dy = dir * SCROLLING_FACTOR;
  45.     if (dy > 0 && dy + obj.content.y > 0) dy = -obj.content.y;
  46.     if (dy < 0 && dy + obj.content.y < -dh) dy = - obj.content.y - dh;
  47.     obj.content.moveBy(obj.content.x,dy);
  48.   }
  49.   if (obj && !vert) {
  50.     var dw = obj.content.w - obj.w;
  51.     var dx = dir * SCROLLING_FACTOR;
  52.     if (dx > 0 && dx + obj.content.x > 0) dx = -obj.content.x;
  53.     if (dx < 0 && dx + obj.content.x < -dw) dx = - obj.content.x - dw;
  54.     obj.content.moveBy(dx,obj.content.y);
  55.   }
  56. }
  57. function ScrollBoxRedraw() {
  58.   var w = this.w-this.up.w;
  59.   if (NS) this.content.obj.clip.width = w;
  60.   else    this.content.obj.style.pixelWidth = w;
  61.  
  62.   this.up.moveTo(w, 0);
  63.   this.down.moveTo(w, this.h-this.down.w);
  64. }
  65.