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

  1. // Lemon (HK) Ltd
  2. // last modified on 30 July 1999
  3.  
  4. __INIT = IE = NS = ver4 = zmax = 0;
  5. __registered_Slide = new Array();
  6. __registered_Grow = new Array();
  7. __registered_Loading = new Array();
  8.  
  9. function SimpleLayer(src) {
  10.   if (!__INIT) {
  11.     IE = document.all ? 1 : 0;
  12.     NS = document.layers ? 1 : 0;
  13.     IE4 = navigator.appVersion.indexOf("MSIE 5") == -1;
  14.     zmax = 999;
  15.     __INIT=true;
  16.     document.onmouseup = null;
  17.     document.onmousedown = null;
  18.     document.onmousemove = null;
  19.   }
  20.   this.obj = getObject(src);
  21.   if (NS) {
  22.     this.x = this.obj.left;
  23.     this.y = this.obj.top;
  24.     this.w = this.obj.clip.width;
  25.     this.h = this.obj.clip.height;
  26.     this.z = this.obj.zIndex;
  27.   }
  28.   if (IE) {
  29.     this.x = this.obj.offsetLeft;
  30.     this.y = this.obj.offsetTop;
  31.     this.w = this.obj.offsetWidth;
  32.     this.h = this.obj.offsetHeight;   
  33.     this.z = this.obj.style.zIndex;
  34.   }
  35.   this.id = this.obj.id;
  36.   this.moveTo = SimpleLayerMoveTo;
  37.   this.moveBy = SimpleLayerMoveBy;
  38.   this.resize = SimpleLayerResize;
  39.   this.clip = SimpleLayerClip;
  40.   this.isVisible = SimpleLayerIsVisible;
  41.   this.show = SimpleLayerShow;
  42.   this.hide = SimpleLayerHide;
  43.   this.bringTo = SimpleLayerBringTo;
  44.   this.bringToFront = SimpleLayerBringToFront;
  45.   this.bringToBack = SimpleLayerBringToBack;
  46.   this.slideTo = SimpleLayerSlideTo;
  47.   this.growTo = SimpleLayerGrowTo;
  48.   this.load = SimpleLayerLoad;
  49.   this.onMouseDown = SimpleLayerOnMouseDown;
  50.   this.onMouseUp = SimpleLayerOnMouseUp;
  51.   this.onMouseMove = SimpleLayerOnMouseMove;
  52.   this.onMouseOver = SimpleLayerOnMouseOver;
  53.   this.onMouseOut = SimpleLayerOnMouseOut;
  54.   this.path=src;
  55.   this.timeout=null;
  56.   this.iframe=null;
  57.   this.afterSlide = null;
  58.   this.clip(0,this.w,0,this.h);
  59. }
  60. function SimpleLayerMoveTo(x,y) {
  61.   this.x=x; this.y=y;
  62.   if (NS) { this.obj.left = x; this.obj.top = y; }
  63.   else { this.obj.style.pixelLeft = x; this.obj.style.pixelTop = y; }
  64. }
  65. function SimpleLayerMoveBy(x,y) {
  66.   this.moveTo(this.x+x,this.y+y);
  67. }
  68. function SimpleLayerResize(w,h) {
  69.   this.w=w; this.h=h;
  70.   this.clip(0,w,0,h);
  71.   if (NS) { this.obj.clip.width = w; this.obj.clip.height = h; }
  72.   else { this.obj.style.pixelWidth = w; this.obj.style.pixelHeight = h; }
  73. }
  74. function SimpleLayerClip(l,r,t,b) {
  75.   if (NS) { 
  76.       this.obj.clip.left=l;
  77.       this.obj.clip.right=r;
  78.       this.obj.clip.top=t;
  79.       this.obj.clip.bottom=b;
  80.   }
  81.   else this.obj.style.clip = "rect("+t+"px, "+r+"px, "+b+"px, "+l+"px)";
  82. }
  83. function SimpleLayerIsVisible() {
  84.   return NS ? this.obj.visibility == "show": this.obj.style.visibility == "visible";
  85. }
  86. function SimpleLayerShow() {
  87.   NS ? this.obj.visibility = "show" : this.obj.style.visibility = "visible";
  88. }
  89. function SimpleLayerHide() {
  90.   NS ? this.obj.visibility = "hide" : this.obj.style.visibility = "hidden";
  91. }
  92. function SimpleLayerBringTo(i) {
  93.   NS ? this.obj.zIndex=i : this.obj.style.zIndex=i;
  94. }
  95. function SimpleLayerBringToFront() {
  96.   this.bringTo(zmax++);
  97. }
  98. function SimpleLayerBringToBack() {
  99.   this.bringTo(1);
  100. }
  101. function SimpleLayerSlideTo(dx, dy, speed, dec, owner) {
  102.   if (__registered_Slide[this.id] == null) __registered_Slide[this.id] = this;
  103.   
  104.   var ddx = (dx > -speed && dx < speed)  ? dx : Math.floor(dx/speed);
  105.   var ddy = (dy > -speed && dy < speed)  ? dy : Math.floor(dy/speed);
  106.   var obj = owner ? __registered_Slide[owner] : this;
  107.   if (!dec) dec=0.5; // 0 to 1
  108.   obj.moveBy(ddx,-ddy);
  109.   dx -= ddx; dy -= ddy; speed-=1-dec;
  110.   if (dx || dy) obj.timeout = setTimeout("SimpleLayerSlideTo("+dx+","+dy+","+speed+","+dec+",'"+obj.id+"')",100); 
  111.   else {
  112.     __registered_Slide[owner ? owner : this.id] = null;
  113.     obj.timeout=null;
  114.     if (obj.afterSlide!=null) obj.afterSlide();
  115.   }
  116. }
  117. function SimpleLayerGrowTo(dw, dh, speed, dec, owner) {
  118.   if (__registered_Grow[this.id] == null) __registered_Grow[this.id] = this;
  119.   
  120.   var ddw = (dw > -speed && dw < speed)  ? dw : Math.floor(dw/speed);
  121.   var ddh = (dh > -speed && dh < speed)  ? dh : Math.floor(dh/speed);
  122.   var obj = owner ? __registered_Grow[owner] : this;
  123.   if (!dec) dec=0.5; // 0 to 1
  124.   obj.resize(obj.w+ddw, obj.h+ddh);
  125.   dw -= ddw; dh -= ddh; speed-=1-dec;
  126.   if (dw || dh) obj.timeout = setTimeout("SimpleLayerGrowTo("+dw+","+dh+","+speed+","+dec+",'"+obj.id+"')",100); 
  127.   else {
  128.     __registered_Grow[owner ? owner : this.id] = null;
  129.     obj.timeout=null;
  130.     // if (obj.afterSlide!=null) obj.afterSlide();
  131.   }
  132. }
  133. function SimpleLayerLoad(url) {
  134.   if (NS) this.obj.load(url,this.w);
  135.   else {
  136.       if (!this.iframe) {
  137.         this.obj.innerHTML = '<div id=SOURCE style="visibility:hidden"><IFRAME name=IF_' + this.id + ' style="height:0px; width:0px; visibility:hidden"></IFRAME></div><div id=DATA></div>';
  138.       this.iframe = this.obj.all("SOURCE").all("IF_" + this.id);
  139.     }
  140.     this.iframe.src=url;
  141.     __registered_Loading["IF_" + this.id] = this;
  142.   }
  143. }
  144. function SimpleLayerLoaded(name) {
  145.   if (NS) return;
  146.   for (var i=document.frames.length-1; i>=0; i--)
  147.   {
  148.       if (document.frames(i).loaded == 1) {
  149.         var fname = document.frames(i).name;
  150.         var t = document.frames(fname).document.body.innerHTML;
  151.         var t_obj = __registered_Loading[fname];
  152.         if (t_obj) t_obj.obj.all("DATA").innerHTML = t;
  153.         __registered_Loading[fname] = null;
  154.       }
  155.   }
  156. }
  157. function SimpleLayerOnMouseDown(handler) {
  158.   if (NS) { 
  159.     if (handler) this.obj.captureEvents(Event.MOUSEDOWN); else this.obj.releaseEvents(Event.MOUSEDOWN);
  160.   }
  161.   this.obj.onmousedown = handler;
  162. }
  163. function SimpleLayerOnMouseUp(handler) {
  164.   if (NS) { 
  165.     if (handler) this.obj.captureEvents(Event.MOUSEUP); else this.obj.releaseEvents(Event.MOUSEUP);
  166.   }
  167.   this.obj.onmouseup = handler;
  168. }
  169. function SimpleLayerOnMouseMove(handler) {
  170.   if (NS) { 
  171.     if (handler) this.obj.captureEvents(Event.MOUSEMOVE); else this.obj.releaseEvents(Event.MOUSEMOVE);
  172.   }
  173.   this.obj.onmousemove = handler;
  174. }
  175. function SimpleLayerOnMouseOver(handler) {
  176.   this.obj.onmouseover = handler;
  177. }
  178. function SimpleLayerOnMouseOut(handler) {
  179.   this.obj.onmouseout = handler;
  180. }
  181. function getObject(name) {
  182.   var obj;
  183.   var names = name.split(".");
  184.   for (var i=0; i<names.length; i++) {
  185.     if (!i) obj = NS ? "document.layers['" + names[i] + "']" : "document.all['" + names[i] + "']";
  186.     else obj += (NS ? ".document." : ".all.") + names[i];
  187.   }
  188.   return eval(obj);
  189. }
  190. function getParent(name) {
  191.   var obj=null;
  192.   var names = name.split(".");
  193.   for (var i=0; i<names.length-1; i++) {
  194.     if (!i) obj = NS ? "document.layers['" + names[i] + "']" : "document.all['" + names[i] + "']";
  195.     else obj += (NS ? ".document." : ".all.") + names[i];
  196.   }
  197.   if (!obj) return null;
  198.   return eval(obj);
  199. }
  200. function findObject(obj, arr) {
  201.   var rslt = null;
  202.   for (var i=arr.length-1; i>=0; i--)
  203.     if (obj == arr[i].obj) { rslt=arr[i]; break; }
  204.   return rslt;  
  205. }
  206.