home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Joystick Magazine 2003 November
/
CD1_JOY_153.iso
/
demos
/
NHL2004Demo.exe
/
fe
/
nhl
/
htc
/
button
/
DynamicButton.htc
< prev
next >
Wrap
Text File
|
2003-08-20
|
7KB
|
233 lines
<!-- Copyright (c) 2002 Electronic Arts Inc. All rights reserved. -->
<PUBLIC:COMPONENT>
<PUBLIC:PROPERTY NAME="imgPath" />
<PUBLIC:PROPERTY NAME="leftImg" />
<PUBLIC:PROPERTY NAME="centerImg" />
<PUBLIC:PROPERTY NAME="rightImg" />
<PUBLIC:PROPERTY NAME="caption" />
<PUBLIC:PROPERTY NAME="defaultWidth" />
<ATTACH EVENT="ondocumentready" HANDLER="doInit" />
<ATTACH EVENT="onmousedown" HANDLER="doMouseDown" />
<ATTACH EVENT="onmouseenter" HANDLER="doMouseEnter" />
<ATTACH EVENT="onmouseleave" HANDLER="doMouseLeave" />
<ATTACH EVENT="onmouseup" HANDLER="doMouseUp" />
<ATTACH EVENT="onselectstart" HANDLER="cancelCursorSelect" />
<PUBLIC:METHOD NAME="setText" />
<script language="javascript">
var aButton = new Array();
var strImgPath, strLeftImg, strCenterImg, strRightImg, strText, nWidth, nHeight, nLeftPos;
var oBtnText, oLeftImg, oCenterImg, oRightImg, nDefaultWidth;
function doInit()
{
strImgPath = (imgPath != null) ? GetInstallFolder() + imgPath : GetInstallFolder() + "fe/NHL/images/button/";
strLeftImg = (leftImg != null) ? leftImg : "butt00_nml.gif";
strCenterImg = (centerImg != null) ? centerImg : "butt01_nml.gif";
strRightImg = (rightImg != null) ? rightImg : "butt02_nml.gif";
strText = (caption !=null) ? caption : "";
nDefaultWidth = (defaultWidth!=null) ? parseInt(defaultWidth) : null;
setDefaults();
createButton();
}
function createButton()
{
createLeftImg();
createText();
createCenterImg();
createRightImg();
}
function createLeftImg()
{
var oImg = element.document.createElement("IMG");
oImg.id = element.id + "_leftImg";
oImg.src = strImgPath + strLeftImg;
aButton[ "left-normal" ] = oImg.src;
aButton[ "left-hover" ] = aButton[ "left-normal" ].toString().replace( /nml/ , 'hov');
aButton[ "left-down" ] = aButton[ "left-normal" ].toString().replace( /nml/ , 'dwn');
with(oImg.style)
{
position = 'absolute';
top = '0px';//currentStyle.top;
left = '0px';//currentStyle.left;
}
element.appendChild(oImg);
oLeftImg = oImg;
nLeftPos = oImg.clientWidth// + element.style.pixelLeft;
nHeight = oImg.clientHeight;
}
function createRightImg()
{
var oImg = element.document.createElement("IMG");
oImg.id = element.id + "_rightImg";
oImg.src = strImgPath + strRightImg;
aButton[ "right-normal" ] = oImg.src;
aButton[ "right-hover" ] = aButton[ "right-normal" ].toString().replace( /nml/ , 'hov');
aButton[ "right-down" ] = aButton[ "right-normal" ].toString().replace( /nml/ , 'dwn');
with(oImg.style)
{
position = 'absolute';
top = '0px';//currentStyle.top;
left = (nDefaultWidth !=null) ? nLeftPos + nDefaultWidth : nLeftPos + nWidth;
}
element.appendChild(oImg);
oRightImg = oImg;
}
function createText()
{
var oSpan = element.document.createElement("SPAN");
oSpan.id = element.id + "_text";
oSpan.innerText = strText;
element.appendChild(oSpan);
with(oSpan.style)
{
position = "absolute";
fontFamily = currentStyle.fontFamily;
color = currentStyle.nmlTextColor;
fontSize = currentStyle.fontSize;
fontStyle = currentStyle.fontStyle;
fontWeight = currentStyle.fontWeight;
overflowY = "hidden";
overflowX = "hidden";
top = '0px';//currentStyle.top;
left = String(nLeftPos) + 'px';
width = (nDefaultWidth !=null) ? String(nDefaultWidth) + 'px' : String(oSpan.clientWidth + 10) + 'px';
textAlign = 'center';
verticalAlign = 'middle';
zIndex = 10;
paddingLeft = "5px";
paddingRight = "5px";
}
//.oSpan.style.top = String(element.style.pixelTop +(nHeight/2 - oSpan.clientHeight/2)-1) + 'px';
oBtnText = oSpan;
nWidth = oSpan.clientWidth;
}
function createCenterImg()
{
var oImg = element.document.createElement("Img");
oImg.src = strImgPath + strCenterImg;
oImg.id = element.id + "_center";
aButton[ "center-normal" ] = oImg.src;
aButton[ "center-hover" ] = aButton[ "center-normal" ].toString().replace( /nml/ , 'hov' );
aButton[ "center-down" ] = aButton[ "center-normal" ].toString().replace( /nml/ , 'dwn' );
with(oImg.style)
{
position = 'absolute';
top = "0px";//currentStyle.top;
left = String(nLeftPos) + 'px';
width = (nDefaultWidth !=null) ? nDefaultWidth : nWidth;
height = nHeight;
}
element.appendChild(oImg);
oCenterImg = oImg;
}
function setDefaults()
{
NormalDefault("fontFamily", "Times New Roman", "Verdana");
NormalDefault("fontSize", "12pt", "10pt");
NormalDefault("fontStyle", "normal", "normal");
NormalDefault("fontWeight", "400", "bolder");
NormalDefault("cursor", "auto", "hand");
NormalDefault("position", "absolute", "absolute");
NormalDefault("left", "0px", "0px");
NormalDefault("top", "0px", "0px");
CustomDefault('nml-text-color', 'nmlTextColor', 'white');
CustomDefault('dwn-text-color', 'dwnTextColor', 'white');
CustomDefault('hov-text-color', 'hovTextColor', 'black');
}
function NormalDefault(sCSSName, sIEDefault, sDefault)
{
if (currentStyle[sCSSName] == sIEDefault
&& (style[sCSSName] == "" || style[sCSSName] == null))
{
style[sCSSName] = sDefault;
}
else style[sCSSName] = currentStyle[sCSSName];
}
function CustomDefault(sCSSName, sScriptName, sDefault)
{
if (currentStyle[sCSSName] == null)
{
style[sCSSName] = sDefault;
}
else style[sCSSName] = currentStyle[sCSSName];
style[sScriptName] = style[sCSSName];
}
function doMouseEnter()
{
doHover();
}
function doMouseLeave()
{
doNormal();
}
function doMouseDown()
{
doDown();
}
function doMouseUp()
{
doHover();
}
function setText( strText )
{
btnText = element.document.all[ srcEl.id + "_text" ];
btnText.innerText = strText;
}
function doHover()
{
oLeftImg.src = aButton[ "left-hover" ];
oCenterImg.src = aButton[ "center-hover" ];
oRightImg.src = aButton[ "right-hover" ];
oBtnText.style.color = element.currentStyle.hovTextColor;
event.cancelBubble = true;
event.returnValue = false;
}
function doNormal()
{
oLeftImg.src = aButton[ "left-normal" ];
oCenterImg.src = aButton[ "center-normal" ];
oRightImg.src = aButton[ "right-normal" ];
oBtnText.style.color = element.currentStyle.nmlTextColor;
event.cancelBubble = true;
event.returnValue = false;
}
function doDown()
{
oLeftImg.src = aButton[ "left-down" ];
oCenterImg.src = aButton[ "center-down" ];
oRightImg.src = aButton[ "right-down" ];
oBtnText.style.color = element.currentStyle.dwnTextColor;
event.cancelBubble = true;
event.returnValue = false;
}
function cancelCursorSelect()
{
event.cancelBubble = true;
event.returnValue = false;
}
</script>
</PUBLIC:COMPONENT>