home *** CD-ROM | disk | FTP | other *** search
- com_netobjects_AnimImg = com_netobjects_ImageCtl;
- com_netobjects_ActiveImg = com_netobjects_ImageCtl;
-
- /* ======================================================================
- OBJECT: com_netobjects_ImageCtl
-
- DESC: This object allows developers to create images with common built
- in behaviors such as rollover effects, state dependent image displays
- image changes on click or mouse down, and image animation.
-
- PLATFORMS: Netscape Navigator 4.01 or higher,
- Microsoft Internet Explorer 4.02 or higher
- ====================================================================== */
- function com_netobjects_ImageCtl(params) {
-
- // Public Properties
- this.name = (params.name != null) ? params.name : "";
- this.linkURL = (params.linkURL != null) ? params.linkURL : "";
- this.alt = (params.alt != null) ? params.alt : "";
-
- this.defaultImage = (params.defaultImage != null) ? params.defaultImage : "";
- this.mouseOutImage = (params.mouseOutImage != null) ? params.mouseOutImage : "";
- this.mouseOverImage = (params.mouseOverImage != null) ? params.mouseOverImage : "";
- this.mouseDownImage = (params.mouseDownImage != null) ? params.mouseDownImage : "";
- this.mouseUpImage = (params.mouseUpImage != null) ? params.mouseUpImage : "";
- this.stateOnImage = (params.stateOnImage != null) ? params.stateOnImage : "";
- this.stateOffImage = (params.stateOffImage != null) ? params.stateOffImage : "";
-
- this.stateOn = ((params.stateOn != null) && (params.stateOn != "")) ? params.stateOn : false;
- this.imageArrayStr = (params.imageArrayStr != null) ? params.imageArrayStr : "";
- this.imageInterval = ((params.imageInterval != null) && (params.imageInterval != "")) ? params.imageInterval : 1000;
-
- this.height = ((params.height != null) && (params.height != "")) ? params.height : 0;
- this.width = ((params.width != null) && (params.width != "")) ? params.width : 0;
- this.target = (params.target != null) ? params.target : "";
- this.border = ((params.border != null) && (params.border != "")) ? params.border : 0;
-
- this.testMode = (params.testMode != null) ? params.testMode : "none"
-
- // Private Properties
- this.imageArray = unEncodeList(this.imageArrayStr); // Parse image array
- this.timerID = null;
- this.imageNo = 0;
- this.rotateNo = 0;
-
- // Public Methods
- this.render = _image_render;
- this.animationStart = _image_animationStart;
- this.animationStop = _image_animationStop;
-
- // Private Methods
- this.validateProperties = _image_validateProperties;
- this.rotateImage = _image_rotateImage;
-
- // Public Events
- this.onClick = _image_onClick;
- this.onMouseDown = _image_onMouseDown;
- this.onMouseUp = _image_onMouseUp;
- this.onMouseOver = _image_onMouseOver;
- this.onMouseOut = _image_onMouseOut;
- this.onError = _image_onError;
- this.onAbort = _image_onAbort;
- this.onLoad = _image_onLoad;
- this.onRender = _image_onRender;
- this.onAnimationStart= _image_onAnimationStart;
- this.onAnimationStop = _image_onAnimationStop;
- this.onRotateImage = _image_onRotateImage;
-
- // Private Events (internal event driven functionality)
- this.eOnClick = _image_eOnClick;
- this.eOnMouseDown = _image_eOnMouseDown;
- this.eOnMouseUp = _image_eOnMouseUp;
- this.eOnMouseOver = _image_eOnMouseOver;
- this.eOnMouseOut = _image_eOnMouseOut;
-
- // Validate object properties
- this.validateProperties();
-
- // Public Methods ----------------------------------------
- function _image_render() {
- // Initialize Variables
- sSrc = "";
- sAlt = "";
- sHeight = "";
- sWidth = "";
- sTarget = "";
- sBorder = "";
- sLink = "";
-
- eMouseOver = "";
- eMouseOut = "";
- eMouseUp = "";
- eMouseDown = "";
- eMouseClick = "";
-
- eError = "";
- eAbort = "";
- eLoad = "";
-
- this.stateOn = true;
-
- // Set Variables
- if (this.defaultImage != "")
- sSrc = " SRC = '" + this.defaultImage + "'";
- else if (this.imageArray[0] != null) // default to first image for animated images
- sSrc = " SRC = '" + this.imageArray[0] + "'";
- sAlt = " ALT = '" + this.alt + "'";
- sBorder = " BORDER = '" + this.border + "'"
- sImageName = " Name = 'Img_" + this.name + "'"
-
- if (this.linkURL != "") {sLink = " HREF = '" + this.linkURL + "'"}
- else {sLink = " HREF = ''"}
-
- if (this.height != 0) {sHeight = " HEIGHT = '" + this.height + "'"}
- if (this.width != 0) {sWidth = " WIDTH = '" + this.width + "'"}
- if (this.target != "") {sTarget = " TARGET = '" + this.target + "'"}
-
- // Build Nav & IE shared link events
- eMouseOver = " onmouseover=\"" + this.name + ".eOnMouseOver();\""
- eMouseOut = " onmouseout=\"" + this.name + ".eOnMouseOut();\""
- eMouseUp = " onmouseup=\"" + this.name + ".eOnMouseUp();\""
- eMouseDown = " onmousedown=\"" + this.name + ".eOnMouseDown();\""
- eMouseClick = " onclick=\"return " + this.name + ".eOnClick();\""
- eLnkEvents = eMouseOver + eMouseOut + eMouseUp + eMouseDown + eMouseClick;
-
- // Build Nav & IE shared Image events
- eError = " onerror=\"" + this.name + ".onError();\""
- eAbort = " onabort=\"" + this.name + ".onAbort();\""
- eLoad = " onload=\"" + this.name + ".onLoad();\""
- eImgEvents = eError + eAbort + eLoad;
-
- // Write HTML
- document.write( "<A" + sLink + sAlt + sTarget + eLnkEvents + ">");
- document.write( "<IMG" + sImageName + sAlt + sSrc + sHeight + sWidth + sBorder + eImgEvents + ">");
- document.write( "</A>");
- // JJK: 9/13/98: Commented out to fix a bug occuring when using this object with HTML tables:
- // it creates an unnecessary extra blank line at the bottom of the row.
- // document.write("\n");
-
- // Start animation if animation control
- if (this.imageArrayStr != "") this.animationStart();
-
- // Fire public events
- this.onRender();
-
- } // END _image_render
-
- /* ======================================================================
-
- METHOD: _image_rotateImage. Rotates image.
-
- ====================================================================== */
- function _image_rotateImage() {
- this.rotateNo = this.rotateNo + 1;
-
- // Set next image
- if (this.imageNo == this.imageArray.length) {this.imageNo = 1} else {this.imageNo = this.imageNo + 1}
-
- // Update image
- eval("window.document.Img_" + this.name + ".src=\"" + this.imageArray[this.imageNo-1] + "\"");
- this.timerID = setTimeout(this.name + ".rotateImage()",this.imageInterval);
-
- // Fire public events
- this.onRotateImage();
-
- } // END _image_rotateImage
-
- /* ======================================================================
-
- METHOD: _image_animationStart. Starts image animation if not already started.
-
- ====================================================================== */
- function _image_animationStart() {
-
- if (this.rotateNo == 0) {
- this.onAnimationStart();
-
- // Fire public events
- this.rotateImage();
- }
-
- } // END _image_animationStart
-
- /* ======================================================================
-
- METHOD: _image_animationStop. Stops image animation if not already stopped
-
- ====================================================================== */
- function _image_animationStop() {
- if (this.rotateNo != 0) {
- clearTimeout(this.timerID);
- this.rotateNo = 0;
-
- // Fire public events
- this.onAnimationStop();
- }
- } // END _image_animationStop
-
- // Private Methods ----------------------------------------
- /* ======================================================================
-
- METHOD: _image_validateProperties. If the test mode is set,
- generate error and/or warning messages if required or recommended properties
- are set with invalid property values or are not set at all.
-
- ====================================================================== */
- function _image_validateProperties() {
- if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
- var errors = new Array()
- iIndex = 0;
-
- // Check for errors
- if (this.name == "")
- errors[iIndex++] = "Name is a required property.";
- if ((this.defaultImage == "") && (this.imageArrayStr == ""))
- errors[iIndex++] = "Default image is a highly recommended property.";
- if ((this.stateOn != false) && (this.stateOn != true))
- errors[iIndex++] = "State On must be a true or false value.";
- if ((this.imageArrayStr != "") && ((params.imageInterval = null) || (params.imageInterval = "")))
- errors[iIndex++] = "Image interval should be specified for animated images.";
-
- // Display errors
- for (var i=0; i<errors.length; i++) {
- if (this.testMode.toLowerCase() == "text")
- document.write( "<BR>" + errors[i] + "\n")
- else
- alert(errors[i]);
-
- }
- }
- } // END _image_validateProperties
-
-
-
- // Private Event Handlers ----------------------------------------
-
- /* ======================================================================
-
- EVENT: _colorpicker_eOnClose. Internal event handler. For the selected
- state, display the appropriate image if available.
-
- ====================================================================== */
- function _image_eOnClick() {
- var clickProceed = false;
-
- // Check the state
- if (this.stateOn == true) {
- // Display on image
- if (this.stateOnImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.stateOnImage + "\"");
- }
- } else {
- // Display off image
- if (this.stateOffImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.stateOffImage + "\"");
- }
- }
- this.stateOn = ! this.stateOn;
-
- if (this.linkURL != "")
- clickProceed = true
-
- // Fire event handler
- this.onClick();
-
- return clickProceed // this.onClick(); should this be overridable?
- } // END _image_eOnClick
-
- /* ======================================================================
-
- EVENT: _image_eOnMouseOver. Internal event handler. Display the MouseOver image if available.
-
- ====================================================================== */
- function _image_eOnMouseOver() {
- if (this.mouseOverImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.mouseOverImage + "\"");
- }
-
- // Fire event handler
- this.onMouseOver();
- } // END _image_eOnMouseOver
-
- /* ======================================================================
-
- EVENT: _image_eOnMouseOut. Internal event handler. Display the MouseOut image if available.
-
- ====================================================================== */
- function _image_eOnMouseOut() {
- if (this.mouseOutImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.mouseOutImage + "\"");
- }
-
- // Fire event handler
- this.onMouseOut();
- } // END _image_eOnMouseOut
-
- /* ======================================================================
-
- EVENT: _image_eOnMouseUp. Internal event handler. Display the MouseUp image if available.
-
- ====================================================================== */
- function _image_eOnMouseUp() {
- if (this.mouseUpImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.mouseUpImage + "\"");
- }
- // Fire event handler
- this.onMouseUp();
- } // END _image_eOnMouseUp
-
- /* ======================================================================
-
- EVENT: _image_eOnMouseDown. Internal event handler. Display the MouseDown image if available.
-
- ====================================================================== */
- function _image_eOnMouseDown() {
- if (this.mouseDownImage != "") {
- eval("window.document.Img_" + this.name + ".src=\"" + this.mouseDownImage + "\"");
- }
-
- // Fire event handler
- this.onMouseDown();
- } // END _image_eOnMouseDown
-
- // Public Event Handlers ----------------------------------------
- function _image_onClick() {
- }
- function _image_onMouseOver() {
- }
- function _image_onMouseOut() {
- }
- function _image_onMouseUp() {
- }
- function _image_onMouseDown() {
- }
- function _image_onError() {
- }
- function _image_onAbort() {
- }
- function _image_onLoad() {
- }
- function _image_onRender() {
- }
- function _image_onAnimationStart() {
- }
- function _image_onAnimationStop() {
- }
- function _image_onRotateImage() {
- }
-
- } // END CONSTRUCTOR com_netobjects_ImageCtl
-
- // Shared Array Parsing function
- function unEncodeJS(input) {
- if (null == input)
- return null;
- if (input == "null" )
- return null;
- output = "";
- i=0;
- while (i<input.length) {
- ch = input.charAt(i++);
- if ('\\' == ch) {
- ch = input.charAt(i++);
- if ('n' == ch) {
- output += '\n';
- } else if (';' == ch) {
- output += ';';
- } else if ('r' == ch) {
- //supress this character
- } else if ('t' == ch) {
- output += '\t';
- } else {
- output += ch;
- }
- } else {
- output += ch;
- }
- }
- return output;
- } // END unEncodeList
-
- function unEncodeList( sList ) {
- aRes = null;
- if ( null != sList && ""!=sList ) {
- aRes = new Array();
- iStart = 0;
- iIndex = 0;
- j=0;
- while (j<sList.length) {
- ch = sList.charAt(j++);
- if ('\\' == ch) {
- ch = sList.charAt(j++);
- } else {
- if ( ';' == ch ) {
- sRaw = sList.substring( iStart, j-1 );
- aRes[iIndex++] = unEncodeJS( sRaw );
- iStart = j;
- }
- }
- }
- if ( iStart != j ) {
- sRaw = sList.substring( iStart, j );
- aRes[iIndex++] = unEncodeJS( sRaw );
- }
- }
- return aRes;
- } // END unEncodeList
-
-