home *** CD-ROM | disk | FTP | other *** search
/ Enter 2002 August / EnterCD 8_2002.iso / Internet / Adobe GoLive 6.0 / data1.cab / PF_AppDir_SDK / Samples / Shared / Adobe / markupUtils.js < prev   
Encoding:
JavaScript  |  2002-03-28  |  3.6 KB  |  148 lines

  1. //------------------------------------------------------------
  2. // ADOBE SYSTEMS INCORPORATED
  3. // Copyright 2000-2002 Adobe Systems Incorporated 
  4. // All Rights Reserved
  5. //
  6. // NOTICE: Adobe permits you to use, modify, and distribute 
  7. // this file in accordance with the terms of the Adobe license 
  8. // agreement accompanying it. If you have received this file 
  9. // from a source other than Adobe, then your use, modification, 
  10. // or distribution of it requires the prior written permission 
  11. // of Adobe.
  12. //------------------------------------------------------------
  13.  
  14. //------------------------------------------------------------
  15. // markupUtils.js
  16.  
  17. // This file contains general purpose functions 
  18. // for the JSXMarkup object
  19.  
  20. // List of functions:
  21. //
  22. // getAncestorOfName(theName): 
  23. // Return ancestor element of theName
  24. // theName: tagName of ancestor element to search for
  25. //
  26. // getChildCount(name)
  27. // For the markup element, return the number of children 
  28. // of name. Children are defined as subElements whose 
  29. // parent is the markup element. If name is not specified, 
  30. // return total number of children.
  31. //
  32. // getChildren(name)
  33. // Return an array with children of the markup element. 
  34. // Children are defined as subElements whose parent is 
  35. // the markup element. Optional name parameter to get
  36. // only children with the given name.
  37. // 
  38. // The function getSubElement returns all children and 
  39. // children's children of the element. 
  40. //
  41. // This implementation use the subElements 
  42. // property to get all children of type tag.
  43.  
  44.  
  45. //-------------------------
  46. // getAncestorOfName
  47. //
  48. // this general purpose function returns the the 
  49. // ancestor element of theName
  50. //
  51.  
  52. function JSXMarkup_getAncestorOfName(theName)  
  53. {
  54.     var rtnVal = null;
  55.     var theElt = this.parent;
  56.     
  57.     while (theElt != null) 
  58.     {
  59.         if (theElt.elementType == "tag") 
  60.         {
  61.             if  (theElt.tagName == theName)    
  62.             {    
  63.                 rtnVal = theElt;
  64.             }
  65.         }
  66.         theElt = theElt.parent;
  67.     }
  68.     return rtnVal;
  69. }
  70.  
  71. JSXMarkup.prototype.getAncestorOfName = JSXMarkup_getAncestorOfName;
  72.  
  73. //----------------------------
  74. // getChildCount()
  75. //
  76. // Count the number of children of 
  77. // theElt. Optionally, specify name
  78. // of children to count.
  79.  
  80. function JSXMarkup_getChildCount(name) 
  81. {
  82.     var ct = 0;
  83.     if (arguments.length == 0) 
  84.     {
  85.         // count all children
  86.         for (var i = 0; i < this.subElements.length; i++) 
  87.         {
  88.             if (this.subElements[i].elementType == "tag")
  89.             {
  90.                 ct++;
  91.             }
  92.         }
  93.     }
  94.     else
  95.     {
  96.         // count all children of name
  97.         for (var i = 0; i < this.subElements.length; i++) 
  98.         {
  99.             if ((this.subElements[i].elementType == "tag") &&
  100.                 (this.subElements[i].tagName == name)) 
  101.             {
  102.                 ct++;
  103.             }
  104.         }
  105.     }
  106.  
  107.     return ct;    
  108. }
  109.  
  110. JSXMarkup.prototype.getChildCount = JSXMarkup_getChildCount;
  111.  
  112. //-------------------------------
  113. // getChildren()
  114. //
  115. // This function returns an array of the children of 
  116. // the current element. Only children whose elementType
  117. // is tag are returned.
  118. // Optional parameter to specify the name of children 
  119. // to get.
  120.  
  121. function JSXMarkup_getChildren (name) 
  122. {
  123.     var childAry = new Array(0);
  124.  
  125.     if (arguments.length == 0)
  126.     {
  127.         for (var i = 0; i < this.subElements.length; i++) 
  128.         {
  129.             if (this.subElements[i].elementType == "tag")
  130.             {
  131.                 childAry.push(this.subElements[i]);
  132.             }
  133.         }
  134.     }
  135.     else { 
  136.         for (var i = 0; i < this.subElements.length; i++) 
  137.         {
  138.             if ((this.subElements[i].elementType == "tag") &&
  139.                 (this.subElements[i].tagName == name)) 
  140.             {
  141.                 childAry.push(this.subElements[i]);
  142.             }
  143.         }
  144.     }
  145.     return childAry;
  146. }
  147.  
  148. JSXMarkup.prototype.getChildren = JSXMarkup_getChildren;