home *** CD-ROM | disk | FTP | other *** search
- /* ======================================================================
- OBJECT: com_netobjects_PopUpWindow
-
- DESCRIPTION: The PopUpWindow object opens and closes a new browser window.
- Browser window properties can be set, such as height, width, etc.
- Also configurable is whether or not certain browser elements are
- present, such as the status bar, toolbar, etc.
-
- TESTED
- PLATFORMS: Netscape Navigator 4.05,
- Microsoft Internet Explorer 4.01
- ====================================================================== */
- function com_netobjects_PopUpWindow(params) {
-
- // Public Properties
- this.name = (params.name != null) ? params.name : "";
- this.testMode = (params.testMode != null) ? params.testMode : "off";
-
- this.URL = (params.URL != null) ? params.URL : "";
- this.toolbar = (params.toolbar != null) ? params.toolbar : true;
- this.location = (params.location != null) ? params.location : true;
- this.directories = (params.directories != null) ? params.directories : true;
- this.status = (params.status != null) ? params.status : true;
- this.menubar = (params.menubar != null) ? params.menubar : true;
- this.scrollbars = (params.scrollbars != null) ? params.scrollbars : true;
- this.resizable = (params.resizable != null) ? params.resizable : true;
- this.width = (params.width != null) ? params.width : true;
- this.height = (params.height != null) ? params.height : true;
- this.top = (params.top != null) ? params.top : true;
- this.left = (params.left != null) ? params.left : true;
-
- // Private Properties
- this.hdlWindow = null; // handle to the opened window
-
- // Public Methods
- this.open = _popupwindow_open;
- this.close = _popupwindow_close;
- this.getName = _popupwindow_getName;
- this.setName = _popupwindow_setName;
-
- // Private Methods
- this.getFeatures = _popupwindow_getFeatures;
- this.validateProperties = _popupwindow_validateProperties;
-
- // Public Events
- this.onClose = _popupwindow_onClose;
- this.onOpen = _popupwindow_onOpen;
-
- // Private Events (internal event driven functionality)
- this.eOnClose = _popupwindow_eOnClose;
-
- // If test mode is set, check for invalid property values
- this.validateProperties();
-
- // Public Methods ----------------------------------------
-
- /* ======================================================================
-
- METHOD: _popupwindow_open. Opens the pop-up window.
-
- ====================================================================== */
- function _popupwindow_open() {
- this.hdlWindow = window.open(this.URL, this.name, this.getFeatures());
-
- // Fire public event
- this.onOpen();
- } // END _popupwindow_open
-
-
- /* ======================================================================
-
- METHOD: _popupwindow_close. Closes the pop-up window if it's open.
-
- ====================================================================== */
- function _popupwindow_close() {
- err = "";
-
- if (this.hdlWindow != null && !this.hdlWindow.closed)
- this.hdlWindow.close();
-
- // Fire private event
- this.eOnClose();
- // Fire public event
- } // END _popupwindow_close
-
-
- // Property Getters
- /* ======================================================================
-
- METHOD: _popupwindow_getName. Getter for the 'name' property.
-
- ====================================================================== */
- function _popupwindow_getName() {
- return this.name;
- } // END _popupwindow_getName
-
-
- // Property Setters
- /* ======================================================================
-
- METHOD: _popupwindow_setName. Setter for the 'name' property. Returns
- true if the property was set, false if it could not be set.
-
- ====================================================================== */
- function _popupwindow_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 _popupwindow_setName
-
-
- // Private Methods ----------------------------------------
-
- /* ======================================================================
-
- METHOD: _popupwindow_getFeatures. Generates a string that combines all
- all of the yes/no propeties into a comma-delimited list of name/value
- pairs. This string corresponds to the required syntax of the JavaScript
- window.open() method's feature list argument.
-
- E.g. statusbar=yes,toolbar=yes,height=200,width=100
-
- ====================================================================== */
- function _popupwindow_getFeatures() {
- sFeatures = "";
-
- if (this.toolbar)
- sFeatures += "toolbar=yes";
- if (this.location)
- sFeatures += ",location=yes";
- if (this.directories)
- sFeatures += ",directories=yes";
- if (this.status)
- sFeatures += ",status=yes";
- if (this.menubar)
- sFeatures += ",menubar=yes";
- if (this.scrollbars)
- sFeatures += ",scrollbars=yes";
- if (this.resizable)
- sFeatures += ",resizable=yes";
- if (this.width != null && this.width != "")
- sFeatures += ",width=" + this.width;
- if (this.height != null && this.height != "")
- sFeatures += ",height=" + this.height;
- if (this.top != null && this.left != "")
- sFeatures += ",top=" + this.top;
- if (this.left != null && this.left != "")
- sFeatures += ",left=" + this.left;
-
- // Strip off the unnecessary starting comma, if one exists
- if (sFeatures.charAt(0) == ',')
- sFeatures = sFeatures.substring(1, sFeatures.length);
-
- return sFeatures;
- } // END _popupwindow_getFeatures()
-
- /* ======================================================================
-
- METHOD: _popupwindow_validateProperties. Used only in test mode. Writes out
- error and warning messages if some property values are set with bad
- values.
-
- ====================================================================== */
- function _popupwindow_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.";
-
- // 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_PopUpWindow, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
- else
- alert("TEST MODE, com_netobjects_PopUpWindow, '" + this.name + "' : " + errors[i]);
- }
- }
- } // END _popupwindow_validateProperties
-
-
- // Private Event Handlers ----------------------------------------
-
- /* ======================================================================
-
- EVENT: _popupwindow_eOnClose. Internal event handler. Resets window handle
- to null then fires the public onClose event.
-
- ====================================================================== */
- function _popupwindow_eOnClose() {
- this.hdlWindow = null;
-
- // Fire public event
- this.onClose();
- } // end _popupwindow_eOnClose()
-
-
- // Public Event Handlers ----------------------------------------
-
- function _popupwindow_onClose() {
- }
- function _popupwindow_onOpen() {
- }
-
- } // END CONSTRUCTOR com_netobjects_PopUpWindow
-
- // Shared code - reused in several components
-
- /* ======================================================================
- 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 == 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
-
- /* ======================================================================
- 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
-