Commit 00cae17a authored by Mengyun Yang's avatar Mengyun Yang Committed by Yuxin Wu

Refactoring javascript to show class name (#385)

parent 37ecbd4e
......@@ -3,14 +3,22 @@
$(function (){
var createList = function(selected) {
var obj = {};
var ul = $('<ul>');
selected.each(function(i,e) {
var className = e.getElementsByTagName('a')[0].href;
className = className.substr(className.lastIndexOf('/')+1);
className = className.substr(0,className.lastIndexOf(".html"));
var fullname = e.id;
var n = $(e).children('.descname').clone();
if (fullname.startsWith('tensorpack.'))
fullname = fullname.substr(11);
var n = $(e).children('.descname').clone();
n[0].innerText = fullname;
var l = $(e).children('.headerlink');
......@@ -20,9 +28,19 @@ $(function (){
a.append(n);
var entry = $('<li>').append(a);
ul.append(entry);
if(className in obj) {
obj[className] = obj[className].append(entry);
} else {
var ul = $('<ul>');
ul.append(entry);
obj[className] = ul;
}
});
return ul;
return obj;
}
......@@ -30,15 +48,20 @@ $(function (){
var customIndex = $('.custom-index');
customIndex.empty();
var selected = $('div.section>dl>dt');
if (selected.length === 0)
return;
var l = createList(selected);
var c = $('<div style="min-width: 300px;">');
var ul = c.clone()
.append(l);
customIndex.append(ul);
var obj = createList(selected);
for(var key in obj) {
var c = $('<div style="min-width: 300px;">');
var a = $('<h4>');
a.html(key);
var u = c.clone().append(a);
var ul = c.clone().append(obj[key]);
customIndex.append(u);
customIndex.append(ul);
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment