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