home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 July / PCpro_2004_07.ISO / docs / amset / printer-friendly.cfm_files / thing_004.js < prev    next >
Encoding:
Text File  |  2003-12-21  |  5.7 KB  |  202 lines

  1. use( "thing.point" );
  2. if( is.ns4 ) use( "thing.resize" );
  3. init( "Thing.init()" );
  4.  
  5. /********************************************************************************
  6.  
  7.     Thing Object
  8.  
  9.     Initialization
  10.         Thing.init()                  -- looks through document & gets all divs ending in "Div"
  11.                                          adds that to the Thing.all array without the "Div"
  12.     Member Variables
  13.         myThing.name                   -- "myThing"
  14.         myThing.id                     -- "myThingDiv"
  15.         myThing.div                    -- the actual html object
  16.         myThing.style                  -- the style of the object
  17.         myThing.position               -- a Point with the thing's position
  18.         myThing.size                   -- a Point with the thing's size
  19.  
  20. ********************************************************************************/
  21.     function Thing( div ){
  22.         this.id = div.id;
  23.         this.name = div.id.replace(/Div/, "");
  24.  
  25.         this.div = div;
  26.         this.style = ( is.ns4 ) ? this.div : this.div.style;
  27.  
  28.         this.position = this.getPosition();
  29.         this.size = this.getSize();
  30.     }
  31.     
  32.     Thing.add = function( div ){
  33.         var name = div.id.slice(0, -3);
  34.         if( div.id == name + "Div" ){
  35.         
  36.             //alert(name);
  37.             
  38.             Thing.all[ name ] = new Thing( div );
  39.             eval( name + " = Thing.all." + name );
  40.         }
  41.     }
  42.     Thing.all = new Array();
  43.     Thing.init = function( doc ){
  44.         this.isLoaded = true;
  45.         if( document.layers ){
  46.             if( doc == null ) doc = document;
  47.             for( var i=0; i<doc.layers.length; i++ ){
  48.                 Thing.add( doc.layers[i] );
  49.                 Thing.init( doc.layers[i].document );
  50.             }
  51.             return true;
  52.         } 
  53.         
  54.         var allD = false;
  55.         if( is.ie4 ) allD = document.all.tags("DIV");
  56.         else if( is.ie5 || is.ie6 ) allD = document.getElementsByTagName("DIV");
  57.         else if( is.ns6 ) allD = document.getElementsByTagName("DIV");
  58.         
  59.         if( allD ){
  60.             for( var i=0; i<allD.length; i++ )
  61.                 Thing.add( allD[i] );
  62.             return true;
  63.         }
  64.         return false;
  65.     }
  66.  
  67. /********************************************************************************
  68.  
  69.     Style Initialization
  70.  
  71.         Point      myThing.getPosition();   -- set this.position and return it
  72.         Point      myThing.getSize();       -- set this.size and return it
  73.         
  74. ********************************************************************************/
  75. if( is.ns4 ) 
  76.     Thing.prototype.getPosition = function(){
  77.         this.position = new Point(
  78.             parseInt(this.style.left),
  79.             parseInt(this.style.top)
  80.         );
  81.         return this.position;
  82.     }
  83. else
  84.     Thing.prototype.getPosition = function(){
  85.         this.position = new Point(
  86.             parseInt(this.div.offsetLeft),
  87.             parseInt(this.div.offsetTop)
  88.         );
  89.         return this.position;
  90.     }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.     
  97. if( is.ns4 )
  98.     Thing.prototype.getSize = function(){
  99.         this.size = new Point(
  100.             this.div.document.width,
  101.             this.div.document.height 
  102.         );
  103.         return this.size;
  104.     }
  105. else if( is.ie4 )
  106.     Thing.prototype.getSize = function(){
  107.         this.size = new Point(
  108.             parseInt( this.div.scrollWidth ), 
  109.             parseInt( this.div.scrollHeight )
  110.         );
  111.         return this.size;
  112.     }
  113. else
  114.     Thing.prototype.getSize = function(){
  115.         this.size = new Point(
  116.             parseInt(this.div.offsetWidth),
  117.             parseInt(this.div.offsetHeight)
  118.         );
  119.         this.style.offsetWidth = this.size.x;
  120.         this.style.offsetHeight = this.size.y;
  121.         return this.size;
  122.     }
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. /********************************************************************************
  130.  
  131.     Position Manipulation
  132.     
  133.         myThing.setPosition()          -- updates the html object to match the position
  134.                                           called by moveTo, moveBy, etc
  135.         myThing.moveTo(p)              -- move to point
  136.         myThing.moveTo(x,y)            -- move to specified location
  137.         myThing.moveBy(p)              -- move by point values
  138.         myThing.moveBy(x,y)            -- move by specified increments
  139.  
  140. ********************************************************************************/
  141.     Thing.prototype.setPosition = function(){
  142.         this.style.left = this.position.x;
  143.         this.style.top = this.position.y;
  144.     }
  145.     Thing.prototype.moveTo = function( /*x,y or p*/ ){
  146.         this.position = new Point( arguments[0], arguments[1] );
  147.         this.setPosition();
  148.     }
  149.     Thing.prototype.moveBy = function( /*x,y or p*/ ){
  150.         this.position = this.position.add( arguments[0], arguments[1] );
  151.         this.setPosition();
  152.     }
  153.  
  154. /********************************************************************************
  155.  
  156.     Visibility Manipulation
  157.     
  158.         myThing.show()                 -- show the div
  159.         myThing.hide()                 -- hide the div
  160.         myThing.isVisible()            -- return true if visible, false if not
  161.         myThing.toggle()               -- hide if visible, show if not
  162.         
  163. ********************************************************************************/
  164.  
  165.     Thing.prototype.show = function(){
  166.         this.style.visibility = "visible";
  167.     }
  168.     Thing.prototype.hide = function(){
  169.         this.style.visibility = "hidden";
  170.     }
  171.     Thing.prototype.isVisible = function(){
  172.         return ( this.style.visibility.indexOf("d") == -1 );
  173.     }
  174.     Thing.prototype.toggle = function(){
  175.         return ( this.isVisible() ) ? this.hide() : this.show();
  176.     }
  177.  
  178.     
  179.     
  180. /********************************************************************************
  181.  
  182.     Miscellaneous Manipulation
  183.     
  184.         myThing.setBackground( color ) -- set the bgcolor to "color"        
  185.  
  186.         myThing.getZindex()            -- get the zIndex
  187.         myThing.setZindex( n )         -- set the zIndex to n
  188.  
  189. ********************************************************************************/
  190. if ( is.ns4 )
  191.     Thing.prototype.setBackground = function( color ){
  192.         this.div.document.bgColor=color;
  193.     }
  194. else
  195.     Thing.prototype.setBackground = function( color ){
  196.         this.style.backgroundColor = color;
  197.     }
  198.     
  199.     Thing.prototype.setZindex = function( n ){
  200.         this.style.zIndex = n;
  201.     }
  202.