PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Documentation/scripts/mshs.js

#
JavaScript | 215 lines | 178 code | 22 blank | 15 comment | 68 complexity | ef4f110bc1ea4104b66c2dc4eb45c83e MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. /* Returns a document element using the Firefox friendly getElementById */
  2. function documentElement(id) {
  3. return document.getElementById(id);
  4. }
  5. /* Locates the first meta tag with a specific name */
  6. function FindMetaTag(name) {
  7. var AllMetaTags = document.getElementsByTagName('meta');
  8. for (var i = 0; i < AllMetaTags.length; i++) {
  9. var MetaTag = AllMetaTags[i];
  10. if (MetaTag.name == name)
  11. return MetaTag;
  12. }
  13. }
  14. /* Gets the MSHS base url for resources */
  15. function ResourceBaseUrl() {
  16. if (isDesignTime) {
  17. return '';
  18. }
  19. else {
  20. // Get the first script tag
  21. var script = document.getElementById('mshs_support_script');
  22. // Extract the src which is a full resource url to within our origin .mshc
  23. var scriptSrc = script.src;
  24. // Get the portion up to the ; (the base url for resource references)
  25. var startIndex = scriptSrc.indexOf(';') + 1;
  26. var scriptUrl = scriptSrc.substring(0, startIndex);
  27. return scriptUrl;
  28. }
  29. }
  30. function ToggleSection(id) {
  31. var element;
  32. var img;
  33. // Find the element
  34. element = documentElement(id);
  35. img = documentElement(id + "_Image");
  36. if (element) {
  37. if (element.className == "hs-collapsed") {
  38. element.className = "hs-expanded";
  39. if (img) {
  40. img.src = ResourceBaseUrl() + "images/hs-expanded.gif";
  41. if (getStyleAttribute(img, "hs-hidealltext"))
  42. img.alt = getStyleAttribute(img, "hs-hidealltext");
  43. else
  44. img.alt = "Hide";
  45. }
  46. }
  47. else {
  48. element.className = "hs-collapsed";
  49. if (img) {
  50. img.src = ResourceBaseUrl() + "images/hs-collapsed.gif";
  51. if (getStyleAttribute(img, "hs-showalltext"))
  52. img.alt = getStyleAttribute(img, "hs-showalltext");
  53. else
  54. img.alt = "Show";
  55. }
  56. };
  57. }
  58. }
  59. function getStyleAttribute(element, styleProp) {
  60. if (element.currentStyle)
  61. return element.currentStyle[styleProp];
  62. else if (window.getComputedStyle)
  63. return document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProp);
  64. }
  65. function HideOrShowAllCSections(show) {
  66. var spans
  67. var divs
  68. spans = document.getElementsByTagName("SPAN");
  69. if (spans) {
  70. for (var spanindex = 0; spanindex < spans.length; spanindex++) {
  71. if ((spans[spanindex].className == "hs-collapsed" && show) || (spans[spanindex].className == "hs-expanded" && !show)) {
  72. ToggleSection(spans[spanindex].id)
  73. }
  74. }
  75. }
  76. divs = document.getElementsByTagName("DIV")
  77. if (divs) {
  78. for (var divindex = 0; divindex < divs.length; divindex++) {
  79. if ((divs[divindex].className == "hs-collapsed" && show) || (divs[divindex].className == "hs-expanded" && !show)) {
  80. ToggleSection(divs[divindex].id)
  81. }
  82. }
  83. }
  84. }
  85. function HideAllCSections() {
  86. var HSHideAll = documentElement("HSHideAll");
  87. var HSShowAll = documentElement("HSShowAll");
  88. HideOrShowAllCSections(false)
  89. if (HSHideAll) {
  90. HSHideAll.style.display = "none";
  91. if (HSShowAll) {
  92. HSShowAll.style.display = "block";
  93. }
  94. }
  95. }
  96. function ShowAllCSections() {
  97. var HSHideAll = documentElement("HSHideAll");
  98. var HSShowAll = documentElement("HSShowAll");
  99. HideOrShowAllCSections(true)
  100. if (HSShowAll) {
  101. HSShowAll.style.display = "none";
  102. if (HSHideAll) {
  103. HSHideAll.style.display = "block";
  104. }
  105. }
  106. }
  107. function ShowPageAddress() {
  108. alert(location.href);
  109. }
  110. function getNextSibling(n) {
  111. n = n.nextSibling;
  112. while (n) {
  113. if (n.nodeType == 1)
  114. return n;
  115. else
  116. n = n.nextSibling;
  117. }
  118. }
  119. function bodyLoadMain() {
  120. if (!isDesignTime) {
  121. // Fix double line breaks
  122. var linebreaks = document.getElementsByTagName("BR");
  123. if (linebreaks) {
  124. for (var linebreakindex = 0; linebreakindex < linebreaks.length; linebreakindex++) {
  125. var linebreak = linebreaks[linebreakindex];
  126. var sibling = getNextSibling(linebreak);
  127. if (sibling && sibling.tagName == "BR")
  128. linebreak.parentNode.removeChild(linebreak);
  129. }
  130. }
  131. // Fix double captions and bookmark links
  132. var anchors = document.getElementsByTagName("A");
  133. if (anchors) {
  134. for (var anchorindex = 0; anchorindex < (anchors.length); anchorindex++) {
  135. var anchor = anchors[anchorindex];
  136. var anchorCaption = anchor.innerText;
  137. if (anchorCaption && anchorCaption.substring(0, anchorCaption.length / 2) == anchorCaption.substring(anchorCaption.length / 2))
  138. anchor.innerHTML = anchorCaption.substring(anchorCaption.length / 2);
  139. // Check for bookmark links - currently prefixed with the full page url
  140. var anchorHref = anchor.href;
  141. if (anchorHref.indexOf('#') != -1) {
  142. var bookmark = anchorHref.substring(anchorHref.indexOf('#'));
  143. if (anchorHref.substring(0, anchorHref.indexOf('#')) == location.href) {
  144. // Bookmark in this document
  145. anchor.target = "_self";
  146. }
  147. }
  148. }
  149. }
  150. // Fix Javascript rules using urls
  151. var stylesheets = document.styleSheets;
  152. if (stylesheets && stylesheets.length > 0) {
  153. for (var stylesheetindex = 0; stylesheetindex < (stylesheets.length); stylesheetindex++) {
  154. var stylesheet = stylesheets[stylesheetindex];
  155. var rules;
  156. if (stylesheet.rules) {
  157. rules = stylesheet.rules;
  158. }
  159. else {
  160. rules = stylesheet.cssRules;
  161. }
  162. if (rules) {
  163. for (var ruleindex = 0; ruleindex < rules.length; ruleindex++) {
  164. var rule = rules[ruleindex];
  165. if (rule.style.backgroundImage) {
  166. if (rule.style.backgroundImage.substring(0, 4) == 'url(') {
  167. var backgroundText = rule.style.backgroundImage;
  168. var originalUrl
  169. if (rule.style.backgroundImage.indexOf('127.0.0.1') != -1) {
  170. // Chrome - rule returned as full url
  171. originalUrl = backgroundText.substring(backgroundText.indexOf('/', backgroundText.indexOf('127.0.0.1')) + 5, backgroundText.lastIndexOf(')'));
  172. }
  173. else {
  174. // IE - rule returned as original, with a .. prefix
  175. originalUrl = backgroundText.substring(backgroundText.indexOf('../') + 2, backgroundText.lastIndexOf(')'));
  176. }
  177. originalUrl = originalUrl.replace("\"", "");
  178. var newUrl = 'url(\"' + ResourceBaseUrl() + originalUrl + '\")';
  179. backgroundText = newUrl + backgroundText.substring(backgroundText.indexOf(')') + 1);
  180. rule.style.backgroundImage = backgroundText;
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. if (!isDesignTime) {
  189. bodyLoad();
  190. // Show the main content section
  191. document.getElementById('mainBody').style.display = 'block';
  192. }
  193. }