home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2003 October / cmycha200310.iso / NHL2004 / NHL2004Demo.exe / fe / nhl / htc / toggle / Toggle.htc
Text File  |  2003-08-20  |  6KB  |  179 lines

  1. <!-- Copyright (c) 2002 Electronic Arts Inc. All rights reserved. -->
  2.  
  3. <PUBLIC:COMPONENT lightweight=true>
  4.     <PUBLIC:PROPERTY    NAME="imgSrc"            />
  5.     <PUBLIC:PROPERTY    NAME="onText"            />
  6.     <PUBLIC:PROPERTY    NAME="offText"            />    
  7.     <PUBLIC:METHOD      NAME="isTrue"            />    
  8.     <PUBLIC:METHOD        NAME="setValue"            />    
  9.     <ATTACH   EVENT="ondocumentready"     HANDLER="doInit"        />
  10.     <ATTACH   EVENT="onmousedown"       HANDLER="doMouseDown"   />
  11.     <ATTACH   EVENT="onmouseup"         HANDLER="doMouseUp"     />
  12.     <ATTACH   EVENT="onmouseleave"      HANDLER="doMouseUp"  />
  13.     <ATTACH      EVENT="onselectstart"        HANDLER="cancelCursorSelect"    />    
  14.  
  15.     <script language="javascript">
  16.     var aButton         = new Array();
  17.     var strImgSrc, strImgPath, strImgName, nIsTrue, strOnText, strOffText;
  18.     
  19.     function doInit()
  20.     {
  21.         strImgSrc       = (imgSrc != null) ? imgSrc : "../../NHL/images/button/controller_config_nml.gif";
  22.         strOnText        = (onText !=null) ?  onText : "ON";    
  23.         strOffText        = (offText !=null) ?  offText : "OFF";        
  24.         nIsTrue = 0;
  25.         strImgName = strImgSrc.split('/');
  26.         strImgName.reverse();
  27.         strImgName = strImgName[0];
  28.         strImgPath = strImgSrc.substr(0, strImgSrc.length - strImgName.length);
  29.         createImg( "normal"  , strImgName );
  30.         createImg( "hover"   , strImgName.replace(/nml/ , "hov" ));
  31.         createImg( "down"    , strImgName.replace(/nml/ , "dwn"));
  32.         setDefaults();
  33.         createToggle();            
  34.     }
  35.     
  36.     function setDefaults() 
  37.     {
  38.         NormalDefault("fontFamily",        "Times New Roman",    "Arial");
  39.         NormalDefault("fontSize",         "12pt",                "10pt");
  40.         NormalDefault("fontStyle",         "normal",            "italic");        
  41.         NormalDefault("fontWeight",     "400",                "800");
  42.         NormalDefault("color",             "black",            "black");
  43.         NormalDefault("cursor",            "auto",                "hand");
  44.         NormalDefault("left",            "0px",                "0px");                
  45.         NormalDefault("top",            "0px",                "0px");            
  46.                 
  47.         CustomDefault('nml-text-color',    'nmlTextColor',    'black');
  48.         CustomDefault('dwn-text-color',    'dwnTextColor',    'white');
  49.         CustomDefault('hov-text-color',    'hovTextColor',    'white');        
  50.     }    
  51.     
  52.     function NormalDefault(sCSSName, sIEDefault, sDefault)
  53.     {
  54.        if (currentStyle[sCSSName] == sIEDefault 
  55.            && (style[sCSSName] == "" || style[sCSSName] == null))
  56.        {
  57.            style[sCSSName] = sDefault;
  58.        }
  59.        else style[sCSSName] = currentStyle[sCSSName];
  60.     }        
  61.     
  62.     function CustomDefault(sCSSName, sScriptName, sDefault)
  63.     {
  64.        if (currentStyle[sCSSName] == null)
  65.        {
  66.            style[sCSSName] = sDefault;
  67.        }
  68.        else style[sCSSName] = currentStyle[sCSSName];
  69.        
  70.        style[sScriptName] = style[sCSSName];
  71.     }
  72.     
  73.     function createImg( sId , sImgName )
  74.     {
  75.         var oImg = new Image();
  76.         oImg.src = strImgPath + sImgName;
  77.         aButton[ sId ] = oImg;
  78.     }
  79.     
  80.     function createToggle()
  81.     {
  82.         var oImg              = element.document.createElement("IMG");
  83.         oImg.id                  = element.id + "_img";
  84.         oImg.src              = strImgPath + strImgName;
  85.         with(oImg.style)
  86.         {
  87.             position         =         'absolute';
  88.             top                =        currentStyle.top;
  89.             left            =        currentStyle.left;        
  90.         }    
  91.         element.appendChild(oImg);
  92.         var oSpan              = element.document.createElement("SPAN");
  93.         oSpan.id              = element.id + "_text";
  94.         with(oSpan.style)
  95.         {            
  96.             position         =         'absolute';
  97.             fontFamily        =       currentStyle.fontFamily;
  98.             color           =       currentStyle.color;
  99.             fontSize           =       currentStyle.fontSize;
  100.             fontStyle          =       currentStyle.fontStyle;
  101.             fontWeight         =       currentStyle.fontWeight;
  102.             height             =         String(oImg.clientHeight) + 'px';
  103.             width             =         String(oImg.clientWidth) + 'px';
  104.             overflowY        =         "hidden";
  105.             overflowX        =         "hidden";            
  106.             top                =        currentStyle.top;
  107.             left            =        currentStyle.left;
  108.             textAlign         =         'center';
  109.             paddingTop        =         String(oImg.clientHeight/ 5) + "px";
  110.         }
  111.  
  112.         element.appendChild(oSpan);
  113.     }
  114.     
  115.     function doMouseDown()
  116.     {
  117.         doColorChange( 'dwn' );
  118.         nIsTrue ? setValue( 0 ) : setValue( 1 );
  119.     }
  120.  
  121.     function doMouseUp()
  122.     {  
  123.     
  124.         doColorChange('nml');
  125.     }
  126.     
  127.     function setValue( nBoolean ) 
  128.     {
  129.         btnText     =     element.document.all[ srcEl.id + "_text" ];
  130.         nBoolean ?     btnText.innerText = strOnText : btnText.innerText = strOffText;
  131.         nIsTrue = nBoolean;
  132.     }
  133.     
  134.     function isTrue()
  135.     {
  136.         var nBoolean = 0;
  137.         btnText     =     element.document.all[ srcEl.id + "_text" ];
  138.         if(btnText.innerText.match(/ON/))
  139.             nBoolean = 1;
  140.         return nBoolean;    
  141.     }
  142.     
  143.     function doColorChange( sState )
  144.     {
  145.         srcEl                             = event.srcElement;
  146.         if(srcEl.id.match(/_/)) srcEl     = srcEl.parentElement;
  147.         btnText                            = element.document.all[ srcEl.id + "_text" ];
  148.         btnImg                             = element.document.all[ srcEl.id + "_img" ];
  149.         if(btnImg != null)
  150.         {
  151.             if(sState.match(/nml/))btnImg.src  = aButton[ "normal" ].src; 
  152.                if(sState.match(/hov/))btnImg.src  = aButton[ "hover" ].src;
  153.                if(sState.match(/dwn/))btnImg.src  = aButton[ "down" ].src;        
  154.         }
  155.         switch( sState )
  156.         {
  157.             case "dwn":
  158.             if(btnText != null)
  159.                 btnText.style.color = element.currentStyle.dwnTextColor;
  160.                 break;
  161.             case "nml":
  162.             if(btnText != null)
  163.                 btnText.style.color = element.currentStyle.nmlTextColor;
  164.                 break;
  165.             case "hov":
  166.             if(btnText != null)
  167.                 btnText.style.color = element.currentStyle.hovTextColor;
  168.                 break;
  169.         }
  170.     }
  171.     
  172.     function cancelCursorSelect() 
  173.     { 
  174.         event.cancelBubble  = true;
  175.         event.returnValue   = false;
  176.     }
  177.     </script>
  178.  
  179. </PUBLIC:COMPONENT>