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

  1. <!-- Copyright (c) 2002 Electronic Arts Inc. All rights reserved. -->
  2.  
  3. <PUBLIC:COMPONENT>
  4.     <PUBLIC:PROPERTY    NAME="imgPath"            />
  5.     <PUBLIC:PROPERTY    NAME="leftImg"            />    
  6.     <PUBLIC:PROPERTY    NAME="centerImg"        />    
  7.     <PUBLIC:PROPERTY    NAME="rightImg"            />    
  8.     <PUBLIC:PROPERTY    NAME="caption"            />    
  9.     <PUBLIC:PROPERTY    NAME="defaultWidth"        />    
  10.     <ATTACH   EVENT="ondocumentready"     HANDLER="doInit"        />
  11.     <ATTACH   EVENT="onmousedown"       HANDLER="doMouseDown"   />
  12.     <ATTACH   EVENT="onmouseenter"      HANDLER="doMouseEnter"  />
  13.     <ATTACH   EVENT="onmouseleave"      HANDLER="doMouseLeave"  />
  14.     <ATTACH   EVENT="onmouseup"         HANDLER="doMouseUp"     />
  15.     <ATTACH      EVENT="onselectstart"        HANDLER="cancelCursorSelect"    />    
  16.     <PUBLIC:METHOD    NAME="setText"                />        
  17.     
  18.     <script language="javascript">
  19.     var aButton         = new Array();
  20.     var strImgPath, strLeftImg, strCenterImg, strRightImg, strText, nWidth, nHeight, nLeftPos;
  21.     var oBtnText, oLeftImg, oCenterImg, oRightImg, nDefaultWidth;
  22.     
  23.     function doInit()
  24.     {
  25.         strImgPath      = (imgPath != null)     ? GetInstallFolder() + imgPath : GetInstallFolder() + "fe/NHL/images/button/";
  26.         strLeftImg      = (leftImg != null)     ? leftImg : "butt00_nml.gif";
  27.         strCenterImg      = (centerImg != null)     ? centerImg : "butt01_nml.gif";        
  28.         strRightImg      = (rightImg != null)     ? rightImg : "butt02_nml.gif";        
  29.         strText               = (caption !=null)         ? caption : "";
  30.         nDefaultWidth    = (defaultWidth!=null)    ? parseInt(defaultWidth) : null;
  31.         setDefaults();
  32.         createButton();
  33.     }
  34.  
  35.     function createButton()
  36.     {
  37.         createLeftImg();        
  38.         createText();
  39.         createCenterImg();
  40.         createRightImg();
  41.     }
  42.     
  43.     function createLeftImg()
  44.     {
  45.         var oImg = element.document.createElement("IMG");
  46.         oImg.id                          = element.id + "_leftImg";
  47.         oImg.src                      = strImgPath + strLeftImg;
  48.         aButton[ "left-normal" ]     = oImg.src;
  49.         aButton[ "left-hover" ]      = aButton[ "left-normal" ].toString().replace( /nml/ , 'hov');
  50.         aButton[ "left-down" ]      = aButton[ "left-normal" ].toString().replace( /nml/ , 'dwn');        
  51.         with(oImg.style)
  52.         {
  53.             position         =         'absolute';
  54.             top                =        '0px';//currentStyle.top;
  55.             left            =        '0px';//currentStyle.left;
  56.         }
  57.         element.appendChild(oImg);
  58.         oLeftImg     = oImg;
  59.         nLeftPos     = oImg.clientWidth// + element.style.pixelLeft;
  60.         nHeight     = oImg.clientHeight;    
  61.     }
  62.     
  63.     function createRightImg()
  64.     {
  65.         var oImg = element.document.createElement("IMG");
  66.         oImg.id                  = element.id + "_rightImg";
  67.         oImg.src              = strImgPath + strRightImg;
  68.         aButton[ "right-normal" ]     = oImg.src;
  69.         aButton[ "right-hover" ]      = aButton[ "right-normal" ].toString().replace( /nml/ , 'hov');
  70.         aButton[ "right-down" ]      = aButton[ "right-normal" ].toString().replace( /nml/ , 'dwn');            
  71.         with(oImg.style)
  72.         {
  73.             position         =         'absolute';
  74.             top                =        '0px';//currentStyle.top;
  75.             left            =        (nDefaultWidth !=null) ? nLeftPos + nDefaultWidth : nLeftPos + nWidth;    
  76.         }
  77.         element.appendChild(oImg);
  78.         oRightImg = oImg;
  79.     }
  80.     
  81.     function createText()
  82.     {
  83.         var oSpan              = element.document.createElement("SPAN");
  84.         oSpan.id              = element.id + "_text";
  85.         oSpan.innerText          =    strText;
  86.         element.appendChild(oSpan);
  87.  
  88.         with(oSpan.style)
  89.         {            
  90.             position         =         "absolute";
  91.             fontFamily        =       currentStyle.fontFamily;
  92.             color           =       currentStyle.nmlTextColor;
  93.             fontSize           =       currentStyle.fontSize;
  94.             fontStyle          =       currentStyle.fontStyle;
  95.             fontWeight         =       currentStyle.fontWeight;            
  96.             overflowY        =         "hidden";
  97.             overflowX        =         "hidden";            
  98.             top                =        '0px';//currentStyle.top;
  99.             left            =        String(nLeftPos) + 'px';            
  100.             width            =       (nDefaultWidth !=null) ? String(nDefaultWidth) + 'px' : String(oSpan.clientWidth + 10) + 'px';    
  101.             textAlign         =         'center';
  102.             verticalAlign    =        'middle';
  103.             zIndex            =        10;
  104.             paddingLeft        =         "5px";
  105.             paddingRight    =         "5px";
  106.         }
  107.         //.oSpan.style.top = String(element.style.pixelTop +(nHeight/2 - oSpan.clientHeight/2)-1) + 'px';
  108.         oBtnText       = oSpan;
  109.         nWidth         = oSpan.clientWidth;
  110.     }
  111.  
  112.     function createCenterImg()
  113.     {
  114.         var oImg              = element.document.createElement("Img");
  115.         oImg.src              = strImgPath + strCenterImg;
  116.         oImg.id               = element.id + "_center";
  117.         aButton[ "center-normal" ]  = oImg.src;
  118.         aButton[ "center-hover" ]     = aButton[ "center-normal" ].toString().replace( /nml/ , 'hov' );
  119.         aButton[ "center-down" ]      = aButton[ "center-normal" ].toString().replace( /nml/ , 'dwn' );
  120.         with(oImg.style)
  121.         {
  122.             position         =         'absolute';
  123.             top                =        "0px";//currentStyle.top;
  124.             left            =        String(nLeftPos) + 'px';
  125.             width            =        (nDefaultWidth !=null) ? nDefaultWidth : nWidth;
  126.             height            =       nHeight;
  127.         }    
  128.         element.appendChild(oImg);
  129.         oCenterImg = oImg;
  130.     }    
  131.     function setDefaults() 
  132.     {
  133.         NormalDefault("fontFamily",        "Times New Roman",    "Verdana");
  134.         NormalDefault("fontSize",         "12pt",                "10pt");
  135.         NormalDefault("fontStyle",         "normal",            "normal");        
  136.         NormalDefault("fontWeight",     "400",                "bolder");
  137.         NormalDefault("cursor",            "auto",                "hand");
  138.         NormalDefault("position",        "absolute",            "absolute");            
  139.         NormalDefault("left",            "0px",                "0px");        
  140.         NormalDefault("top",            "0px",                "0px");            
  141.                 
  142.         CustomDefault('nml-text-color',    'nmlTextColor',    'white');
  143.         CustomDefault('dwn-text-color',    'dwnTextColor',    'white');
  144.         CustomDefault('hov-text-color',    'hovTextColor',    'black');        
  145.     }    
  146.     
  147.     function NormalDefault(sCSSName, sIEDefault, sDefault)
  148.     {
  149.        if (currentStyle[sCSSName] == sIEDefault 
  150.            && (style[sCSSName] == "" || style[sCSSName] == null))
  151.        {
  152.            style[sCSSName] = sDefault;
  153.        }
  154.        else style[sCSSName] = currentStyle[sCSSName];
  155.     }        
  156.     
  157.     function CustomDefault(sCSSName, sScriptName, sDefault)
  158.     {
  159.        if (currentStyle[sCSSName] == null)
  160.        {
  161.            style[sCSSName] = sDefault;
  162.        }
  163.        else style[sCSSName] = currentStyle[sCSSName];
  164.        
  165.        style[sScriptName] = style[sCSSName];
  166.     }
  167.  
  168.     
  169.     function doMouseEnter()
  170.     {
  171.         doHover();
  172.     }
  173.     
  174.     function doMouseLeave()
  175.     {
  176.         doNormal();
  177.     }
  178.     
  179.     
  180.     function doMouseDown()
  181.     {
  182.         doDown();
  183.     }
  184.     
  185.     function doMouseUp()
  186.     {  
  187.         doHover();
  188.     }
  189.  
  190.     function setText( strText ) 
  191.     {
  192.         btnText                = element.document.all[ srcEl.id + "_text" ];
  193.         btnText.innerText     = strText;
  194.     }    
  195.     
  196.     function doHover()
  197.     {
  198.         oLeftImg.src                              = aButton[ "left-hover" ];
  199.         oCenterImg.src                            = aButton[ "center-hover" ];
  200.         oRightImg.src                            = aButton[ "right-hover" ];    
  201.         oBtnText.style.color                     = element.currentStyle.hovTextColor;
  202.         event.cancelBubble  = true;
  203.         event.returnValue   = false;
  204.     }
  205.     
  206.     function doNormal()
  207.     {
  208.         oLeftImg.src                          = aButton[ "left-normal" ];
  209.         oCenterImg.src                         = aButton[ "center-normal" ];
  210.         oRightImg.src                        = aButton[ "right-normal" ];    
  211.         oBtnText.style.color                 = element.currentStyle.nmlTextColor;        
  212.         event.cancelBubble  = true;
  213.         event.returnValue   = false;             
  214.     }
  215.     
  216.     function doDown()
  217.     {
  218.         oLeftImg.src                          = aButton[ "left-down" ];
  219.         oCenterImg.src                        = aButton[ "center-down" ];
  220.         oRightImg.src                        = aButton[ "right-down" ];        
  221.         oBtnText.style.color                 = element.currentStyle.dwnTextColor;
  222.         event.cancelBubble  = true;
  223.         event.returnValue   = false;        
  224.     }
  225.     
  226.     function cancelCursorSelect() 
  227.     { 
  228.         event.cancelBubble  = true;
  229.         event.returnValue   = false;
  230.     }
  231.     </script>
  232.  
  233. </PUBLIC:COMPONENT>