home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2003 October / cmycha200310.iso / NHL2004 / NHL2004Demo.exe / fe / nhl / htc / button / Button.htc next >
Text File  |  2003-08-20  |  5KB  |  179 lines

  1. <!-- Copyright (c) 2002 Electronic Arts Inc. All rights reserved. -->
  2.  
  3. <PUBLIC:COMPONENT>
  4.     <PUBLIC:PROPERTY    NAME="imgSrc"            />
  5.     <PUBLIC:PROPERTY    NAME="text"                />    
  6.     <ATTACH   EVENT="ondocumentready"     HANDLER="doInit"        />
  7.     <ATTACH   EVENT="onmousedown"       HANDLER="doMouseDown"   />
  8.     <ATTACH   EVENT="onmouseenter"      HANDLER="doMouseEnter"  />
  9.     <ATTACH   EVENT="onmouseleave"      HANDLER="doMouseLeave"  />
  10.     <ATTACH   EVENT="onmouseup"         HANDLER="doMouseUp"     />
  11.     <ATTACH      EVENT="onselectstart"        HANDLER="cancelCursorSelect"    />    
  12.     <PUBLIC:METHOD    NAME="setText"                />        
  13.  
  14.     <script language="javascript">
  15.     var aButton         = new Array();
  16.     var strImgSrc, strImgPath, strImgName, strText;
  17.     
  18.     function doInit()
  19.     {
  20.         strImgSrc  = (imgSrc != null) ? imgSrc : "../../NHL/images/button/controller_config_nml.gif";
  21.         strImgName = strImgSrc.split('/');
  22.         strImgName.reverse();
  23.         strImgName = strImgName[0];
  24.         strImgPath = strImgSrc.substr(0, strImgSrc.length - strImgName.length);
  25.         strText       = (text !=null) ? text : "";    
  26.         createImg( "normal"  , strImgName );
  27.         createImg( "hover"   , strImgName.replace(/nml/ , "hov" ));
  28.         createImg( "down"    , strImgName.replace(/nml/ , "dwn"));
  29.         setDefaults();
  30.         createButton();            
  31. //        defaults.viewLink = document;        
  32.     }
  33.     
  34.     function setDefaults() 
  35.     {
  36.         NormalDefault("fontFamily",        "Times New Roman",    "Arial");
  37.         NormalDefault("fontSize",         "12pt",                "10pt");
  38.         NormalDefault("fontStyle",         "normal",            "italic");        
  39.         NormalDefault("fontWeight",     "400",                "800");
  40.         NormalDefault("color",             "black",            "black");
  41.         NormalDefault("cursor",            "auto",                "hand");
  42.         NormalDefault("left",            "0px",                "0px");                
  43.         NormalDefault("top",            "0px",                "0px");            
  44.                 
  45.         CustomDefault('nml-text-color',    'nmlTextColor',    'black');
  46.         CustomDefault('dwn-text-color',    'dwnTextColor',    'white');
  47.         CustomDefault('hov-text-color',    'hovTextColor',    'white');        
  48.     }    
  49.     
  50.     function NormalDefault(sCSSName, sIEDefault, sDefault)
  51.     {
  52.        if (currentStyle[sCSSName] == sIEDefault 
  53.            && (style[sCSSName] == "" || style[sCSSName] == null))
  54.        {
  55.            style[sCSSName] = sDefault;
  56.        }
  57.        else style[sCSSName] = currentStyle[sCSSName];
  58.     }        
  59.     
  60.     function CustomDefault(sCSSName, sScriptName, sDefault)
  61.     {
  62.        if (currentStyle[sCSSName] == null)
  63.        {
  64.            style[sCSSName] = sDefault;
  65.        }
  66.        else style[sCSSName] = currentStyle[sCSSName];
  67.        
  68.        style[sScriptName] = style[sCSSName];
  69.     }
  70.     
  71.     function createImg( sId , sImgName )
  72.     {
  73.         var oImg = new Image();
  74.         oImg.src = strImgPath + sImgName;
  75.         aButton[ sId ] = oImg;
  76.     }
  77.     
  78.     function createButton()
  79.     {
  80.         var oImg              = element.document.createElement("IMG");
  81.         oImg.id                  = element.id + "_img";
  82.         oImg.src              = strImgPath + strImgName;
  83.         with(oImg.style)
  84.         {
  85.             position         =         'absolute';
  86.             top                =        currentStyle.top;
  87.             left            =        currentStyle.left;        
  88.         }    
  89.         element.appendChild(oImg);
  90.         var oSpan              = element.document.createElement("SPAN");
  91.         oSpan.id              = element.id + "_text";
  92.         oSpan.innerText          =    strText;
  93.         with(oSpan.style)
  94.         {            
  95.             position         =         'absolute';
  96.             fontFamily        =       currentStyle.fontFamily;
  97.             color           =       currentStyle.color;
  98.             fontSize           =       currentStyle.fontSize;
  99.             fontStyle          =       currentStyle.fontStyle;
  100.             fontWeight         =       currentStyle.fontWeight;
  101.             height             =         String(oImg.clientHeight) + 'px';
  102.             width             =         String(oImg.clientWidth) + 'px';
  103.             overflowY        =         "hidden";
  104.             overflowX        =         "hidden";            
  105.             top                =        currentStyle.top;
  106.             left            =        currentStyle.left;
  107.             textAlign         =         'center';
  108.             paddingTop        =         String(oImg.clientHeight/ 5) + "px";
  109.         }
  110.  
  111.         element.appendChild(oSpan);
  112.     }
  113.     
  114.     function doMouseEnter()
  115.     {
  116.         doColorChange( 'hov' );
  117.     }
  118.     
  119.     function doMouseLeave()
  120.     {
  121.         doColorChange( 'nml' );
  122.     }
  123.     
  124.     
  125.     function doMouseDown()
  126.     {
  127.         oAudioInterface.PlaySpinnerSFX();
  128.         doColorChange( 'dwn' );
  129.     }
  130.     
  131.     function doMouseUp()
  132.     {  
  133.     
  134.         doColorChange('hov');
  135.     }
  136.  
  137.     function setText( strText ) 
  138.     {
  139.         btnText                = element.document.all[ srcEl.id + "_text" ];
  140.         btnText.innerText     = strText;
  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>