home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / objects.js < prev    next >
Encoding:
Text File  |  1998-10-05  |  3.0 KB  |  89 lines

  1. function com_netobjects_objectsComponent(params) {
  2.     this.isPropInObj = isPropInObj;
  3.     this.viewObject = viewObject;
  4.  
  5.        this.name = (params.name+"" != "undefined" && params.name != null ? params.name : "objectsComponent1");
  6.  
  7.     /* ======================================================================
  8.     FUNCTION:    isPropInObj
  9.      
  10.     INPUT:        str (string): the value to be compared
  11.                     partialMatch (boolean): (optional) should partial or exact matches be performed.
  12.                                                     Defaults to false if unspecified (i.e. does 
  13.                                                     exact match, not partial match, by default).        
  14.     
  15.     RETURN:      true, if the value is found equal to or partially equal to a property of the object;
  16.                   false, otherwise;
  17.                     returns null if invalid arguments were passed
  18.     
  19.     DESC:            This function loops through all of the properties in any JavaScript/JScript object
  20.                     and searches for a given property in the object.  The function can be configured
  21.                     so that partial matches on a property name can be conducted.  
  22.     ====================================================================== */
  23.     function isPropInObj ( str, obj, partialMatch ) {
  24.         var result = false;
  25.  
  26.         // Return immediately if an invalid value was passed in
  27.         if (str+"" == "undefined" || str+"" == "null")    
  28.             return null;
  29.         if (obj+"" == "undefined" || obj+"" == "null")    
  30.             return null;
  31.             
  32.         // Default partialMatch to false if undefined or null
  33.         if (partialMatch+"" == "undefined"  || partialMatch+"" == "null")    
  34.             partialMatch = false;
  35.     
  36.         // Make sure the string argument is a string
  37.         str += "";
  38.         
  39.         if (partialMatch) 
  40.             for (var firProp in obj) {
  41.                 if (firProp.indexOf(str) != -1) {
  42.                     result = true;
  43.                 }
  44.             }
  45.                     
  46.         else 
  47.             for (var firProp in obj) {
  48.                 if (firProp == str) {
  49.                     result = true;
  50.                 }
  51.             }
  52.         return result;
  53.         
  54.     } // end isPropInObj
  55.     
  56.     /* ======================================================================
  57.     FUNCTION:    viewObject
  58.      
  59.     INPUT:        obj (object): the object to be viewed
  60.                     objName (string): the name of the object that corresponds to obj
  61.     
  62.     RETURN:      A string containing HTML showing the list of object properties;
  63.                     returns null if invalid arguments were passed
  64.     
  65.     DESC:            This function loops through any JavaScript/JScript object and 
  66.                     and returns HTML that will display all properties of the object 
  67.                     between two HTML horizontal rules.
  68.     ====================================================================== */
  69.     function viewObject (obj, objName) {
  70.         var outputStr = "";
  71.     
  72.         // Return immediately if an invalid value was passed in
  73.         if (obj+"" == "undefined" || obj+"" == "null")    
  74.             return null;
  75.         // Set default object name if none is provided
  76.         if (objName+"" == "undefined" || objName+"" == "null")    
  77.             objName = "[Object]";
  78.         
  79.           outputStr = "<BR><HR><BR>\n";
  80.           outputStr += "\n<BR><B>"+objName+" Properties: </B><BR>";
  81.           for (prop in obj) {
  82.             outputStr += "\n<BR>"+objName+"."+prop+" = "+obj[prop];
  83.           }
  84.           outputStr += "<BR><HR><BR>\n";
  85.           
  86.           return outputStr;
  87.     } // end viewObject
  88. }
  89.