PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Documentation/scripts/mshs.js

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