home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ******************** Begin Button Object ******************** */ /* ====================================================================== OBJECT: com_netobjects_Button PLATFORMS: Netscape Navigator 4.01 or higher, Microsoft Internet Explorer 4.02 or higher DESC: This object allows developers to create form buttons with common built in event handlers such as onClick, onMouseDown, and more. The event handlers can be overridden to define custom responses to button events. The button property "type" indicates if the form button is of type "button", "submit" or "reset". ====================================================================== */ function com_netobjects_Button(params) { // Public Properties this.name = (params.name != null) ? params.name : ""; this.buttonName = (params.buttonName != null) ? params.buttonName : ""; this.formName = (params.formName != null) ? params.formName : ""; this.label = (params.label != null) ? params.label : ""; this.type = (params.type != null) ? params.type : ""; this.testMode = (params.testMode != null) ? params.testMode : "off"; // Public Methods this.render = _button_render; this.getName = _button_getName; this.setName = _button_setName; // Private Methods this.validateProperties = _button_validateProperties; // Public Events this.onBlur = _button_onBlur; this.onClick = _button_onClick; this.onFocus = _button_onFocus; this.onMouseDown = _button_onMouseDown; this.onMouseUp = _button_onMouseUp; this.onRender = _button_onRender; // Private Events (internal event driven functionality) // Validate object properties this.validateProperties(); // Public Methods ---------------------------------------- /* ====================================================================== METHOD: _button_render. Renders the button in HTML. ====================================================================== */ function _button_render() { // Initialize Variables var sbuttonName = ""; var slabel = ""; var stype = ""; var sonBlur = ""; var sonClick = ""; var sonFocus = ""; var sonMouseDown = ""; var sonMouseUp = ""; var eEvents = ""; // Set Variables sbuttonName = " Name = \"" + this.buttonName + "\""; slabel = " Value = \"" + this.label + "\""; stype = " Type = \"" + this.type + "\""; // Build Nav & IE shared link events sonBlur = " onBlur=\"" + this.name + ".onBlur();\""; sonClick = " onClick=\"return " + this.name + ".onClick();\""; sonFocus = " onFocus=\"" + this.name + ".onFocus();\""; sonMouseDown = " onMouseDown=\"" + this.name + ".onMouseDown()\""; sonMouseUp = " onMouseUp=\"" + this.name + ".onMouseUp();\""; eEvents = sonBlur + sonClick + sonFocus + sonMouseDown + sonMouseUp; // Write HTML document.write( "<Input" + sbuttonName + slabel + stype + eEvents + ">\n"); // Fire public events this.onRender(); } // END _button_render // Property Getters /* ====================================================================== METHOD: _button_getName. Getter for the 'name' property. ====================================================================== */ function _button_getName() { return this.name; } // END _button_getName // Property Setters /* ====================================================================== METHOD: _button_setName. Setter for the 'name' property. Returns true if the property was set, false if it could not be set. ====================================================================== */ function _button_setName(thevalue) { var returnVal = true; // Don't allow users to set the name once a name has been set. Errors // will occur if the object's name is changed midstream. if (this.name == null && !IsNum(thevalue.charAt(0)) && IsAlphaNumOrUnderscore(thevalue)) this.name = thevalue; else returnVal = false; return returnVal; } // END _button_setName /* ====================================================================== METHOD: _button_validateProperties. Used only in test mode. Writes out error and warning messages if some property values are set with bad values. ====================================================================== */ function _button_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.buttonName == "") errors[iIndex++] = "Button name is a required property."; if (this.name == this.buttonName) errors[iIndex++] = "The name property and the buttonName property are currently equal. This can cause event handlers to fail and can cause other errors."; // Display errors for (var i=0; i<errors.length; i++) { if (this.testMode.toLowerCase() == "text") document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_Button, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n"); else alert("TEST MODE, com_netobjects_Button, '" + this.name + "' : " + errors[i]); } } } // END _button_validateProperties // Public Event Handlers ---------------------------------------- // Default handlers for each event, can be overridden in calling page. function _button_onBlur() { } function _button_onClick() { } function _button_onFocus() { } function _button_onMouseDown() { } function _button_onMouseUp() { } function _button_onRender() { } } // END CONSTRUCTOR com_netobjects_Button /* ====================================================================== FUNCTION: IsNum INPUT: numstr (string/number) - the string that will be tested to ensure that the value is a number (int or float) RETURN: true, if all characters represent a valid integer or float false, otherwise. PLATFORMS: Netscape Navigator 3.01 and higher, Microsoft Internet Explorer 3.02 and higher, Netscape Enterprise Server 3.0, Microsoft IIS/ASP 3.0. ====================================================================== */ function IsNum( numstr ) { // Return immediately if an invalid value was passed in if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "") return false; var isValid = true; var decCount = 0; // number of decimal points in the string // convert to a string for performing string comparisons. numstr += ""; // Loop through string and test each character. If any // character is not a number, return a false result. // Include special cases for negative numbers (first char == '-') // and a single decimal point (any one char in string == '.'). for (i = 0; i < numstr.length; i++) { // track number of decimal points if (numstr.charAt(i) == ".") decCount++; if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) { isValid = false; break; } else if ((numstr.charAt(i) == "-" && i != 0) || (numstr.charAt(i) == "." && numstr.length == 1) || (numstr.charAt(i) == "." && decCount > 1)) { isValid = false; break; } } // END for return isValid; } // end IsNum /* ====================================================================== FUNCTION: IsAlphaNumOrUnderscore INPUT: str (string) - the string to be tested RETURN: true, if the string contains only alphanumeric characters or underscores. false, otherwise. PLATFORMS: Netscape Navigator 3.01 and higher, Microsoft Internet Explorer 3.02 and higher, Netscape Enterprise Server 3.0, Microsoft IIS/ASP 3.0. ====================================================================== */ function IsAlphaNumOrUnderscore( str ) { // Return immediately if an invalid value was passed in if (str+"" == "undefined" || str+"" == "null" || str+"" == "") return false; var isValid = true; str += ""; // convert to a string for performing string comparisons. // Loop through string one character at a time. If non-alpha numeric // is found then, break out of loop and return a false result for (i = 0; i < str.length; i++) { // Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z" if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) || ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) || (str.charAt(i) == "_") ) ) { isValid = false; break; } } // END for return isValid; } // end IsAlphaNumOrUnderscore /* ******************** END Button Object ******************** */