Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  Licensed to the Apache Software Foundation (ASF) under one or more
0003  contributor license agreements.  See the NOTICE file distributed with
0004  this work for additional information regarding copyright ownership.
0005  The ASF licenses this file to You under the Apache License, Version 2.0
0006  (the "License"); you may not use this file except in compliance with
0007  the License.  You may obtain a copy of the License at
0008 
0009     http://www.apache.org/licenses/LICENSE-2.0
0010 
0011  Unless required by applicable law or agreed to in writing, software
0012  distributed under the License is distributed on an "AS IS" BASIS,
0013  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  See the License for the specific language governing permissions and
0015  limitations under the License.
0016 */
0017 
0018 $(function (){
0019 
0020     function startsWith(s, prefix) {
0021         return s && s.indexOf(prefix) === 0;
0022     }
0023 
0024     function buildSidebarLinkMap() {
0025         var linkMap = {};
0026         $('div.sphinxsidebar a.reference.internal').each(function (i,a)  {
0027             var href = $(a).attr('href');
0028             if (startsWith(href, '#module-')) {
0029                 var id = href.substr(8);
0030                 linkMap[id] = [$(a), null];
0031             }
0032         })
0033         return linkMap;
0034     };
0035 
0036     function getAdNoteDivs(dd) {
0037         var noteDivs = {};
0038         dd.find('> div.admonition.note > p.last').each(function (i, p) {
0039             var text = $(p).text();
0040             if (!noteDivs.experimental && startsWith(text, 'Experimental')) {
0041                 noteDivs.experimental = $(p).parent();
0042             }
0043             if (!noteDivs.deprecated && startsWith(text, 'Deprecated')) {
0044                 noteDivs.deprecated = $(p).parent();
0045             }
0046         });
0047         return noteDivs;
0048     }
0049 
0050     function getParentId(name) {
0051         var last_idx = name.lastIndexOf('.');
0052         return last_idx == -1? '': name.substr(0, last_idx);
0053     }
0054 
0055     function buildTag(text, cls, tooltip) {
0056         return '<span class="pys-tag ' + cls + ' hasTooltip">' + text + '<span class="tooltip">'
0057             + tooltip + '</span></span>'
0058     }
0059 
0060 
0061     var sidebarLinkMap = buildSidebarLinkMap();
0062 
0063     $('dl.class, dl.function').each(function (i,dl)  {
0064 
0065         dl = $(dl);
0066         dt = dl.children('dt').eq(0);
0067         dd = dl.children('dd').eq(0);
0068         var id = dt.attr('id');
0069         var desc = dt.find('> .descname').text();
0070         var adNoteDivs = getAdNoteDivs(dd);
0071 
0072         if (id) {
0073             var parent_id = getParentId(id);
0074 
0075             var r = sidebarLinkMap[parent_id];
0076             if (r) {
0077                 if (r[1] === null) {
0078                     r[1] = $('<ul/>');
0079                     r[0].parent().append(r[1]);
0080                 }
0081                 var tags = '';
0082                 if (adNoteDivs.experimental) {
0083                     tags += buildTag('E', 'pys-tag-experimental', 'Experimental');
0084                     adNoteDivs.experimental.addClass('pys-note pys-note-experimental');
0085                 }
0086                 if (adNoteDivs.deprecated) {
0087                     tags += buildTag('D', 'pys-tag-deprecated', 'Deprecated');
0088                     adNoteDivs.deprecated.addClass('pys-note pys-note-deprecated');
0089                 }
0090                 var li = $('<li/>');
0091                 var a = $('<a href="#' + id + '">' + desc + '</a>');
0092                 li.append(a);
0093                 li.append(tags);
0094                 r[1].append(li);
0095                 sidebarLinkMap[id] = [a, null];
0096             }
0097         }
0098     });
0099 });