admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | function toggle_private() { |
| 2 | // Search for any private/public links on this page. Store |
| 3 | // their old text in "cmd," so we will know what action to |
| 4 | // take; and change their text to the opposite action. |
| 5 | var cmd = "?"; |
| 6 | var elts = document.getElementsByTagName("a"); |
| 7 | for(var i=0; i<elts.length; i++) { |
| 8 | if (elts[i].className == "privatelink") { |
| 9 | cmd = elts[i].innerHTML; |
| 10 | elts[i].innerHTML = ((cmd && cmd.substr(0,4)=="show")? |
| 11 | "hide private":"show private"); |
| 12 | } |
| 13 | } |
| 14 | // Update all DIVs containing private objects. |
| 15 | var elts = document.getElementsByTagName("div"); |
| 16 | for(var i=0; i<elts.length; i++) { |
| 17 | if (elts[i].className == "private") { |
| 18 | elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"none":"block"); |
| 19 | } |
| 20 | else if (elts[i].className == "public") { |
| 21 | elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"block":"none"); |
| 22 | } |
| 23 | } |
| 24 | // Update all table rows containing private objects. Note, we |
| 25 | // use "" instead of "block" becaue IE & firefox disagree on what |
| 26 | // this should be (block vs table-row), and "" just gives the |
| 27 | // default for both browsers. |
| 28 | var elts = document.getElementsByTagName("tr"); |
| 29 | for(var i=0; i<elts.length; i++) { |
| 30 | if (elts[i].className == "private") { |
| 31 | elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"none":""); |
| 32 | } |
| 33 | } |
| 34 | // Update all list items containing private objects. |
| 35 | var elts = document.getElementsByTagName("li"); |
| 36 | for(var i=0; i<elts.length; i++) { |
| 37 | if (elts[i].className == "private") { |
| 38 | elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")? |
| 39 | "none":""); |
| 40 | } |
| 41 | } |
| 42 | // Update all list items containing private objects. |
| 43 | var elts = document.getElementsByTagName("ul"); |
| 44 | for(var i=0; i<elts.length; i++) { |
| 45 | if (elts[i].className == "private") { |
| 46 | elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"none":"block"); |
| 47 | } |
| 48 | } |
| 49 | // Set a cookie to remember the current option. |
| 50 | document.cookie = "EpydocPrivate="+cmd; |
| 51 | } |
| 52 | function show_private() { |
| 53 | var elts = document.getElementsByTagName("a"); |
| 54 | for(var i=0; i<elts.length; i++) { |
| 55 | if (elts[i].className == "privatelink") { |
| 56 | cmd = elts[i].innerHTML; |
| 57 | if (cmd && cmd.substr(0,4)=="show") |
| 58 | toggle_private(); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | function getCookie(name) { |
| 63 | var dc = document.cookie; |
| 64 | var prefix = name + "="; |
| 65 | var begin = dc.indexOf("; " + prefix); |
| 66 | if (begin == -1) { |
| 67 | begin = dc.indexOf(prefix); |
| 68 | if (begin != 0) return null; |
| 69 | } else |
| 70 | { begin += 2; } |
| 71 | var end = document.cookie.indexOf(";", begin); |
| 72 | if (end == -1) |
| 73 | { end = dc.length; } |
| 74 | return unescape(dc.substring(begin + prefix.length, end)); |
| 75 | } |
| 76 | function setFrame(url1, url2) { |
| 77 | parent.frames[1].location.href = url1; |
| 78 | parent.frames[2].location.href = url2; |
| 79 | } |
| 80 | function checkCookie() { |
| 81 | var cmd=getCookie("EpydocPrivate"); |
| 82 | if (cmd && cmd.substr(0,4)!="show" && location.href.indexOf("#_") < 0) |
| 83 | toggle_private(); |
| 84 | } |
| 85 | function toggleCallGraph(id) { |
| 86 | var elt = document.getElementById(id); |
| 87 | if (elt.style.display == "none") |
| 88 | elt.style.display = "block"; |
| 89 | else |
| 90 | elt.style.display = "none"; |
| 91 | } |
| 92 | function expand(id) { |
| 93 | var elt = document.getElementById(id+"-expanded"); |
| 94 | if (elt) elt.style.display = "block"; |
| 95 | var elt = document.getElementById(id+"-expanded-linenums"); |
| 96 | if (elt) elt.style.display = "block"; |
| 97 | var elt = document.getElementById(id+"-collapsed"); |
| 98 | if (elt) { elt.innerHTML = ""; elt.style.display = "none"; } |
| 99 | var elt = document.getElementById(id+"-collapsed-linenums"); |
| 100 | if (elt) { elt.innerHTML = ""; elt.style.display = "none"; } |
| 101 | var elt = document.getElementById(id+"-toggle"); |
| 102 | if (elt) { elt.innerHTML = "-"; } |
| 103 | } |
| 104 | |
| 105 | function collapse(id) { |
| 106 | var elt = document.getElementById(id+"-expanded"); |
| 107 | if (elt) elt.style.display = "none"; |
| 108 | var elt = document.getElementById(id+"-expanded-linenums"); |
| 109 | if (elt) elt.style.display = "none"; |
| 110 | var elt = document.getElementById(id+"-collapsed-linenums"); |
| 111 | if (elt) { elt.innerHTML = "<br />"; elt.style.display="block"; } |
| 112 | var elt = document.getElementById(id+"-toggle"); |
| 113 | if (elt) { elt.innerHTML = "+"; } |
| 114 | var elt = document.getElementById(id+"-collapsed"); |
| 115 | if (elt) { |
| 116 | elt.style.display = "block"; |
| 117 | |
| 118 | var indent = elt.getAttribute("indent"); |
| 119 | var pad = elt.getAttribute("pad"); |
| 120 | var s = "<tt class='py-lineno'>"; |
| 121 | for (var i=0; i<pad.length; i++) { s += " " } |
| 122 | s += "</tt>"; |
| 123 | s += " <tt class='py-line'>"; |
| 124 | for (var i=0; i<indent.length; i++) { s += " " } |
| 125 | s += "<a href='#' onclick='expand(\"" + id; |
| 126 | s += "\");return false'>...</a></tt><br />"; |
| 127 | elt.innerHTML = s; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | function toggle(id) { |
| 132 | elt = document.getElementById(id+"-toggle"); |
| 133 | if (elt.innerHTML == "-") |
| 134 | collapse(id); |
| 135 | else |
| 136 | expand(id); |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | function highlight(id) { |
| 141 | var elt = document.getElementById(id+"-def"); |
| 142 | if (elt) elt.className = "py-highlight-hdr"; |
| 143 | var elt = document.getElementById(id+"-expanded"); |
| 144 | if (elt) elt.className = "py-highlight"; |
| 145 | var elt = document.getElementById(id+"-collapsed"); |
| 146 | if (elt) elt.className = "py-highlight"; |
| 147 | } |
| 148 | |
| 149 | function num_lines(s) { |
| 150 | var n = 1; |
| 151 | var pos = s.indexOf("\n"); |
| 152 | while ( pos > 0) { |
| 153 | n += 1; |
| 154 | pos = s.indexOf("\n", pos+1); |
| 155 | } |
| 156 | return n; |
| 157 | } |
| 158 | |
| 159 | // Collapse all blocks that mave more than `min_lines` lines. |
| 160 | function collapse_all(min_lines) { |
| 161 | var elts = document.getElementsByTagName("div"); |
| 162 | for (var i=0; i<elts.length; i++) { |
| 163 | var elt = elts[i]; |
| 164 | var split = elt.id.indexOf("-"); |
| 165 | if (split > 0) |
| 166 | if (elt.id.substring(split, elt.id.length) == "-expanded") |
| 167 | if (num_lines(elt.innerHTML) > min_lines) |
| 168 | collapse(elt.id.substring(0, split)); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function expandto(href) { |
| 173 | var start = href.indexOf("#")+1; |
| 174 | if (start != 0 && start != href.length) { |
| 175 | if (href.substring(start, href.length) != "-") { |
| 176 | collapse_all(4); |
| 177 | pos = href.indexOf(".", start); |
| 178 | while (pos != -1) { |
| 179 | var id = href.substring(start, pos); |
| 180 | expand(id); |
| 181 | pos = href.indexOf(".", pos+1); |
| 182 | } |
| 183 | var id = href.substring(start, href.length); |
| 184 | expand(id); |
| 185 | highlight(id); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function kill_doclink(id) { |
| 191 | var parent = document.getElementById(id); |
| 192 | parent.removeChild(parent.childNodes.item(0)); |
| 193 | } |
| 194 | function auto_kill_doclink(ev) { |
| 195 | if (!ev) var ev = window.event; |
| 196 | if (!this.contains(ev.toElement)) { |
| 197 | var parent = document.getElementById(this.parentID); |
| 198 | parent.removeChild(parent.childNodes.item(0)); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | function doclink(id, name, targets_id) { |
| 203 | var elt = document.getElementById(id); |
| 204 | |
| 205 | // If we already opened the box, then destroy it. |
| 206 | // (This case should never occur, but leave it in just in case.) |
| 207 | if (elt.childNodes.length > 1) { |
| 208 | elt.removeChild(elt.childNodes.item(0)); |
| 209 | } |
| 210 | else { |
| 211 | // The outer box: relative + inline positioning. |
| 212 | var box1 = document.createElement("div"); |
| 213 | box1.style.position = "relative"; |
| 214 | box1.style.display = "inline"; |
| 215 | box1.style.top = 0; |
| 216 | box1.style.left = 0; |
| 217 | |
| 218 | // A shadow for fun |
| 219 | var shadow = document.createElement("div"); |
| 220 | shadow.style.position = "absolute"; |
| 221 | shadow.style.left = "-1.3em"; |
| 222 | shadow.style.top = "-1.3em"; |
| 223 | shadow.style.background = "#404040"; |
| 224 | |
| 225 | // The inner box: absolute positioning. |
| 226 | var box2 = document.createElement("div"); |
| 227 | box2.style.position = "relative"; |
| 228 | box2.style.border = "1px solid #a0a0a0"; |
| 229 | box2.style.left = "-.2em"; |
| 230 | box2.style.top = "-.2em"; |
| 231 | box2.style.background = "white"; |
| 232 | box2.style.padding = ".3em .4em .3em .4em"; |
| 233 | box2.style.fontStyle = "normal"; |
| 234 | box2.onmouseout=auto_kill_doclink; |
| 235 | box2.parentID = id; |
| 236 | |
| 237 | // Get the targets |
| 238 | var targets_elt = document.getElementById(targets_id); |
| 239 | var targets = targets_elt.getAttribute("targets"); |
| 240 | var links = ""; |
| 241 | target_list = targets.split(","); |
| 242 | for (var i=0; i<target_list.length; i++) { |
| 243 | var target = target_list[i].split("="); |
| 244 | links += "<li><a href='" + target[1] + |
| 245 | "' style='text-decoration:none'>" + |
| 246 | target[0] + "</a></li>"; |
| 247 | } |
| 248 | |
| 249 | // Put it all together. |
| 250 | elt.insertBefore(box1, elt.childNodes.item(0)); |
| 251 | //box1.appendChild(box2); |
| 252 | box1.appendChild(shadow); |
| 253 | shadow.appendChild(box2); |
| 254 | box2.innerHTML = |
| 255 | "Which <b>"+name+"</b> do you want to see documentation for?" + |
| 256 | "<ul style='margin-bottom: 0;'>" + |
| 257 | links + |
| 258 | "<li><a href='#' style='text-decoration:none' " + |
| 259 | "onclick='kill_doclink(\""+id+"\");return false;'>"+ |
| 260 | "<i>None of the above</i></a></li></ul>"; |
| 261 | } |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | function get_anchor() { |
| 266 | var href = location.href; |
| 267 | var start = href.indexOf("#")+1; |
| 268 | if ((start != 0) && (start != href.length)) |
| 269 | return href.substring(start, href.length); |
| 270 | } |
| 271 | function redirect_url(dottedName) { |
| 272 | // Scan through each element of the "pages" list, and check |
| 273 | // if "name" matches with any of them. |
| 274 | for (var i=0; i<pages.length; i++) { |
| 275 | |
| 276 | // Each page has the form "<pagename>-m" or "<pagename>-c"; |
| 277 | // extract the <pagename> portion & compare it to dottedName. |
| 278 | var pagename = pages[i].substring(0, pages[i].length-2); |
| 279 | if (pagename == dottedName.substring(0,pagename.length)) { |
| 280 | |
| 281 | // We've found a page that matches `dottedName`; |
| 282 | // construct its URL, using leftover `dottedName` |
| 283 | // content to form an anchor. |
| 284 | var pagetype = pages[i].charAt(pages[i].length-1); |
| 285 | var url = pagename + ((pagetype=="m")?"-module.html": |
| 286 | "-class.html"); |
| 287 | if (dottedName.length > pagename.length) |
| 288 | url += "#" + dottedName.substring(pagename.length+1, |
| 289 | dottedName.length); |
| 290 | return url; |
| 291 | } |
| 292 | } |
| 293 | } |