home *** CD-ROM | disk | FTP | other *** search
/ Venus 7000 / darktronics.iso / Software / Service Packs / WinXPSP1.exe / appwiz.cp_ / appwiz.cpl / HTML / BPLATE.JS < prev    next >
Encoding:
Text File  |  2002-08-29  |  3.3 KB  |  163 lines

  1. function _NextToken(sz, ichStart, chDelim)
  2. {
  3. var ich = ichStart;
  4. var cch = sz.length;
  5. while (ich < cch && sz.charAt(ich) == chDelim)
  6. {
  7. ich++;
  8. }
  9. if (ich == cch)
  10. ich = -1;
  11. return ich;
  12. }
  13. function BoilerPlate()
  14. {
  15. this._rgszFields = new Array();
  16. this._cfield = 0;
  17. }
  18. function BoilerPlate_Parse(szArgs)
  19. {
  20. szArgs += " "; 
  21. var ichTag = 0;
  22. while (true)
  23. {
  24. ichTag = szArgs.indexOf("<", ichTag);
  25. if (-1 == ichTag)
  26. break;
  27. else 
  28. {
  29. ichTag++;
  30. var ichNameEnd = szArgs.indexOf(" ", ichTag);
  31. var ichValueBegin = _NextToken(szArgs, ichNameEnd, " ");
  32. var ichValueEnd;
  33. if (szArgs.charAt(ichValueBegin) == '"')
  34.             {
  35.                 ichValueBegin++;
  36.                 
  37.                 ichValueEnd = szArgs.indexOf('"', ichValueBegin);
  38. }
  39. else
  40. ichValueEnd = szArgs.indexOf(">", ichValueBegin);
  41. var szField = szArgs.substring(ichTag, ichNameEnd);
  42. var szValue = szArgs.substring(ichValueBegin, ichValueEnd);
  43. this._rgszFields[szField.toLowerCase()] = szValue;
  44. this._cfield++;
  45. ichTag = ichValueEnd;
  46. }
  47. }
  48. }
  49. function BoilerPlate_Get(szFieldName)
  50. {
  51. var szValue = this._rgszFields[szFieldName.toLowerCase()];
  52. if ("" == szValue || "undefined" == typeof szValue)
  53. return null;
  54. return szValue;
  55. }
  56. function BoilerPlate_Length()
  57. {
  58. return this._cfield;
  59. }
  60. function _FindParentRow(elem)
  61. {
  62. var trLast = null;
  63. while (elem)
  64. {
  65. if ("TR" == elem.tagName.toUpperCase())
  66. return elem;
  67. elem = elem.parentElement;
  68. }
  69. return null;
  70. }
  71. function BoilerPlate_Apply()
  72. {
  73. var i;
  74. for (i = document.all.length - 1; i >= 0; i--)
  75. {
  76. var elem = document.all.item(i);
  77. var szField;
  78. var bDeleteRow = false;
  79. var bIsElemMarked = false;
  80. var bHideElem = false;
  81. if (null != elem._bpInnerText)
  82. {
  83. szField = this.Get(elem._bpInnerText);
  84. if (null == szField)
  85. {
  86. bDeleteRow = true;
  87. bHideElem = true;
  88. szField = "n/a";
  89. }
  90. elem.innerText = szField;
  91. bIsElemMarked = true;
  92. }
  93. if (null != elem._bpHref && "A" == elem.tagName)
  94. {
  95. szField = this.Get(elem._bpHref);
  96. bHideElem = false; 
  97. if (null != szField && 
  98. ("http:" == szField.substring(0, 5) || 
  99. "https:" == szField.substring(0, 6) ||
  100. "file:" == szField.substring(0, 5) ||
  101. "ftp:" == szField.substring(0, 4)))
  102. {
  103. elem.href = szField;
  104. if ("n/a" == elem.innerText)
  105. {
  106. elem.innerText = elem.href;
  107. }
  108. if (elem.href != elem.innerText)
  109. {
  110. elem.title = elem.href;
  111. }
  112. bDeleteRow = false; 
  113. }
  114. else
  115. {
  116. elem.style.color = document.fgColor;
  117. }
  118. bIsElemMarked = true;
  119. if ("n/a" == szField)
  120. bHideElem = true;
  121. }
  122. if (null != elem._bpValue)
  123. {
  124. elem._bpVar = this.Get(elem._bpValue);
  125. bIsElemMarked = true;
  126. }
  127. if (null != elem._bpNop && null == this.Get(elem._bpNop))
  128. {
  129. bHideElem = true;
  130. }
  131. if (bHideElem)
  132. {
  133. elem.style.display = 'none';
  134. }
  135. if (bIsElemMarked)
  136. {
  137. var trElem = _FindParentRow(elem);
  138. if (trElem && false != trElem._bpDelete)
  139. {
  140. trElem._bpDelete = bDeleteRow;
  141. }
  142. }
  143. }
  144. var rgrows = document.all.tags("TR");
  145. for (i = rgrows.length - 1; i >= 0; i--)
  146. {
  147. var trElem = rgrows[i];
  148. if (trElem && trElem._bpDelete)
  149. {
  150. var tbl = trElem.parentElement;
  151. tbl.deleteRow(trElem.rowIndex);
  152. }
  153. }
  154. }
  155. function InitBoilerPlateClass()
  156. {
  157. new BoilerPlate(null);
  158. BoilerPlate.prototype.Parse = BoilerPlate_Parse;
  159. BoilerPlate.prototype.Get = BoilerPlate_Get;
  160. BoilerPlate.prototype.Length = BoilerPlate_Length;
  161. BoilerPlate.prototype.Apply = BoilerPlate_Apply;
  162. }
  163.