home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CyberMycha 2003 October
/
cmycha200310.iso
/
NHL2004
/
NHL2004Demo.exe
/
fe
/
COMMON
/
js
/
easoImage.js
< prev
next >
Wrap
Text File
|
2003-08-20
|
3KB
|
92 lines
//A nice little wrapper class for dealing with multiple image states.
//Simply construct the image passing in the src, width, and height
//Then you can set the images for each state ('over', 'down', 'disabled') via setImage
//Or you can define a name convention for all images:
//For Example if your image name is something like--btn1_nml.gif
//Then you probably have an over state for the image called btn1_hov.gif
//So call setNameConvention('_nml', '_hov');
//
function eaImage(src, width, height)
{
this.width = width;
this.height = height;
this.nml = new Image();
this.nml.src = src;
this.nml.width = width;
this.nml.height = height;
this.ovr = new Image();
this.dwn = new Image();
this.dis = new Image();
};
eaImage.prototype.getImage = function(sState)
{
switch (sState) {
case "over": return this.ovr;
case "down": return this.dwn;
case "disabled": return this.dis;
default: return this.nml;
};
sState = null;
};
eaImage.prototype.getImageSrc = function(sState)
{
return this.getImage(sState).src;
};
eaImage.prototype.setImage = function(sState, src, width, height)
{
switch(sState) {
case "over": this.ovr.width=width;this.ovr.height=height;this.ovr.src=src;break;
case "down": this.dwn.width=width;this.dwn.height=height;this.dwn.src= src;break;
case "disabled": this.dis.width=width;this.dis.height= height;this.dis.src=src;break;
default: this.nml.width=width;this.nml.height= height;this.nml.src=src;break;
};
sState = src = width = height = null;
};
eaImage.prototype.setNameConvention = function(nml, ovr, dwn, dis)
{
this.nmlExp = new RegExp(nml, "g");
this.ovr.src = this.nml.src.replace(this.nmlExp, ovr);
this.ovr.width = this.width;
this.ovr.height = this.height;
this.dwn.src = this.nml.src.replace(this.nmlExp, dwn);
this.dwn.width = this.width;
this.dwn.height = this.height;
this.dis.src = this.nml.src.replace(this.nmlExp, dis);
this.dis.width = this.width;
this.dis.height = this.height;
delete this.nmlExp;
};
eaImage.prototype.toHTMLString = function(sState, sAttrs)
{
var returnStr = "";
sAttrs = (sAttrs) ? sAttrs + "" : "";
this.tmpImg = null;
switch (sState) {
case "over": this.tmpImg = this.ovr; break;
case "down": this.tmpImg = this.dwn; break;
case "disabled": this.tmpImg = this.dis; break;
default: this.tmpImg = this.nml; break;
};
returnStr = "<img src='" + this.tmpImg.src + "' width='" + this.tmpImg.width + "' height='" + this.tmpImg.height +"' " + sAttrs + ">"
delete this.tmpImg;
return returnStr;
};
//The following two methods are static class methods for batching the params together
eaImage.createWithSrc = function(nmlSrc, nmlWidth, nmlHeight, ovrSrc, dwnSrc, disSrc)
{
var eaImage = new eaImage(nmlSrc, nmlWidth, nmlHeight);
with (eaImage) {
setImage("over", ovrSrc, nmlWidth, nmlHeight);
setImage("down", dwnSrc, nmlWidth, nmlHeight);
setImage("dis", disSrc, nmlWidth, nmlHeight);
};
return eaImage;
};
eaImage.createWithConvention = function(nmlSrc, nmlWidth, nmlHeight, nmlExp, ovrExp, dwnExp, disExp)
{
var returnImg = new eaImage(nmlSrc, nmlWidth, nmlHeight);
returnImg.setNameConvention(nmlExp, ovrExp, nmlExp, nmlExp);
return returnImg;
};